discourse/plugins
Joffrey JAFFEUX 59ec86933a
DEV: DMultiSelect (#32240)
The `DMultiSelect` component provides a customizable multi-select
dropdown with support for both mouse and keyboard interactions.

![Screenshot 2025-04-10 at 15 40
26](https://github.com/user-attachments/assets/277619db-6e56-4beb-8eda-f76360cd2ad8)

### 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>
2025-04-15 14:56:57 +02:00
..
automation DEV: [gjs-codemod] Convert automation/styleguide/other to gjs 2025-04-14 15:36:16 +01:00
chat UX: Onebox & quote border radius (#32242) 2025-04-14 10:55:51 -05:00
checklist FIX: replace positive lookbehind on checklist inputrule (#31827) 2025-03-14 07:31:21 -03:00
discourse-details FIX: click handler position on rich editor details node (#32268) 2025-04-14 14:06:54 -03:00
discourse-lazy-videos Update translations (#31377) 2025-02-18 14:51:47 +01:00
discourse-local-dates FEATURE: add footnote (plugin) rich editor extension (#31719) 2025-04-14 14:25:36 -03:00
discourse-narrative-bot UX: Improve naming for anonymous mode settings (#31832) 2025-03-21 04:54:06 +03:00
discourse-presence DEV: [gjs-codemod] Convert automation/styleguide/other to gjs 2025-04-14 15:36:16 +01:00
footnote UX: keep content on rich editor footnote inputrule (#32296) 2025-04-14 19:36:18 -03:00
poll DEV: [gjs-codemod] Convert automation/styleguide/other to gjs 2025-04-14 15:36:16 +01:00
spoiler-alert FEATURE: add spoiler (plugin) rich editor extension (#31717) 2025-03-11 20:13:52 -03:00
styleguide DEV: DMultiSelect (#32240) 2025-04-15 14:56:57 +02:00