@salesforce/design-system-react 11.0.0-rc.1 → 11.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/cjs/components/accordion/index.cjs +1 -1
- package/dist/cjs/components/accordion/index.cjs.map +1 -1
- package/dist/cjs/components/accordion/panel.cjs.map +1 -1
- package/dist/cjs/components/builder-header/nav-dropdown.cjs.map +1 -1
- package/dist/cjs/components/builder-header/nav-link.cjs.map +1 -1
- package/dist/cjs/components/builder-header/toolbar.cjs.map +1 -1
- package/dist/cjs/components/button/index.cjs.map +1 -1
- package/dist/cjs/components/button-stateful/index.cjs.map +1 -1
- package/dist/cjs/components/checkbox/index.cjs.map +1 -1
- package/dist/cjs/components/color-picker/color-picker.cjs.map +1 -1
- package/dist/cjs/components/combobox/combobox.cjs +1 -1
- package/dist/cjs/components/combobox/combobox.cjs.map +1 -1
- package/dist/cjs/components/date-picker/date-picker.cjs +1 -1
- package/dist/cjs/components/date-picker/date-picker.cjs.map +1 -1
- package/dist/cjs/components/date-picker/index.cjs.map +1 -1
- package/dist/cjs/components/files/file.cjs.map +1 -1
- package/dist/cjs/components/icon/index.cjs.map +1 -1
- package/dist/cjs/components/icon/input-icon/index.cjs.map +1 -1
- package/dist/cjs/components/icon-settings/index.cjs.map +1 -1
- package/dist/cjs/components/input/index.cjs.map +1 -1
- package/dist/cjs/components/input/private/inner-input.cjs.map +1 -1
- package/dist/cjs/components/menu-dropdown/button-trigger.cjs.map +1 -1
- package/dist/cjs/components/menu-dropdown/menu-dropdown.cjs.map +1 -1
- package/dist/cjs/components/modal/index.cjs.map +1 -1
- package/dist/cjs/components/panel/filtering/group.cjs.map +1 -1
- package/dist/cjs/components/pill/index.cjs.map +1 -1
- package/dist/cjs/components/popover/edit-dialog.cjs.map +1 -1
- package/dist/cjs/components/popover/popover.cjs.map +1 -1
- package/dist/cjs/components/progress-indicator/index.cjs.map +1 -1
- package/dist/cjs/components/progress-ring/index.cjs.map +1 -1
- package/dist/cjs/components/radio/index.cjs.map +1 -1
- package/dist/cjs/components/radio-group/check-props.cjs.map +1 -1
- package/dist/cjs/components/radio-group/index.cjs.map +1 -1
- package/dist/cjs/components/scoped-notification/index.cjs.map +1 -1
- package/dist/cjs/components/setup-assistant/step.cjs.map +1 -1
- package/dist/cjs/components/slider/index.cjs.map +1 -1
- package/dist/cjs/components/split-view/header.cjs.map +1 -1
- package/dist/cjs/components/tabs/index.cjs.map +1 -1
- package/dist/cjs/components/tabs/panel.cjs.map +1 -1
- package/dist/cjs/components/textarea/index.cjs +1 -1
- package/dist/cjs/components/textarea/index.cjs.map +1 -1
- package/dist/cjs/components/tooltip/index.cjs.map +1 -1
- package/dist/cjs/components/tree/tree.cjs.map +1 -1
- package/dist/cjs/components/trial-bar/button.cjs.map +1 -1
- package/dist/cjs/components/trial-bar/dropdown.cjs.map +1 -1
- package/dist/cjs/components/utilities/menu-list/item-label.cjs.map +1 -1
- package/dist/cjs/utilities/get-component-doc.cjs +1 -1
- package/dist/cjs/utilities/get-component-doc.cjs.map +1 -1
- package/dist/cjs/utilities/warning/children-as-trigger.cjs +1 -1
- package/dist/cjs/utilities/warning/children-as-trigger.cjs.map +1 -1
- package/dist/cjs/utilities/warning/deprecated-property-value.cjs +1 -1
- package/dist/cjs/utilities/warning/deprecated-property-value.cjs.map +1 -1
- package/dist/cjs/utilities/warning/deprecated-property.cjs +1 -1
- package/dist/cjs/utilities/warning/deprecated-property.cjs.map +1 -1
- package/dist/cjs/utilities/warning/removal-version.cjs +2 -0
- package/dist/cjs/utilities/warning/removal-version.cjs.map +1 -0
- package/dist/es/components/accordion/index.js +7 -3
- package/dist/es/components/accordion/index.js.map +1 -1
- package/dist/es/components/accordion/panel.js.map +1 -1
- package/dist/es/components/builder-header/nav-dropdown.js.map +1 -1
- package/dist/es/components/builder-header/nav-link.js.map +1 -1
- package/dist/es/components/builder-header/toolbar.js.map +1 -1
- package/dist/es/components/button/index.js.map +1 -1
- package/dist/es/components/button-stateful/index.js.map +1 -1
- package/dist/es/components/checkbox/index.js.map +1 -1
- package/dist/es/components/color-picker/color-picker.js.map +1 -1
- package/dist/es/components/combobox/combobox.js +4 -2
- package/dist/es/components/combobox/combobox.js.map +1 -1
- package/dist/es/components/date-picker/date-picker.js +1 -1
- package/dist/es/components/date-picker/date-picker.js.map +1 -1
- package/dist/es/components/date-picker/index.js.map +1 -1
- package/dist/es/components/files/file.js.map +1 -1
- package/dist/es/components/icon/index.js.map +1 -1
- package/dist/es/components/icon/input-icon/index.js.map +1 -1
- package/dist/es/components/icon-settings/index.js.map +1 -1
- package/dist/es/components/input/index.js.map +1 -1
- package/dist/es/components/input/private/inner-input.js.map +1 -1
- package/dist/es/components/menu-dropdown/button-trigger.js.map +1 -1
- package/dist/es/components/menu-dropdown/menu-dropdown.js.map +1 -1
- package/dist/es/components/modal/index.js.map +1 -1
- package/dist/es/components/panel/filtering/group.js.map +1 -1
- package/dist/es/components/pill/index.js.map +1 -1
- package/dist/es/components/popover/edit-dialog.js.map +1 -1
- package/dist/es/components/popover/popover.js.map +1 -1
- package/dist/es/components/progress-indicator/index.js.map +1 -1
- package/dist/es/components/progress-ring/index.js.map +1 -1
- package/dist/es/components/radio/index.js.map +1 -1
- package/dist/es/components/radio-group/check-props.js.map +1 -1
- package/dist/es/components/radio-group/index.js.map +1 -1
- package/dist/es/components/scoped-notification/index.js.map +1 -1
- package/dist/es/components/setup-assistant/step.js.map +1 -1
- package/dist/es/components/slider/index.js.map +1 -1
- package/dist/es/components/split-view/header.js.map +1 -1
- package/dist/es/components/tabs/index.js.map +1 -1
- package/dist/es/components/tabs/panel.js.map +1 -1
- package/dist/es/components/textarea/index.js +29 -44
- package/dist/es/components/textarea/index.js.map +1 -1
- package/dist/es/components/tooltip/index.js.map +1 -1
- package/dist/es/components/tree/tree.js.map +1 -1
- package/dist/es/components/trial-bar/button.js.map +1 -1
- package/dist/es/components/trial-bar/dropdown.js.map +1 -1
- package/dist/es/components/utilities/menu-list/item-label.js.map +1 -1
- package/dist/es/utilities/get-component-doc.js +6 -6
- package/dist/es/utilities/get-component-doc.js.map +1 -1
- package/dist/es/utilities/warning/children-as-trigger.js +9 -8
- package/dist/es/utilities/warning/children-as-trigger.js.map +1 -1
- package/dist/es/utilities/warning/deprecated-property-value.js +11 -10
- package/dist/es/utilities/warning/deprecated-property-value.js.map +1 -1
- package/dist/es/utilities/warning/deprecated-property.js +9 -8
- package/dist/es/utilities/warning/deprecated-property.js.map +1 -1
- package/dist/es/utilities/warning/removal-version.js +6 -0
- package/dist/es/utilities/warning/removal-version.js.map +1 -0
- package/dist/llms/components/accordion.md +267 -0
- package/dist/llms/components/alert.md +228 -0
- package/dist/llms/components/avatar.md +167 -0
- package/dist/llms/components/badge.md +153 -0
- package/dist/llms/components/breadcrumb.md +148 -0
- package/dist/llms/components/builder-header.examples.md +239 -0
- package/dist/llms/components/builder-header.md +736 -0
- package/dist/llms/components/button-group.md +167 -0
- package/dist/llms/components/button-stateful.md +246 -0
- package/dist/llms/components/button.md +661 -0
- package/dist/llms/components/card.md +368 -0
- package/dist/llms/components/carousel.md +365 -0
- package/dist/llms/components/checkbox.md +887 -0
- package/dist/llms/components/color-picker.md +591 -0
- package/dist/llms/components/combobox.examples.md +802 -0
- package/dist/llms/components/combobox.md +929 -0
- package/dist/llms/components/date-picker.md +546 -0
- package/dist/llms/components/docked-composer.md +173 -0
- package/dist/llms/components/dynamic-icon.md +226 -0
- package/dist/llms/components/expandable-section.md +198 -0
- package/dist/llms/components/files.md +337 -0
- package/dist/llms/components/filter.md +775 -0
- package/dist/llms/components/icon-settings.md +301 -0
- package/dist/llms/components/icon.md +1040 -0
- package/dist/llms/components/input.md +746 -0
- package/dist/llms/components/media-object.md +125 -0
- package/dist/llms/components/menu-dropdown.md +732 -0
- package/dist/llms/components/modal.md +504 -0
- package/dist/llms/components/page-header.md +282 -0
- package/dist/llms/components/panel.md +256 -0
- package/dist/llms/components/pill-container.md +218 -0
- package/dist/llms/components/pill.md +266 -0
- package/dist/llms/components/popover.md +600 -0
- package/dist/llms/components/portal-settings.md +371 -0
- package/dist/llms/components/progress-bar.md +175 -0
- package/dist/llms/components/progress-indicator.md +399 -0
- package/dist/llms/components/progress-ring.md +146 -0
- package/dist/llms/components/radio-button-group.md +285 -0
- package/dist/llms/components/radio-group.md +242 -0
- package/dist/llms/components/radio.md +269 -0
- package/dist/llms/components/scoped-notification.md +156 -0
- package/dist/llms/components/setup-assistant.md +398 -0
- package/dist/llms/components/simple-data-table.examples.md +2773 -0
- package/dist/llms/components/simple-data-table.md +919 -0
- package/dist/llms/components/slider.md +217 -0
- package/dist/llms/components/spinner.md +232 -0
- package/dist/llms/components/split-view.md +350 -0
- package/dist/llms/components/tabs.md +311 -0
- package/dist/llms/components/textarea.md +331 -0
- package/dist/llms/components/toast.md +267 -0
- package/dist/llms/components/tooltip.md +470 -0
- package/dist/llms/components/tree.md +1011 -0
- package/dist/llms/components/trial-bar.md +383 -0
- package/dist/llms/components/vertical-navigation.md +196 -0
- package/dist/llms/components/visual-picker.md +362 -0
- package/dist/llms/components/welcome-mat.md +885 -0
- package/dist/llms/docs/migration-v11.md +471 -0
- package/dist/llms/llms-full.txt +6874 -0
- package/dist/llms/llms.txt +133 -0
- package/dist/llms/rules.md +36 -0
- package/dist/types/components/accordion/index.d.ts.map +1 -1
- package/dist/types/components/accordion/panel.d.ts +7 -7
- package/dist/types/components/builder-header/nav-dropdown.d.ts +1 -0
- package/dist/types/components/builder-header/nav-dropdown.d.ts.map +1 -1
- package/dist/types/components/builder-header/nav-link.d.ts +0 -1
- package/dist/types/components/builder-header/nav-link.d.ts.map +1 -1
- package/dist/types/components/builder-header/toolbar.d.ts +0 -1
- package/dist/types/components/builder-header/toolbar.d.ts.map +1 -1
- package/dist/types/components/button/index.d.ts +6 -3
- package/dist/types/components/button/index.d.ts.map +1 -1
- package/dist/types/components/button-stateful/index.d.ts +4 -1
- package/dist/types/components/button-stateful/index.d.ts.map +1 -1
- package/dist/types/components/checkbox/index.d.ts +19 -5
- package/dist/types/components/checkbox/index.d.ts.map +1 -1
- package/dist/types/components/color-picker/color-picker.d.ts +6 -4
- package/dist/types/components/color-picker/color-picker.d.ts.map +1 -1
- package/dist/types/components/color-picker/types.d.ts +2 -2
- package/dist/types/components/combobox/combobox.d.ts +22 -0
- package/dist/types/components/combobox/combobox.d.ts.map +1 -1
- package/dist/types/components/date-picker/date-picker.d.ts +16 -4
- package/dist/types/components/date-picker/date-picker.d.ts.map +1 -1
- package/dist/types/components/date-picker/index.d.ts +2 -6
- package/dist/types/components/date-picker/index.d.ts.map +1 -1
- package/dist/types/components/files/file.d.ts +1 -1
- package/dist/types/components/icon/index.d.ts +1 -0
- package/dist/types/components/icon/index.d.ts.map +1 -1
- package/dist/types/components/icon/input-icon/index.d.ts +3 -0
- package/dist/types/components/icon/input-icon/index.d.ts.map +1 -1
- package/dist/types/components/icon-settings/index.d.ts.map +1 -1
- package/dist/types/components/input/index.d.ts +2 -1
- package/dist/types/components/input/index.d.ts.map +1 -1
- package/dist/types/components/menu-dropdown/button-trigger.d.ts +5 -0
- package/dist/types/components/menu-dropdown/button-trigger.d.ts.map +1 -1
- package/dist/types/components/menu-dropdown/menu-dropdown.d.ts +4 -0
- package/dist/types/components/menu-dropdown/menu-dropdown.d.ts.map +1 -1
- package/dist/types/components/modal/index.d.ts +5 -5
- package/dist/types/components/page-header/types.d.ts +3 -0
- package/dist/types/components/page-header/types.d.ts.map +1 -1
- package/dist/types/components/panel/filtering/group.d.ts +2 -0
- package/dist/types/components/panel/filtering/group.d.ts.map +1 -1
- package/dist/types/components/pill/index.d.ts +1 -0
- package/dist/types/components/pill/index.d.ts.map +1 -1
- package/dist/types/components/popover/edit-dialog.d.ts +1 -3
- package/dist/types/components/popover/edit-dialog.d.ts.map +1 -1
- package/dist/types/components/popover/popover.d.ts +1 -0
- package/dist/types/components/popover/popover.d.ts.map +1 -1
- package/dist/types/components/progress-indicator/index.d.ts +1 -0
- package/dist/types/components/progress-indicator/index.d.ts.map +1 -1
- package/dist/types/components/progress-ring/index.d.ts +1 -0
- package/dist/types/components/progress-ring/index.d.ts.map +1 -1
- package/dist/types/components/radio/index.d.ts +2 -2
- package/dist/types/components/radio/index.d.ts.map +1 -1
- package/dist/types/components/radio-group/index.d.ts +2 -0
- package/dist/types/components/radio-group/index.d.ts.map +1 -1
- package/dist/types/components/scoped-notification/index.d.ts +1 -0
- package/dist/types/components/scoped-notification/index.d.ts.map +1 -1
- package/dist/types/components/setup-assistant/step.d.ts +0 -1
- package/dist/types/components/setup-assistant/step.d.ts.map +1 -1
- package/dist/types/components/simple-data-table/types.d.ts +1 -0
- package/dist/types/components/simple-data-table/types.d.ts.map +1 -1
- package/dist/types/components/slider/index.d.ts +4 -2
- package/dist/types/components/slider/index.d.ts.map +1 -1
- package/dist/types/components/tabs/index.d.ts +1 -0
- package/dist/types/components/tabs/index.d.ts.map +1 -1
- package/dist/types/components/tabs/panel.d.ts +2 -1
- package/dist/types/components/tabs/panel.d.ts.map +1 -1
- package/dist/types/components/textarea/index.d.ts +9 -40
- package/dist/types/components/textarea/index.d.ts.map +1 -1
- package/dist/types/components/tooltip/index.d.ts +5 -0
- package/dist/types/components/tooltip/index.d.ts.map +1 -1
- package/dist/types/components/tree/tree.d.ts +5 -0
- package/dist/types/components/tree/tree.d.ts.map +1 -1
- package/dist/types/components/utilities/menu-list/item-label.d.ts +12 -0
- package/dist/types/components/utilities/menu-list/item-label.d.ts.map +1 -1
- package/package.json +8 -5
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
# Combobox
|
|
2
|
+
|
|
3
|
+
An input field that is either an autocomplete or read-only, with a listbox of
|
|
4
|
+
predefined options.
|
|
5
|
+
|
|
6
|
+
## Import
|
|
7
|
+
|
|
8
|
+
```tsx
|
|
9
|
+
import { Combobox, comboboxFilterAndLimit, comboboxAddSubheadings } from '@salesforce/design-system-react';
|
|
10
|
+
// or, one entry point per module:
|
|
11
|
+
import Combobox from '@salesforce/design-system-react/components/combobox';
|
|
12
|
+
import comboboxFilterAndLimit from '@salesforce/design-system-react/components/combobox/filter';
|
|
13
|
+
import comboboxAddSubheadings from '@salesforce/design-system-react/components/combobox/add-subheadings';
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Combobox props
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import type { ComboboxProps } from '@salesforce/design-system-react/components/combobox';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The props type is a union: some props only apply to some variants (see the Types block). A prop is marked required only when every variant requires it.
|
|
23
|
+
|
|
24
|
+
| Prop | Type | Required | Description |
|
|
25
|
+
| --- | --- | --- | --- |
|
|
26
|
+
| `aria-describedby` | `string` | | aria-describedby attribute |
|
|
27
|
+
| `assistiveText` | `ComboboxAssistiveText \| ComboboxAssistiveText & { popoverLabel: string; }` | | Assistive text for accessibility |
|
|
28
|
+
| `className` | `string \| string[] \| Record<string, boolean>` | | CSS classes for combobox container |
|
|
29
|
+
| `classNameContainer` | `string \| string[] \| Record<string, boolean>` | | CSS classes for top level container |
|
|
30
|
+
| `classNameMenu` | `string \| string[] \| Record<string, boolean>` | | CSS classes for dropdown menu |
|
|
31
|
+
| `classNameMenuSubHeader` | `string \| string[] \| Record<string, boolean>` | | CSS classes for menu sub header |
|
|
32
|
+
| `defaultIsOpen` | `boolean` | | Initial open state when `isOpen` is not set. Ignored when `isOpen` is set. |
|
|
33
|
+
| `disabled` | `boolean` | | Disables the input and keeps the menu closed. Applies to every variant. |
|
|
34
|
+
| `entityCombobox` | `ReactNode` | | Entity combobox for grouped comboboxes |
|
|
35
|
+
| `errorText` | `string` | | Error text to display |
|
|
36
|
+
| `events` | `ComboboxEvents` | | Event callbacks |
|
|
37
|
+
| `events.onBlur` | `(event: FocusEvent<Element, Element>) => void` | | |
|
|
38
|
+
| `events.onChange` | `(event: ChangeEvent<HTMLInputElement, Element>, data: { value: string }) => void` | | |
|
|
39
|
+
| `events.onClose` | `(event: SyntheticEvent<Element, Event> \| undefined, data: Record<string, unknown>) => void` | | Fires after the menu has closed (uncontrolled), or when a controlled `isOpen` changes to `false`. `event` is the event of the close request, when there was one. |
|
|
40
|
+
| `events.onFocus` | `(event: FocusEvent<Element, Element>, data: Record<string, unknown>) => void` | | |
|
|
41
|
+
| `events.onOpen` | `(event: SyntheticEvent<Element, Event> \| undefined, data: Record<string, unknown>) => void` | | Fires after the menu has opened and rendered, controlled or not. |
|
|
42
|
+
| `events.onRequestClose` | `(event: SyntheticEvent<Element, Event>, data: Record<string, unknown>) => void` | | Fires when the user asks to close the menu (Escape, blur, selecting an option, the popover buttons). With a controlled `isOpen`, set it to `false` to close. |
|
|
43
|
+
| `events.onRequestOpen` | `(event: SyntheticEvent<Element, Event> \| undefined, data: Record<string, unknown>) => void` | | Fires when the user asks to open the menu (typing, clicking the input, Down, Enter) while it is closed. With a controlled `isOpen`, set it to `true` to open. |
|
|
44
|
+
| `events.onRequestRemoveSelectedOption` | `(event: SyntheticEvent<Element, Event>, data: { selection: ComboboxOption[] }) => void` | | |
|
|
45
|
+
| `events.onSelect` | `(event: SyntheticEvent<Element, Event>, data: { selection: ComboboxOption[] }) => void` | | Fires with the requested selection when an option is chosen. `selection` is controlled, so update it to accept the change. |
|
|
46
|
+
| `events.onSelectActionItem` | `(event: MouseEvent<Element, MouseEvent> \| KeyboardEvent<Element>, data: { option: ComboboxActionItem; value: string }) => void` | | Fires when an `optionsSearchEntity` or `optionsAddItem` row is chosen by click or Enter. `value` is the current input text. |
|
|
47
|
+
| `events.onSubmit` | `(event: KeyboardEvent<Element>, data: { value: string }) => void` | | |
|
|
48
|
+
| `fieldLevelHelpTooltip` | `ReactNode` | | Field level help tooltip |
|
|
49
|
+
| `hasDeselect` | `boolean` | | Whether to show deselect option |
|
|
50
|
+
| `hasInputSpinner` | `boolean` | | Whether to show input spinner |
|
|
51
|
+
| `hasMenuSpinner` | `boolean` | | Whether to show menu spinner |
|
|
52
|
+
| `hasStaticAlignment` | `boolean` | | Whether to use static alignment |
|
|
53
|
+
| `id` | `string` | | HTML id |
|
|
54
|
+
| `inheritWidthOf` | `'target' \| 'menu' \| 'none'` (`'none' \| 'menu' \| 'target'`) | | Sets dialog width inheritance |
|
|
55
|
+
| `input` | `ReactElement<Partial<InputProps>>` | | An `Input` element whose props are passed to the combobox's input. They win over the combobox's own, except `onChange`, which is called with `(event, { value })` alongside the combobox's handler. |
|
|
56
|
+
| `inputRef` | `(ref: HTMLInputElement \| null) => void` | | Callback to get input ref |
|
|
57
|
+
| `isOpen` | `boolean` | | Whether the menu is open. Leave unset to let the combobox open and close itself (start state from `defaultIsOpen`). When set, the combobox only reports open and close requests through `events.onRequestOpen` and `events.onRequestClose`; update `isOpen` to act on them. |
|
|
58
|
+
| `labels` | `ComboboxLabels` | | Text labels |
|
|
59
|
+
| `menuItem` | `ComboboxLegacyMenuItem` | | **Deprecated.** Use `renderMenuItem` instead. |
|
|
60
|
+
| `menuItemVisibleLength` | `5 \| 7 \| 10` | | Menu item visible length |
|
|
61
|
+
| `menuMaxWidth` | `string` | | Menu max width |
|
|
62
|
+
| `menuPosition` | `'absolute' \| 'overflowBoundaryElement' \| 'relative'` | | Menu position |
|
|
63
|
+
| `multiple` | `boolean` | | Whether multiple selection is allowed |
|
|
64
|
+
| `onRenderMenuItem` | `ComboboxLegacyMenuItem` | | **Deprecated.** Use `renderMenuItem`, which is called as a function with `{ assistiveText, isSelected, option }`. |
|
|
65
|
+
| `options` | `ComboboxOption[]` | | Menu options |
|
|
66
|
+
| `optionsAddItem` | `ComboboxActionItem[]` | | Action items shown below the options, such as "New Account" |
|
|
67
|
+
| `optionsSearchEntity` | `ComboboxActionItem[]` | | Action items shown above the options, such as "Search in Accounts" |
|
|
68
|
+
| `popover` | `ReactElement<Partial<PopoverProps>>` | | A `Popover` element rendered as the dialog. Its props win over the combobox's defaults, except `body`, which the combobox wraps, and `children`, which the combobox replaces with its input. |
|
|
69
|
+
| `predefinedOptionsOnly` | `boolean` | | Whether only predefined options are allowed |
|
|
70
|
+
| `renderMenuItem` | `(data: ComboboxRenderMenuItemData) => ReactNode` | | Renders each option's content in place of the default label and icon. Receives `{ assistiveText, isSelected, option }`. |
|
|
71
|
+
| `required` | `boolean` | | Whether field is required |
|
|
72
|
+
| `selectedListboxRef` | `(ref: HTMLUListElement \| null) => void` | | Callback to get selected listbox ref |
|
|
73
|
+
| `selection` | `ComboboxOption[]` | Yes | Selected options. Controlled: `events.onSelect` and `events.onRequestRemoveSelectedOption` report the requested selection; update `selection` to accept it. |
|
|
74
|
+
| `singleInputDisabled` | `boolean` | | **Deprecated.** Use `disabled`, which now disables the input in every variant. |
|
|
75
|
+
| `tooltipMenuItemDisabled` | `ReactElement<Partial<TooltipProps>>` | | A `Tooltip` element shown on disabled menu items. Its props win over the combobox's defaults; an option's `tooltipContent` wins over its `content`. |
|
|
76
|
+
| `value` | `string` | | Text in the input. Controlled: update it from `events.onChange`. (`defaultValue` was removed in v11.) |
|
|
77
|
+
| `variant` | `'base' \| 'inline-listbox' \| 'readonly' \| 'popover'` | | Listbox variants. Defaults to `base`. `inline-listbox` with `multiple` is deprecated (SLDS deprecated the inline listbox): use `base` with `multiple`, which lists the selections after the input. |
|
|
78
|
+
|
|
79
|
+
## comboboxFilterAndLimit
|
|
80
|
+
|
|
81
|
+
SLDS recommends auto-complete/search inputs menus have a limit of 10 items.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
comboboxFilterAndLimit({ inputValue, limit, options, selection }: { inputValue: any; limit?: number | undefined; options: any; selection: any; }): any
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## comboboxAddSubheadings
|
|
88
|
+
|
|
89
|
+
This is a UX pattern recommendation for auto-complete search results that can contain multiple subheadings within the results. It inserts a subheading object based on `option.category === subheading.id` directly before a found option object and only inserts the subheading at the first occurence of that type of option.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
comboboxAddSubheadings({ subheadings, filteredOptions }: { filteredOptions: any; subheadings: any; }): never[]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Types
|
|
96
|
+
|
|
97
|
+
Declarations the props above refer to, from the package `.d.ts`:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
export type ComboboxProps = ComboboxBaseProps & ComboboxVariantProps;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* `variant` decides where the menu content comes from: `options` for the
|
|
104
|
+
* listbox variants, or a custom `popover` dialog.
|
|
105
|
+
*/
|
|
106
|
+
export type ComboboxVariantProps = {
|
|
107
|
+
/**
|
|
108
|
+
* Listbox variants. Defaults to `base`. `inline-listbox` with
|
|
109
|
+
* `multiple` is deprecated (SLDS deprecated the inline listbox):
|
|
110
|
+
* use `base` with `multiple`, which lists the selections after the input.
|
|
111
|
+
*/
|
|
112
|
+
variant?: 'base' | 'inline-listbox' | 'readonly';
|
|
113
|
+
/** Assistive text for accessibility */
|
|
114
|
+
assistiveText?: ComboboxAssistiveText;
|
|
115
|
+
/** Menu options */
|
|
116
|
+
options: ComboboxOption[];
|
|
117
|
+
popover?: never;
|
|
118
|
+
} | {
|
|
119
|
+
/** Custom dialog content instead of a listbox */
|
|
120
|
+
variant: 'popover';
|
|
121
|
+
/** Assistive text for accessibility. `popoverLabel` labels the dialog. */
|
|
122
|
+
assistiveText: ComboboxAssistiveText & {
|
|
123
|
+
popoverLabel: string;
|
|
124
|
+
};
|
|
125
|
+
options?: never;
|
|
126
|
+
/**
|
|
127
|
+
* A `Popover` element rendered as the dialog. Its props win over the combobox's
|
|
128
|
+
* defaults, except `body`, which the combobox wraps, and `children`, which the
|
|
129
|
+
* combobox replaces with its input.
|
|
130
|
+
*/
|
|
131
|
+
popover: ReactElement<Partial<PopoverProps>>;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export interface ComboboxAssistiveText {
|
|
135
|
+
/** Visually hidden input label, used when there is no `labels.label`. */
|
|
136
|
+
label?: string;
|
|
137
|
+
/** Spinner label while `hasMenuSpinner` is set. Defaults to the English text `Loading`. */
|
|
138
|
+
loadingMenuItems?: string;
|
|
139
|
+
/** Read before the selected item in the menu of the `readonly` variant. Defaults to the English text `Current Selection:`. */
|
|
140
|
+
optionSelectedInMenu?: string;
|
|
141
|
+
/** `aria-label` of the `popover` variant's dialog. Required for that variant. */
|
|
142
|
+
popoverLabel?: string;
|
|
143
|
+
/** Label of the button that removes the selected option in the single-select `inline-listbox` variant. Defaults to the English text `Remove selected option`. */
|
|
144
|
+
removeSingleSelectedOption?: string;
|
|
145
|
+
/** Appended to each pill's label in multiple selection. Defaults to the English text `, Press delete or backspace to remove`. */
|
|
146
|
+
removePill?: string;
|
|
147
|
+
/** Label of the listbox of selected pills in multiple selection. Defaults to the English text `Selected Options:`. */
|
|
148
|
+
selectedListboxLabel?: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type ComboboxOption = ComboboxItemOption | ComboboxSeparatorOption | ComboboxActionOption | ComboboxDeselectOption;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A selectable option. Group items under a `subheadings` entry from
|
|
155
|
+
* `comboboxAddSubheadings` with `category`.
|
|
156
|
+
*/
|
|
157
|
+
export interface ComboboxItemOption {
|
|
158
|
+
/** Structural rows set `type`; selectable items leave it unset. */
|
|
159
|
+
type?: undefined;
|
|
160
|
+
id: string;
|
|
161
|
+
/** Matches the `id` of a subheading passed to `comboboxAddSubheadings` */
|
|
162
|
+
category?: string;
|
|
163
|
+
label?: string;
|
|
164
|
+
subTitle?: string;
|
|
165
|
+
title?: string;
|
|
166
|
+
icon?: ComboboxOptionIcon;
|
|
167
|
+
disabled?: boolean;
|
|
168
|
+
tooltipContent?: ReactNode;
|
|
169
|
+
value?: string;
|
|
170
|
+
onClick?: never;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The `<Icon>` shown before an option. Its `size` defaults to `small` in the menu. */
|
|
174
|
+
export type ComboboxOptionIcon = ReactElement<IconProps>;
|
|
175
|
+
|
|
176
|
+
/** A non-interactive group label. Without a `label` it renders as a divider. */
|
|
177
|
+
export interface ComboboxSeparatorOption {
|
|
178
|
+
type: 'separator';
|
|
179
|
+
id: string;
|
|
180
|
+
label?: string | ComboboxOptionLabelRenderer;
|
|
181
|
+
category?: never;
|
|
182
|
+
subTitle?: never;
|
|
183
|
+
title?: never;
|
|
184
|
+
icon?: never;
|
|
185
|
+
disabled?: never;
|
|
186
|
+
tooltipContent?: never;
|
|
187
|
+
value?: never;
|
|
188
|
+
onClick?: never;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A function `label`, called with the current search term. */
|
|
192
|
+
export type ComboboxOptionLabelRenderer = (searchTerm: string) => ReactNode;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* An action row above (`header`) or below (`footer`) the options. Usually
|
|
196
|
+
* created from `optionsSearchEntity` and `optionsAddItem`.
|
|
197
|
+
*/
|
|
198
|
+
export type ComboboxActionOption = (ComboboxActionOptionFields & {
|
|
199
|
+
type: 'header';
|
|
200
|
+
}) | (ComboboxActionOptionFields & {
|
|
201
|
+
type: 'footer';
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
/** Fields shared by `header` and `footer` action rows. */
|
|
205
|
+
export interface ComboboxActionOptionFields {
|
|
206
|
+
id: string;
|
|
207
|
+
label?: string | ComboboxOptionLabelRenderer;
|
|
208
|
+
icon?: ComboboxOptionIcon;
|
|
209
|
+
disabled?: boolean;
|
|
210
|
+
/** @deprecated Only called on Enter, for `type: 'header' | 'footer'` rows
|
|
211
|
+
* passed directly in `options`. Use `optionsSearchEntity`/`optionsAddItem`
|
|
212
|
+
* with `events.onSelectActionItem` instead. */
|
|
213
|
+
onClick?: (event: MouseEvent) => void;
|
|
214
|
+
category?: never;
|
|
215
|
+
subTitle?: never;
|
|
216
|
+
title?: never;
|
|
217
|
+
tooltipContent?: never;
|
|
218
|
+
value?: never;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** The "clear selection" row added by `hasDeselect`. */
|
|
222
|
+
export interface ComboboxDeselectOption {
|
|
223
|
+
type: 'deselect';
|
|
224
|
+
id: string;
|
|
225
|
+
label?: string;
|
|
226
|
+
value?: string;
|
|
227
|
+
category?: never;
|
|
228
|
+
subTitle?: never;
|
|
229
|
+
title?: never;
|
|
230
|
+
icon?: never;
|
|
231
|
+
disabled?: never;
|
|
232
|
+
tooltipContent?: never;
|
|
233
|
+
onClick?: never;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface ComboboxEvents {
|
|
237
|
+
onBlur?: (event: React.FocusEvent) => void;
|
|
238
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>, data: {
|
|
239
|
+
value: string;
|
|
240
|
+
}) => void;
|
|
241
|
+
/**
|
|
242
|
+
* Fires after the menu has closed (uncontrolled), or when a controlled
|
|
243
|
+
* `isOpen` changes to `false`. `event` is the event of the close request,
|
|
244
|
+
* when there was one.
|
|
245
|
+
*/
|
|
246
|
+
onClose?: (event: React.SyntheticEvent | undefined, data: Record<string, unknown>) => void;
|
|
247
|
+
onFocus?: (event: React.FocusEvent, data: Record<string, unknown>) => void;
|
|
248
|
+
/** Fires after the menu has opened and rendered, controlled or not. */
|
|
249
|
+
onOpen?: (event: React.SyntheticEvent | undefined, data: Record<string, unknown>) => void;
|
|
250
|
+
/**
|
|
251
|
+
* Fires when the user asks to close the menu (Escape, blur, selecting an
|
|
252
|
+
* option, the popover buttons). With a controlled `isOpen`, set it to
|
|
253
|
+
* `false` to close.
|
|
254
|
+
*/
|
|
255
|
+
onRequestClose?: (event: React.SyntheticEvent, data: Record<string, unknown>) => void;
|
|
256
|
+
/**
|
|
257
|
+
* Fires when the user asks to open the menu (typing, clicking the input,
|
|
258
|
+
* Down, Enter) while it is closed. With a controlled `isOpen`, set it to
|
|
259
|
+
* `true` to open.
|
|
260
|
+
*/
|
|
261
|
+
onRequestOpen?: (event: React.SyntheticEvent | undefined, data: Record<string, unknown>) => void;
|
|
262
|
+
onRequestRemoveSelectedOption?: (event: React.SyntheticEvent, data: {
|
|
263
|
+
selection: ComboboxOption[];
|
|
264
|
+
}) => void;
|
|
265
|
+
/**
|
|
266
|
+
* Fires with the requested selection when an option is chosen. `selection`
|
|
267
|
+
* is controlled, so update it to accept the change.
|
|
268
|
+
*/
|
|
269
|
+
onSelect?: (event: React.SyntheticEvent, data: {
|
|
270
|
+
selection: ComboboxOption[];
|
|
271
|
+
}) => void;
|
|
272
|
+
/** Fires when an `optionsSearchEntity` or `optionsAddItem` row is chosen by
|
|
273
|
+
* click or Enter. `value` is the current input text. */
|
|
274
|
+
onSelectActionItem?: (event: React.MouseEvent | React.KeyboardEvent, data: {
|
|
275
|
+
option: ComboboxActionItem;
|
|
276
|
+
value: string;
|
|
277
|
+
}) => void;
|
|
278
|
+
onSubmit?: (event: React.KeyboardEvent, data: {
|
|
279
|
+
value: string;
|
|
280
|
+
}) => void;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* An action row in the menu: `optionsSearchEntity` items render above the
|
|
285
|
+
* options, `optionsAddItem` items below them. Choosing one (click or Enter)
|
|
286
|
+
* calls `events.onSelectActionItem` and closes the menu. Action rows are
|
|
287
|
+
* commands, not records, so they never fire `onSelect` or enter the selection.
|
|
288
|
+
*/
|
|
289
|
+
export interface ComboboxActionItem {
|
|
290
|
+
id?: string;
|
|
291
|
+
icon?: ComboboxOptionIcon;
|
|
292
|
+
label?: string | ((searchTerm: string) => ReactNode);
|
|
293
|
+
disabled?: boolean;
|
|
294
|
+
/** @deprecated Use `events.onSelectActionItem`. If both are set, both are
|
|
295
|
+
* called, this one first. */
|
|
296
|
+
onClick?: (event: React.MouseEvent | React.KeyboardEvent, data: {
|
|
297
|
+
option: ComboboxActionItem;
|
|
298
|
+
}) => void;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export interface ComboboxLabels {
|
|
302
|
+
/** First menu item of a single-select `readonly` combobox; choosing it clears the selection. Defaults to the English text `None`. */
|
|
303
|
+
deselectOption?: string;
|
|
304
|
+
/** Visible label above the input. */
|
|
305
|
+
label?: ReactNode | string;
|
|
306
|
+
/** Cancel button in the `popover` variant's footer. Defaults to the English text `Cancel`. */
|
|
307
|
+
cancelButton?: string;
|
|
308
|
+
/** Done button in the `popover` variant's footer. Defaults to the English text `Done`. */
|
|
309
|
+
doneButton?: string;
|
|
310
|
+
/** Input text of a multiple-selection `readonly` combobox with more than one option selected. Defaults to the English text `<n> options selected`. */
|
|
311
|
+
multipleOptionsSelected?: string;
|
|
312
|
+
/** Shown in the menu when no options match. Defaults to the English text `No matches found.`. */
|
|
313
|
+
noOptionsFound?: ReactNode | string;
|
|
314
|
+
/** Input placeholder. */
|
|
315
|
+
placeholder?: string;
|
|
316
|
+
/** Input placeholder of the `readonly` variant. Defaults to the English text `Select an Option`. */
|
|
317
|
+
placeholderReadOnly?: string;
|
|
318
|
+
/** Title of each pill's remove icon. Defaults to the English text `Remove`. */
|
|
319
|
+
removePillTitle?: string;
|
|
320
|
+
/** Tooltip for disabled options. Defaults to the English text `This option is disabled.`. */
|
|
321
|
+
optionDisabledTooltipLabel?: string;
|
|
322
|
+
/** Title of the search icon in the input. */
|
|
323
|
+
inputIconTitle?: string;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Component accepted by the deprecated `onRenderMenuItem` and `menuItem` props
|
|
328
|
+
*/
|
|
329
|
+
type ComboboxLegacyMenuItem = React.ComponentType<{
|
|
330
|
+
assistiveText?: ComboboxAssistiveText;
|
|
331
|
+
selected: boolean;
|
|
332
|
+
/** Custom renderers only receive selectable rows */
|
|
333
|
+
option: ComboboxItemOption | ComboboxDeselectOption;
|
|
334
|
+
}>;
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Argument passed to `renderMenuItem`
|
|
338
|
+
*/
|
|
339
|
+
export interface ComboboxRenderMenuItemData extends ComboboxMenuRenderMenuItemData {
|
|
340
|
+
/** The combobox's assistive text */
|
|
341
|
+
assistiveText: ComboboxAssistiveText;
|
|
342
|
+
}
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
- `InputProps`: see [input.md](https://opensource.salesforce.com/design-system-react/components/input.md)
|
|
346
|
+
- `PopoverProps`: see [popover.md](https://opensource.salesforce.com/design-system-react/components/popover.md)
|
|
347
|
+
- `TooltipProps`: see [tooltip.md](https://opensource.salesforce.com/design-system-react/components/tooltip.md)
|
|
348
|
+
|
|
349
|
+
## Examples
|
|
350
|
+
|
|
351
|
+
Every story in Storybook for this component, in sidebar order, as code for an app: imports use the package paths, and Storybook's own code (`meta`, decorators, `parameters`) is left out. A story that renders an `__examples__` file shows that file the first time. Icons are served from `/assets/icons` (see `IconSettings`). Storybook: <https://opensource.salesforce.com/design-system-react/?path=/docs/components-combobox--docs>.
|
|
352
|
+
|
|
353
|
+
### Shared code: `components/combobox/__docs__/Combobox.stories.tsx`
|
|
354
|
+
|
|
355
|
+
The stories from Components/Combobox below use these imports and helpers.
|
|
356
|
+
|
|
357
|
+
```tsx
|
|
358
|
+
import { useState } from 'react';
|
|
359
|
+
import Combobox, {
|
|
360
|
+
type ComboboxItemOption,
|
|
361
|
+
type ComboboxOption,
|
|
362
|
+
} from '@salesforce/design-system-react/components/combobox';
|
|
363
|
+
import Checkbox from '@salesforce/design-system-react/components/checkbox';
|
|
364
|
+
import Icon from '@salesforce/design-system-react/components/icon';
|
|
365
|
+
import Input from '@salesforce/design-system-react/components/input';
|
|
366
|
+
import Popover from '@salesforce/design-system-react/components/popover';
|
|
367
|
+
import Tooltip from '@salesforce/design-system-react/components/tooltip';
|
|
368
|
+
import UNSAFE_DirectionSettings from '@salesforce/design-system-react/components/utilities/UNSAFE_direction';
|
|
369
|
+
|
|
370
|
+
// Sample account options
|
|
371
|
+
const accounts = [
|
|
372
|
+
{
|
|
373
|
+
id: '1',
|
|
374
|
+
label: 'Acme',
|
|
375
|
+
subTitle: 'Account • San Francisco',
|
|
376
|
+
category: 'account',
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
id: '2',
|
|
380
|
+
label: 'Salesforce.com, Inc.',
|
|
381
|
+
subTitle: 'Account • San Francisco',
|
|
382
|
+
category: 'account',
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
id: '3',
|
|
386
|
+
label: 'Global Media',
|
|
387
|
+
subTitle: 'Account • New York',
|
|
388
|
+
category: 'account',
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
id: '4',
|
|
392
|
+
label: 'United Partners',
|
|
393
|
+
subTitle: 'Account • Chicago',
|
|
394
|
+
category: 'account',
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
id: '5',
|
|
398
|
+
label: 'Edge Communications',
|
|
399
|
+
subTitle: 'Account • Austin',
|
|
400
|
+
category: 'account',
|
|
401
|
+
},
|
|
402
|
+
];
|
|
403
|
+
|
|
404
|
+
// Sample accounts with icons
|
|
405
|
+
const accountsWithIcons = accounts.map((account) => ({
|
|
406
|
+
...account,
|
|
407
|
+
icon: (
|
|
408
|
+
<Icon
|
|
409
|
+
assistiveText={{ label: 'Account' }}
|
|
410
|
+
category="standard"
|
|
411
|
+
name="account"
|
|
412
|
+
/>
|
|
413
|
+
),
|
|
414
|
+
}));
|
|
415
|
+
|
|
416
|
+
// ===== Readonly Variant Stories (Picklist) =====
|
|
417
|
+
|
|
418
|
+
const picklistOptions = [
|
|
419
|
+
{ id: '1', label: 'Option One' },
|
|
420
|
+
{ id: '2', label: 'Option Two' },
|
|
421
|
+
{ id: '3', label: 'Option Three' },
|
|
422
|
+
{ id: '4', label: 'Option Four' },
|
|
423
|
+
{ id: '5', label: 'Option Five' },
|
|
424
|
+
];
|
|
425
|
+
|
|
426
|
+
// ===== Popover Variant (Dialog) =====
|
|
427
|
+
|
|
428
|
+
const languages = ['English', 'German', 'Tobagonian Creole English', 'Spanish'];
|
|
429
|
+
|
|
430
|
+
// ===== Custom Menu Item Rendering =====
|
|
431
|
+
|
|
432
|
+
// A custom renderer for each option, showing a two-line entity layout
|
|
433
|
+
// (label + meta) via `renderMenuItem`.
|
|
434
|
+
const renderEntityMenuItem = ({
|
|
435
|
+
option,
|
|
436
|
+
}: {
|
|
437
|
+
option: Pick<ComboboxItemOption, 'label' | 'subTitle' | 'disabled'>;
|
|
438
|
+
}) => (
|
|
439
|
+
<span>
|
|
440
|
+
<span
|
|
441
|
+
className={`slds-listbox__option-text slds-listbox__option-text_entity${
|
|
442
|
+
option.disabled ? ' slds-disabled-text' : ''
|
|
443
|
+
}`}
|
|
444
|
+
>
|
|
445
|
+
{option.label}
|
|
446
|
+
</span>
|
|
447
|
+
<span
|
|
448
|
+
className={`slds-listbox__option-meta slds-listbox__option-meta_entity${
|
|
449
|
+
option.disabled ? ' slds-disabled-text' : ''
|
|
450
|
+
}`}
|
|
451
|
+
>
|
|
452
|
+
{option.subTitle || ' '}
|
|
453
|
+
</span>
|
|
454
|
+
</span>
|
|
455
|
+
);
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### Base
|
|
459
|
+
|
|
460
|
+
```tsx
|
|
461
|
+
const Base = () => {
|
|
462
|
+
const [inputValue, setInputValue] = useState('');
|
|
463
|
+
const [selection, setSelection] = useState<ComboboxOption[]>(
|
|
464
|
+
accountsWithIcons.slice(0, 2)
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
return (
|
|
468
|
+
<Combobox
|
|
469
|
+
id="base-combobox"
|
|
470
|
+
labels={{ label: 'Search', placeholder: 'Search Salesforce' }}
|
|
471
|
+
multiple
|
|
472
|
+
options={accountsWithIcons.filter(
|
|
473
|
+
(account) =>
|
|
474
|
+
!inputValue ||
|
|
475
|
+
account.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
476
|
+
)}
|
|
477
|
+
selection={selection}
|
|
478
|
+
value={inputValue}
|
|
479
|
+
events={{
|
|
480
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
481
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
482
|
+
setSelection(newSelection);
|
|
483
|
+
setInputValue('');
|
|
484
|
+
},
|
|
485
|
+
onRequestRemoveSelectedOption: (
|
|
486
|
+
_event,
|
|
487
|
+
{ selection: newSelection }
|
|
488
|
+
) => {
|
|
489
|
+
setSelection(newSelection);
|
|
490
|
+
},
|
|
491
|
+
}}
|
|
492
|
+
/>
|
|
493
|
+
);
|
|
494
|
+
};
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
### Base With Menu Subheader
|
|
498
|
+
|
|
499
|
+
```tsx
|
|
500
|
+
const BaseWithMenuSubheader = () => {
|
|
501
|
+
const [inputValue, setInputValue] = useState('');
|
|
502
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
503
|
+
|
|
504
|
+
const optionsWithSeparator: ComboboxOption[] = [
|
|
505
|
+
{ id: 'header', label: 'Recent Accounts', type: 'separator' },
|
|
506
|
+
...accountsWithIcons.slice(0, 3),
|
|
507
|
+
{ id: 'divider', type: 'separator' },
|
|
508
|
+
...accountsWithIcons.slice(3),
|
|
509
|
+
];
|
|
510
|
+
|
|
511
|
+
return (
|
|
512
|
+
<Combobox
|
|
513
|
+
id="base-with-subheader"
|
|
514
|
+
labels={{ label: 'Search', placeholder: 'Search Salesforce' }}
|
|
515
|
+
multiple
|
|
516
|
+
options={optionsWithSeparator}
|
|
517
|
+
selection={selection}
|
|
518
|
+
value={inputValue}
|
|
519
|
+
events={{
|
|
520
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
521
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
522
|
+
setSelection(newSelection);
|
|
523
|
+
setInputValue('');
|
|
524
|
+
},
|
|
525
|
+
onRequestRemoveSelectedOption: (
|
|
526
|
+
_event,
|
|
527
|
+
{ selection: newSelection }
|
|
528
|
+
) => {
|
|
529
|
+
setSelection(newSelection);
|
|
530
|
+
},
|
|
531
|
+
}}
|
|
532
|
+
/>
|
|
533
|
+
);
|
|
534
|
+
};
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### With Menu Separator
|
|
538
|
+
|
|
539
|
+
```tsx
|
|
540
|
+
const WithMenuSeparator = () => {
|
|
541
|
+
const [inputValue, setInputValue] = useState('');
|
|
542
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
543
|
+
|
|
544
|
+
const optionsWithSeparator: ComboboxOption[] = [
|
|
545
|
+
...accountsWithIcons.slice(0, 2),
|
|
546
|
+
{ id: 'divider-1', type: 'separator' },
|
|
547
|
+
...accountsWithIcons.slice(2, 4),
|
|
548
|
+
{ id: 'divider-2', type: 'separator' },
|
|
549
|
+
...accountsWithIcons.slice(4),
|
|
550
|
+
];
|
|
551
|
+
|
|
552
|
+
return (
|
|
553
|
+
<Combobox
|
|
554
|
+
id="base-with-separator"
|
|
555
|
+
labels={{ label: 'Search', placeholder: 'Search Salesforce' }}
|
|
556
|
+
options={optionsWithSeparator}
|
|
557
|
+
selection={selection}
|
|
558
|
+
value={inputValue}
|
|
559
|
+
events={{
|
|
560
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
561
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
562
|
+
setSelection(newSelection);
|
|
563
|
+
setInputValue('');
|
|
564
|
+
},
|
|
565
|
+
onRequestRemoveSelectedOption: (
|
|
566
|
+
_event,
|
|
567
|
+
{ selection: newSelection }
|
|
568
|
+
) => {
|
|
569
|
+
setSelection(newSelection);
|
|
570
|
+
},
|
|
571
|
+
}}
|
|
572
|
+
/>
|
|
573
|
+
);
|
|
574
|
+
};
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### With Inline Help Tooltip
|
|
578
|
+
|
|
579
|
+
```tsx
|
|
580
|
+
const WithInlineHelpTooltip = () => {
|
|
581
|
+
const [inputValue, setInputValue] = useState('');
|
|
582
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
583
|
+
|
|
584
|
+
return (
|
|
585
|
+
<Combobox
|
|
586
|
+
id="inline-help-tooltip"
|
|
587
|
+
fieldLevelHelpTooltip={
|
|
588
|
+
<Tooltip
|
|
589
|
+
align="top left"
|
|
590
|
+
content="Type to search Salesforce objects..."
|
|
591
|
+
id="combobox-help-tooltip"
|
|
592
|
+
/>
|
|
593
|
+
}
|
|
594
|
+
labels={{ label: 'Search', placeholder: 'Search Salesforce' }}
|
|
595
|
+
options={accountsWithIcons.filter(
|
|
596
|
+
(account) =>
|
|
597
|
+
!inputValue ||
|
|
598
|
+
account.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
599
|
+
)}
|
|
600
|
+
selection={selection}
|
|
601
|
+
value={inputValue}
|
|
602
|
+
events={{
|
|
603
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
604
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
605
|
+
setSelection(newSelection);
|
|
606
|
+
setInputValue('');
|
|
607
|
+
},
|
|
608
|
+
onRequestRemoveSelectedOption: (
|
|
609
|
+
_event,
|
|
610
|
+
{ selection: newSelection }
|
|
611
|
+
) => {
|
|
612
|
+
setSelection(newSelection);
|
|
613
|
+
},
|
|
614
|
+
}}
|
|
615
|
+
/>
|
|
616
|
+
);
|
|
617
|
+
};
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
### With Inherited Menu Width
|
|
621
|
+
|
|
622
|
+
```tsx
|
|
623
|
+
const WithInheritedMenuWidth = () => {
|
|
624
|
+
const longLabelAccounts = [
|
|
625
|
+
{
|
|
626
|
+
id: '1',
|
|
627
|
+
label:
|
|
628
|
+
'A very very very very very very very very very very very long title to show how menu width will behave',
|
|
629
|
+
subTitle: 'Account • San Francisco',
|
|
630
|
+
category: 'account',
|
|
631
|
+
},
|
|
632
|
+
...accountsWithIcons.slice(1),
|
|
633
|
+
];
|
|
634
|
+
const [inputValue, setInputValue] = useState('');
|
|
635
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
636
|
+
|
|
637
|
+
return (
|
|
638
|
+
<Combobox
|
|
639
|
+
id="inherit-menu-width"
|
|
640
|
+
inheritWidthOf="menu"
|
|
641
|
+
labels={{ label: 'Search', placeholder: 'Search Salesforce' }}
|
|
642
|
+
menuMaxWidth="500px"
|
|
643
|
+
options={longLabelAccounts.filter(
|
|
644
|
+
(account) =>
|
|
645
|
+
!inputValue ||
|
|
646
|
+
account.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
647
|
+
)}
|
|
648
|
+
selection={selection}
|
|
649
|
+
value={inputValue}
|
|
650
|
+
events={{
|
|
651
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
652
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
653
|
+
setSelection(newSelection);
|
|
654
|
+
setInputValue('');
|
|
655
|
+
},
|
|
656
|
+
onRequestRemoveSelectedOption: (
|
|
657
|
+
_event,
|
|
658
|
+
{ selection: newSelection }
|
|
659
|
+
) => {
|
|
660
|
+
setSelection(newSelection);
|
|
661
|
+
},
|
|
662
|
+
}}
|
|
663
|
+
/>
|
|
664
|
+
);
|
|
665
|
+
};
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
### With Scrollable Menu
|
|
669
|
+
|
|
670
|
+
```tsx
|
|
671
|
+
const WithScrollableMenu = () => {
|
|
672
|
+
const manyOptions = Array.from({ length: 15 }, (_, index) => ({
|
|
673
|
+
id: `option-${index}`,
|
|
674
|
+
label: `Option ${index + 1}`,
|
|
675
|
+
}));
|
|
676
|
+
const [inputValue, setInputValue] = useState('');
|
|
677
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
678
|
+
|
|
679
|
+
return (
|
|
680
|
+
<Combobox
|
|
681
|
+
id="scrollable-menu"
|
|
682
|
+
labels={{ label: 'Search', placeholder: 'Search Options' }}
|
|
683
|
+
menuItemVisibleLength={5}
|
|
684
|
+
options={manyOptions.filter(
|
|
685
|
+
(option) =>
|
|
686
|
+
!inputValue ||
|
|
687
|
+
option.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
688
|
+
)}
|
|
689
|
+
selection={selection}
|
|
690
|
+
value={inputValue}
|
|
691
|
+
events={{
|
|
692
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
693
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
694
|
+
setSelection(newSelection);
|
|
695
|
+
setInputValue('');
|
|
696
|
+
},
|
|
697
|
+
onRequestRemoveSelectedOption: (
|
|
698
|
+
_event,
|
|
699
|
+
{ selection: newSelection }
|
|
700
|
+
) => {
|
|
701
|
+
setSelection(newSelection);
|
|
702
|
+
},
|
|
703
|
+
}}
|
|
704
|
+
/>
|
|
705
|
+
);
|
|
706
|
+
};
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
### With Custom Input Component
|
|
710
|
+
|
|
711
|
+
```tsx
|
|
712
|
+
const WithCustomInputComponent = () => {
|
|
713
|
+
const [inputValue, setInputValue] = useState('');
|
|
714
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
715
|
+
|
|
716
|
+
return (
|
|
717
|
+
<Combobox
|
|
718
|
+
id="custom-input"
|
|
719
|
+
input={
|
|
720
|
+
<Input
|
|
721
|
+
autoComplete="off"
|
|
722
|
+
label="Search"
|
|
723
|
+
placeholder="My overridden placeholder"
|
|
724
|
+
/>
|
|
725
|
+
}
|
|
726
|
+
labels={{ label: 'Search', placeholder: 'Search Salesforce' }}
|
|
727
|
+
options={accountsWithIcons.filter(
|
|
728
|
+
(account) =>
|
|
729
|
+
!inputValue ||
|
|
730
|
+
account.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
731
|
+
)}
|
|
732
|
+
selection={selection}
|
|
733
|
+
value={inputValue}
|
|
734
|
+
events={{
|
|
735
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
736
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
737
|
+
setSelection(newSelection);
|
|
738
|
+
setInputValue('');
|
|
739
|
+
},
|
|
740
|
+
onRequestRemoveSelectedOption: (
|
|
741
|
+
_event,
|
|
742
|
+
{ selection: newSelection }
|
|
743
|
+
) => {
|
|
744
|
+
setSelection(newSelection);
|
|
745
|
+
},
|
|
746
|
+
}}
|
|
747
|
+
/>
|
|
748
|
+
);
|
|
749
|
+
};
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
### Inline Single
|
|
753
|
+
|
|
754
|
+
```tsx
|
|
755
|
+
const InlineSingle = () => {
|
|
756
|
+
const [inputValue, setInputValue] = useState('');
|
|
757
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
758
|
+
|
|
759
|
+
return (
|
|
760
|
+
<Combobox
|
|
761
|
+
id="inline-single"
|
|
762
|
+
labels={{ label: 'Account', placeholder: 'Search Accounts' }}
|
|
763
|
+
options={accountsWithIcons.filter(
|
|
764
|
+
(account) =>
|
|
765
|
+
!inputValue ||
|
|
766
|
+
account.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
767
|
+
)}
|
|
768
|
+
selection={selection}
|
|
769
|
+
value={inputValue}
|
|
770
|
+
variant="inline-listbox"
|
|
771
|
+
events={{
|
|
772
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
773
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
774
|
+
setSelection(newSelection);
|
|
775
|
+
setInputValue('');
|
|
776
|
+
},
|
|
777
|
+
onRequestRemoveSelectedOption: (
|
|
778
|
+
_event,
|
|
779
|
+
{ selection: newSelection }
|
|
780
|
+
) => {
|
|
781
|
+
setSelection(newSelection);
|
|
782
|
+
},
|
|
783
|
+
}}
|
|
784
|
+
/>
|
|
785
|
+
);
|
|
786
|
+
};
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
### Inline Multiple (deprecated)
|
|
790
|
+
|
|
791
|
+
```tsx
|
|
792
|
+
const InlineMultiple = () => {
|
|
793
|
+
const [inputValue, setInputValue] = useState('');
|
|
794
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
795
|
+
|
|
796
|
+
return (
|
|
797
|
+
<Combobox
|
|
798
|
+
id="inline-multiple"
|
|
799
|
+
labels={{ label: 'Accounts', placeholder: 'Search Accounts' }}
|
|
800
|
+
multiple
|
|
801
|
+
options={accountsWithIcons.filter(
|
|
802
|
+
(account) =>
|
|
803
|
+
!inputValue ||
|
|
804
|
+
account.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
805
|
+
)}
|
|
806
|
+
selection={selection}
|
|
807
|
+
value={inputValue}
|
|
808
|
+
variant="inline-listbox"
|
|
809
|
+
events={{
|
|
810
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
811
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
812
|
+
setSelection(newSelection);
|
|
813
|
+
setInputValue('');
|
|
814
|
+
},
|
|
815
|
+
onRequestRemoveSelectedOption: (
|
|
816
|
+
_event,
|
|
817
|
+
{ selection: newSelection }
|
|
818
|
+
) => {
|
|
819
|
+
setSelection(newSelection);
|
|
820
|
+
},
|
|
821
|
+
}}
|
|
822
|
+
/>
|
|
823
|
+
);
|
|
824
|
+
};
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
### Search And Add Entities
|
|
828
|
+
|
|
829
|
+
```tsx
|
|
830
|
+
const SearchAndAddEntities = () => {
|
|
831
|
+
const [inputValue, setInputValue] = useState('');
|
|
832
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
833
|
+
|
|
834
|
+
return (
|
|
835
|
+
<Combobox
|
|
836
|
+
id="search-add-entities"
|
|
837
|
+
labels={{ label: 'Search', placeholder: 'Search Salesforce' }}
|
|
838
|
+
optionsAddItem={[
|
|
839
|
+
{
|
|
840
|
+
id: 'add-new-entity',
|
|
841
|
+
icon: (
|
|
842
|
+
<Icon
|
|
843
|
+
assistiveText={{ label: 'Add' }}
|
|
844
|
+
category="utility"
|
|
845
|
+
name="add"
|
|
846
|
+
size="x-small"
|
|
847
|
+
/>
|
|
848
|
+
),
|
|
849
|
+
label: 'New Entity',
|
|
850
|
+
},
|
|
851
|
+
]}
|
|
852
|
+
optionsSearchEntity={[
|
|
853
|
+
{
|
|
854
|
+
id: 'search-in-salesforce',
|
|
855
|
+
icon: (
|
|
856
|
+
<Icon
|
|
857
|
+
assistiveText={{ label: 'Search' }}
|
|
858
|
+
category="utility"
|
|
859
|
+
name="search"
|
|
860
|
+
size="x-small"
|
|
861
|
+
/>
|
|
862
|
+
),
|
|
863
|
+
label: 'Search in Salesforce',
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
id: 'search-in-accounts',
|
|
867
|
+
icon: (
|
|
868
|
+
<Icon
|
|
869
|
+
assistiveText={{ label: 'Search in Accounts' }}
|
|
870
|
+
category="utility"
|
|
871
|
+
name="search"
|
|
872
|
+
size="x-small"
|
|
873
|
+
/>
|
|
874
|
+
),
|
|
875
|
+
label: 'Search in Accounts',
|
|
876
|
+
},
|
|
877
|
+
]}
|
|
878
|
+
options={accountsWithIcons.filter(
|
|
879
|
+
(account) =>
|
|
880
|
+
!inputValue ||
|
|
881
|
+
account.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
882
|
+
)}
|
|
883
|
+
selection={selection}
|
|
884
|
+
value={inputValue}
|
|
885
|
+
variant="inline-listbox"
|
|
886
|
+
events={{
|
|
887
|
+
onChange: (_event, { value }) => setInputValue(value),
|
|
888
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
889
|
+
setSelection(newSelection);
|
|
890
|
+
setInputValue('');
|
|
891
|
+
},
|
|
892
|
+
onSelectActionItem: (...args) =>
|
|
893
|
+
console.log('onSelectActionItem', ...args),
|
|
894
|
+
onRequestRemoveSelectedOption: (
|
|
895
|
+
_event,
|
|
896
|
+
{ selection: newSelection }
|
|
897
|
+
) => {
|
|
898
|
+
setSelection(newSelection);
|
|
899
|
+
},
|
|
900
|
+
}}
|
|
901
|
+
/>
|
|
902
|
+
);
|
|
903
|
+
};
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
### Readonly Single
|
|
907
|
+
|
|
908
|
+
```tsx
|
|
909
|
+
const ReadonlySingle = () => {
|
|
910
|
+
const [selection, setSelection] = useState<ComboboxOption[]>([]);
|
|
911
|
+
|
|
912
|
+
return (
|
|
913
|
+
<Combobox
|
|
914
|
+
id="readonly-single"
|
|
915
|
+
labels={{ label: 'Select Option' }}
|
|
916
|
+
options={picklistOptions}
|
|
917
|
+
selection={selection}
|
|
918
|
+
variant="readonly"
|
|
919
|
+
events={{
|
|
920
|
+
onSelect: (_event, { selection: newSelection }) => {
|
|
921
|
+
setSelection(newSelection);
|
|
922
|
+
},
|
|
923
|
+
}}
|
|
924
|
+
/>
|
|
925
|
+
);
|
|
926
|
+
};
|
|
927
|
+
```
|
|
928
|
+
|
|
929
|
+
More stories: [combobox.examples.md](https://opensource.salesforce.com/design-system-react/components/combobox.examples.md).
|