discourse/app/assets/javascripts/select-kit/addon/components/group-dropdown.js
Joffrey JAFFEUX cb59681d86
DEV: select-kit third major update with focus on accessibility (#13303)
Major changes included:
- better support for screen readers
- trapping focus in modals
- better tabbing order in composer
- alerts on no content found/number of items found
- better autofocus in modals
- mini-tag-chooser is now a multi-select component
- each multi-select-component will now display selection on one row
2021-08-23 10:44:19 +02:00

43 lines
1.2 KiB
JavaScript

import { gte, reads } from "@ember/object/computed";
import ComboBoxComponent from "select-kit/components/combo-box";
import DiscourseURL from "discourse/lib/url";
import I18n from "I18n";
import { computed } from "@ember/object";
import { setting } from "discourse/lib/computed";
export default ComboBoxComponent.extend({
pluginApiIdentifiers: ["group-dropdown"],
classNames: ["group-dropdown"],
content: reads("groupsWithShortcut"),
valueProperty: null,
nameProperty: null,
hasManyGroups: gte("content.length", 10),
enableGroupDirectory: setting("enable_group_directory"),
selectKitOptions: {
caretDownIcon: "caret-right",
caretUpIcon: "caret-down",
filterable: "hasManyGroups",
},
groupsWithShortcut: computed("groups.[]", function () {
const shortcuts = [];
if (this.enableGroupDirectory || this.get("currentUser.staff")) {
shortcuts.push(I18n.t("groups.index.all"));
}
return shortcuts.concat(this.groups);
}),
actions: {
onChange(groupName) {
if ((this.groups || []).includes(groupName)) {
DiscourseURL.routeToUrl(`/g/${groupName}`);
} else {
DiscourseURL.routeToUrl(`/g`);
}
},
},
});