mirror of
https://github.com/discourse/discourse.git
synced 2025-04-17 05:11:28 +08:00

The `DMultiSelect` component provides a customizable multi-select dropdown with support for both mouse and keyboard interactions.  ### Parameters #### `@loadFn` (required) An async function that returns the data to populate the dropdown options. ```javascript const loadFn = async () => { return [ { id: 1, name: "Option 1" }, { id: 2, name: "Option 2" }, ]; }; ``` #### `@compareFn` A function used to determine equality between items. This is particularly useful when working with complex objects. By default, `id` will be used. ```javascript const compareFn = (a, b) => { return a.name === b.name; }; ``` #### `@selection` An array of pre-selected items that will be displayed as selected when the component renders. ```javascript const selection = [ { id: 1, name: "Option 1" }, { id: 2, name: "Option 2" }, ]; ``` #### `@label` Text label displayed in the trigger element when no items are selected. ```javascript @label="Select options" ``` ### Named Blocks #### :selection Block for customizing how selected items appear in the trigger. ```javascript <:selection as |result|>{{result.name}}</:selection> ``` #### :result Block for customizing how items appear in the dropdown list. ```javascript <:result as |result|>{{result.name}}</:result> ``` #### :result Block for customizing how errors appear in the component. ```javascript <:error as |error|>{{error}}</:error> ``` ### Example Usage ```javascript <DMultiSelect @loadFn={{this.loadOptions}} @selection={{this.selectedItems}} @compareFn={{this.compareItems}} @label="Select options"> <:selection as |result|>{{result.name}}</:selection> <:result as |result|>{{result.name}}</:result> <:error as |error|>{{error}}</:error> </DMultiSelect> ``` Co-Authored-By: Jordan Vidrine <30537603+jordanvidrine@users.noreply.github.com> --------- Co-authored-by: Jordan Vidrine <30537603+jordanvidrine@users.noreply.github.com>