This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/select-kit/addon/components/select-kit/single-select-header.js
2021-09-03 16:41:15 +02:00

33 lines
956 B
JavaScript

import { computed } from "@ember/object";
import SelectKitHeaderComponent from "select-kit/components/select-kit/select-kit-header";
import UtilsMixin from "select-kit/mixins/utils";
import layout from "select-kit/templates/components/select-kit/single-select-header";
import I18n from "I18n";
export default SelectKitHeaderComponent.extend(UtilsMixin, {
tagName: "summary",
layout,
classNames: ["single-select-header"],
attributeBindings: ["name"],
focusIn(event) {
event.stopImmediatePropagation();
document.querySelectorAll(".select-kit-header").forEach((header) => {
if (header !== event.target) {
header.parentNode.open = false;
}
});
},
name: computed("selectedContent.name", function () {
if (this.selectedContent) {
return I18n.t("select_kit.filter_by", {
name: this.selectedContent.name,
});
} else {
return I18n.t("select_kit.select_to_filter");
}
}),
});