@salmonui/dropdowns 0.0.0-stage → 0.3.0
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/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/combobox/Combobox.d.ts +54 -0
- package/dist/combobox/Combobox.d.ts.map +1 -0
- package/dist/combobox/Combobox.js +485 -0
- package/dist/combobox/Combobox.js.map +1 -0
- package/dist/combobox/ComboboxField.d.ts +9 -0
- package/dist/combobox/ComboboxField.d.ts.map +1 -0
- package/dist/combobox/ComboboxField.js +13 -0
- package/dist/combobox/ComboboxField.js.map +1 -0
- package/dist/combobox/columns-grid.d.ts +20 -0
- package/dist/combobox/columns-grid.d.ts.map +1 -0
- package/dist/combobox/columns-grid.js +106 -0
- package/dist/combobox/columns-grid.js.map +1 -0
- package/dist/combobox/columns.d.ts +45 -0
- package/dist/combobox/columns.d.ts.map +1 -0
- package/dist/combobox/columns.js +42 -0
- package/dist/combobox/columns.js.map +1 -0
- package/dist/combobox.css +706 -0
- package/dist/combobox.d.ts +6 -0
- package/dist/combobox.d.ts.map +1 -0
- package/dist/combobox.js +10 -0
- package/dist/combobox.js.map +1 -0
- package/dist/dropdown/core.d.ts +178 -0
- package/dist/dropdown/core.d.ts.map +1 -0
- package/dist/dropdown/core.js +591 -0
- package/dist/dropdown/core.js.map +1 -0
- package/dist/dropdown/field.d.ts +19 -0
- package/dist/dropdown/field.d.ts.map +1 -0
- package/dist/dropdown/field.js +48 -0
- package/dist/dropdown/field.js.map +1 -0
- package/dist/dropdown/locale.d.ts +3 -0
- package/dist/dropdown/locale.d.ts.map +1 -0
- package/dist/dropdown/locale.js +23 -0
- package/dist/dropdown/locale.js.map +1 -0
- package/dist/dropdown/overlay.d.ts +14 -0
- package/dist/dropdown/overlay.d.ts.map +1 -0
- package/dist/dropdown/overlay.js +46 -0
- package/dist/dropdown/overlay.js.map +1 -0
- package/dist/dropdown/popup.d.ts +44 -0
- package/dist/dropdown/popup.d.ts.map +1 -0
- package/dist/dropdown/popup.js +183 -0
- package/dist/dropdown/popup.js.map +1 -0
- package/dist/dropdown/types.d.ts +197 -0
- package/dist/dropdown/types.d.ts.map +1 -0
- package/dist/dropdown/types.js +4 -0
- package/dist/dropdown/types.js.map +1 -0
- package/dist/internal/caret.d.ts +18 -0
- package/dist/internal/caret.d.ts.map +1 -0
- package/dist/internal/caret.js +73 -0
- package/dist/internal/caret.js.map +1 -0
- package/dist/internal/collection/collection.d.ts +53 -0
- package/dist/internal/collection/collection.d.ts.map +1 -0
- package/dist/internal/collection/collection.js +161 -0
- package/dist/internal/collection/collection.js.map +1 -0
- package/dist/internal/collection/fold.d.ts +15 -0
- package/dist/internal/collection/fold.d.ts.map +1 -0
- package/dist/internal/collection/fold.js +33 -0
- package/dist/internal/collection/fold.js.map +1 -0
- package/dist/internal/collection/remote.d.ts +76 -0
- package/dist/internal/collection/remote.d.ts.map +1 -0
- package/dist/internal/collection/remote.js +261 -0
- package/dist/internal/collection/remote.js.map +1 -0
- package/dist/internal/collection/search.d.ts +28 -0
- package/dist/internal/collection/search.d.ts.map +1 -0
- package/dist/internal/collection/search.js +119 -0
- package/dist/internal/collection/search.js.map +1 -0
- package/dist/internal/collection/selection.d.ts +33 -0
- package/dist/internal/collection/selection.d.ts.map +1 -0
- package/dist/internal/collection/selection.js +82 -0
- package/dist/internal/collection/selection.js.map +1 -0
- package/dist/internal/collection/view.d.ts +22 -0
- package/dist/internal/collection/view.d.ts.map +1 -0
- package/dist/internal/collection/view.js +83 -0
- package/dist/internal/collection/view.js.map +1 -0
- package/dist/internal/select.d.ts +2 -0
- package/dist/internal/select.d.ts.map +1 -0
- package/dist/internal/select.js +7 -0
- package/dist/internal/select.js.map +1 -0
- package/dist/listbox/Listbox.d.ts +8 -0
- package/dist/listbox/Listbox.d.ts.map +1 -0
- package/dist/listbox/Listbox.js +887 -0
- package/dist/listbox/Listbox.js.map +1 -0
- package/dist/listbox/drag-types.d.ts +50 -0
- package/dist/listbox/drag-types.d.ts.map +1 -0
- package/dist/listbox/drag-types.js +6 -0
- package/dist/listbox/drag-types.js.map +1 -0
- package/dist/listbox/drag.d.ts +33 -0
- package/dist/listbox/drag.d.ts.map +1 -0
- package/dist/listbox/drag.js +201 -0
- package/dist/listbox/drag.js.map +1 -0
- package/dist/listbox/grid.d.ts +28 -0
- package/dist/listbox/grid.d.ts.map +1 -0
- package/dist/listbox/grid.js +165 -0
- package/dist/listbox/grid.js.map +1 -0
- package/dist/listbox/locale.d.ts +30 -0
- package/dist/listbox/locale.d.ts.map +1 -0
- package/dist/listbox/locale.js +25 -0
- package/dist/listbox/locale.js.map +1 -0
- package/dist/listbox/move.d.ts +16 -0
- package/dist/listbox/move.d.ts.map +1 -0
- package/dist/listbox/move.js +70 -0
- package/dist/listbox/move.js.map +1 -0
- package/dist/listbox/types.d.ts +210 -0
- package/dist/listbox/types.d.ts.map +1 -0
- package/dist/listbox/types.js +2 -0
- package/dist/listbox/types.js.map +1 -0
- package/dist/listbox.css +330 -0
- package/dist/listbox.d.ts +6 -0
- package/dist/listbox.d.ts.map +1 -0
- package/dist/listbox.js +7 -0
- package/dist/listbox.js.map +1 -0
- package/dist/mention/Mention.d.ts +5 -0
- package/dist/mention/Mention.d.ts.map +1 -0
- package/dist/mention/Mention.js +530 -0
- package/dist/mention/Mention.js.map +1 -0
- package/dist/mention/query.d.ts +27 -0
- package/dist/mention/query.d.ts.map +1 -0
- package/dist/mention/query.js +53 -0
- package/dist/mention/query.js.map +1 -0
- package/dist/mention/store.d.ts +22 -0
- package/dist/mention/store.d.ts.map +1 -0
- package/dist/mention/store.js +25 -0
- package/dist/mention/store.js.map +1 -0
- package/dist/mention/types.d.ts +183 -0
- package/dist/mention/types.d.ts.map +1 -0
- package/dist/mention/types.js +2 -0
- package/dist/mention/types.js.map +1 -0
- package/dist/mention.css +116 -0
- package/dist/mention.d.ts +3 -0
- package/dist/mention.d.ts.map +1 -0
- package/dist/mention.js +7 -0
- package/dist/mention.js.map +1 -0
- package/dist/select/Select.d.ts +31 -0
- package/dist/select/Select.d.ts.map +1 -0
- package/dist/select/Select.js +362 -0
- package/dist/select/Select.js.map +1 -0
- package/dist/select/SelectField.d.ts +9 -0
- package/dist/select/SelectField.d.ts.map +1 -0
- package/dist/select/SelectField.js +13 -0
- package/dist/select/SelectField.js.map +1 -0
- package/dist/select.css +536 -0
- package/dist/select.d.ts +5 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +9 -0
- package/dist/select.js.map +1 -0
- package/dist/styles.css +1590 -0
- package/dist/tree-select/TreeSelect.d.ts +69 -0
- package/dist/tree-select/TreeSelect.d.ts.map +1 -0
- package/dist/tree-select/TreeSelect.js +597 -0
- package/dist/tree-select/TreeSelect.js.map +1 -0
- package/dist/tree-select/filter.d.ts +24 -0
- package/dist/tree-select/filter.d.ts.map +1 -0
- package/dist/tree-select/filter.js +74 -0
- package/dist/tree-select/filter.js.map +1 -0
- package/dist/tree-select/locale.d.ts +3 -0
- package/dist/tree-select/locale.d.ts.map +1 -0
- package/dist/tree-select/locale.js +8 -0
- package/dist/tree-select/locale.js.map +1 -0
- package/dist/tree-select/popup.d.ts +19 -0
- package/dist/tree-select/popup.d.ts.map +1 -0
- package/dist/tree-select/popup.js +418 -0
- package/dist/tree-select/popup.js.map +1 -0
- package/dist/tree-select/types.d.ts +152 -0
- package/dist/tree-select/types.d.ts.map +1 -0
- package/dist/tree-select/types.js +4 -0
- package/dist/tree-select/types.js.map +1 -0
- package/dist/tree-select.css +601 -0
- package/dist/tree-select.d.ts +5 -0
- package/dist/tree-select.d.ts.map +1 -0
- package/dist/tree-select.js +10 -0
- package/dist/tree-select.js.map +1 -0
- package/package.json +65 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NuLL
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @salmonui/dropdowns
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ListBox, Select, Combobox, TreeSelect and Mention for Salmon UI.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @salmonui/dropdowns @salmonui/core react react-dom
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
`react` and `react-dom` `>=19` are peer dependencies. ESM only.
|
|
10
|
+
Every `@salmonui/*` package of an application must resolve to the same
|
|
11
|
+
version (they are released together and exact-pinned to each other);
|
|
12
|
+
`@salmonui/core` warns in development when a second copy loads.
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { Select } from '@salmonui/dropdowns/select';
|
|
16
|
+
import { Combobox } from '@salmonui/dropdowns/combobox';
|
|
17
|
+
import { TreeSelect } from '@salmonui/dropdowns/tree-select';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Import the theme stylesheet once per application, then the
|
|
21
|
+
stylesheet of each family you use:
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import '@salmonui/core/styles.css'; // the theme, once per application
|
|
25
|
+
import '@salmonui/dropdowns/listbox/styles.css';
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Each family has its own `@salmonui/dropdowns/<family>/styles.css`.
|
|
29
|
+
A family stylesheet carries its own rules and those of every family and shared
|
|
30
|
+
module it renders, so it is the only stylesheet that family needs.
|
|
31
|
+
|
|
32
|
+
Public entry points:
|
|
33
|
+
|
|
34
|
+
- `@salmonui/dropdowns/listbox`
|
|
35
|
+
- `@salmonui/dropdowns/select`
|
|
36
|
+
- `@salmonui/dropdowns/combobox`
|
|
37
|
+
- `@salmonui/dropdowns/tree-select`
|
|
38
|
+
- `@salmonui/dropdowns/mention`
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type Ref } from 'react';
|
|
2
|
+
import type { DropdownValue } from '../dropdown/types.js';
|
|
3
|
+
import type { DropdownCommonProps, DropdownDomProps, DropdownEventSource, DropdownFieldProps, DropdownLocaleText, DropdownValueChangeEvent } from '../dropdown/types.js';
|
|
4
|
+
import { type ComboboxColumn, type ComboboxSort } from './columns.js';
|
|
5
|
+
export declare const COMBOBOX_DEFAULT_LOCALE_TEXT: DropdownLocaleText;
|
|
6
|
+
export type ComboboxInputChangeReason = 'input' | 'select' | 'clear' | 'escape' | 'blur' | 'reset';
|
|
7
|
+
export interface ComboboxInputChangeEvent {
|
|
8
|
+
readonly source: DropdownEventSource;
|
|
9
|
+
readonly reason: ComboboxInputChangeReason;
|
|
10
|
+
}
|
|
11
|
+
interface ComboboxOwnProps<Item> extends DropdownCommonProps<Item>, DropdownFieldProps, DropdownDomProps {
|
|
12
|
+
/** Text of the input (reactive); `onInputChange` reports every edit. */
|
|
13
|
+
readonly inputValue?: string;
|
|
14
|
+
readonly defaultInputValue?: string;
|
|
15
|
+
readonly onInputChange?: (text: string, event: ComboboxInputChangeEvent) => void;
|
|
16
|
+
/** Committed text without a matching item becomes the value. Default `false`. */
|
|
17
|
+
readonly creatable?: boolean;
|
|
18
|
+
/** Builds the item for created text; `null` rejects it. Default: the text itself. */
|
|
19
|
+
readonly onCreateItem?: (text: string) => Item | null;
|
|
20
|
+
/** Completes the first match inline (`aria-autocomplete="both"`). */
|
|
21
|
+
readonly autofill?: boolean;
|
|
22
|
+
/** The dropdown button (not in the tab order). Default `true`. */
|
|
23
|
+
readonly showTrigger?: boolean;
|
|
24
|
+
/** A click in the input opens the popup. Default `true`. */
|
|
25
|
+
readonly openOnClick?: boolean;
|
|
26
|
+
/** Typed text is committed (created) when focus leaves. */
|
|
27
|
+
readonly commitOnBlur?: boolean;
|
|
28
|
+
/** Table popup (MultiColumn ComboBox): a lightweight `role="grid"`. */
|
|
29
|
+
readonly columns?: readonly ComboboxColumn<Item>[];
|
|
30
|
+
/** Fixed row height of the `columns` popup in px. */
|
|
31
|
+
readonly rowHeight?: number;
|
|
32
|
+
readonly gridLines?: 'default' | 'both' | 'none' | 'horizontal' | 'vertical';
|
|
33
|
+
readonly striped?: boolean;
|
|
34
|
+
/** Header sorting of the `columns` popup. Default `true`. */
|
|
35
|
+
readonly sorting?: boolean | ComboboxSort;
|
|
36
|
+
/** The `<input role="combobox">`. */
|
|
37
|
+
readonly ref?: Ref<HTMLInputElement>;
|
|
38
|
+
}
|
|
39
|
+
export interface ComboboxSingleProps<Item> extends ComboboxOwnProps<Item> {
|
|
40
|
+
readonly multiple?: false;
|
|
41
|
+
readonly value?: DropdownValue | null;
|
|
42
|
+
readonly defaultValue?: DropdownValue | null;
|
|
43
|
+
readonly onValueChange?: (value: DropdownValue | null, event: DropdownValueChangeEvent<Item>) => void;
|
|
44
|
+
}
|
|
45
|
+
export interface ComboboxMultipleProps<Item> extends ComboboxOwnProps<Item> {
|
|
46
|
+
readonly multiple: true;
|
|
47
|
+
readonly value?: readonly DropdownValue[];
|
|
48
|
+
readonly defaultValue?: readonly DropdownValue[];
|
|
49
|
+
readonly onValueChange?: (value: readonly DropdownValue[], event: DropdownValueChangeEvent<Item>) => void;
|
|
50
|
+
}
|
|
51
|
+
export type ComboboxProps<Item = unknown> = ComboboxSingleProps<Item> | ComboboxMultipleProps<Item>;
|
|
52
|
+
export declare function Combobox<Item = unknown>(props: ComboboxProps<Item>): import("react").JSX.Element;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=Combobox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Combobox.d.ts","sourceRoot":"","sources":["../../src/combobox/Combobox.tsx"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createElement as _createElement } from "react";
|
|
4
|
+
// Combobox: the APG editable combobox with list autocomplete. The
|
|
5
|
+
// `<input role="combobox">` keeps DOM focus; the popup
|
|
6
|
+
// is driven by `aria-activedescendant`. Covers ComboBox, AutoComplete
|
|
7
|
+
// (`creatable showTrigger={false}`), the typing MultiSelect (`multiple`,
|
|
8
|
+
// chips, `creatable`, `commitOnBlur`) and MultiColumn ComboBox (`columns`,
|
|
9
|
+
// a lazy `role="grid"` popup).
|
|
10
|
+
import { lazy, Suspense, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
+
import { foldText } from '../internal/collection/fold.js';
|
|
12
|
+
import { useControllableState } from '@salmonui/core/internal/controllable';
|
|
13
|
+
import { isRtl } from '@salmonui/core/internal/position';
|
|
14
|
+
import { DEV } from '@salmonui/core/internal/dev';
|
|
15
|
+
import { assignRef, changeEvent, resolvePopupContext, usePopupModule, HiddenSelect, Icon, ICON_CHEVRON, ICON_X, partClass, partStyle, preventFocusLoss, rootClass, sourceOf, useDropdownController } from '../dropdown/core.js';
|
|
16
|
+
import { DROPDOWN_DEFAULT_LOCALE_TEXT } from '../dropdown/locale.js';
|
|
17
|
+
import { useLocale, useLocaleText } from '@salmonui/core/internal/locale';
|
|
18
|
+
import { compareBy } from './columns.js';
|
|
19
|
+
export const COMBOBOX_DEFAULT_LOCALE_TEXT = DROPDOWN_DEFAULT_LOCALE_TEXT;
|
|
20
|
+
// The `columns` grid popup is a lazy chunk (not in the initial JS).
|
|
21
|
+
const ColumnsGrid = lazy(() => import('./columns-grid.js'));
|
|
22
|
+
const EMPTY = Object.freeze([]);
|
|
23
|
+
const toArray = (value) => (value == null ? EMPTY : Array.isArray(value) ? value : [value]);
|
|
24
|
+
export function Combobox(props) {
|
|
25
|
+
const { open: openProp, defaultOpen, onOpenChange, matchCase = false, ignoreAccents = false, minSearchLength = 0, searchFields, clearable = true, placeholder, disabled = false, readOnly = false, name, required, form, id, maxSelected, closeOnSelect, maxVisibleValues, renderChip, getChipProps, className, style, size, inputValue: inputValueProp, defaultInputValue, onInputChange, creatable = false, onCreateItem, autofill = false, showTrigger = true, openOnClick = true, commitOnBlur = false, columns, rowHeight, gridLines = 'default', striped = false, sorting = true, ref, multiple: multipleProp, value: valueProp, defaultValue, onValueChange, data: _data, getItemValue: _getItemValue, getItemLabel: _getItemLabel, getItemGroup: _getItemGroup, getItemIcon: _getItemIcon, isItemDisabled: _isItemDisabled, selectedItems: _selectedItems, searchOperator: _searchOperator, debounce: _debounce, maxResults: _maxResults, query: _query, virtualization: _virtualization, maxVisibleItems: _maxVisibleItems, popupMode: _popupMode, autoFocus, indicator: _indicator, showSelectAll: _showSelectAll, groupSelection: _groupSelection, hideSelected: _hideSelected, valueSeparator: _valueSeparator, locale: localeProp, renderItem: _renderItem, renderValue: _renderValue, renderGroupHeader: _renderGroupHeader, renderEmpty: _renderEmpty, renderError: _renderError, renderLoading: _renderLoading, popupHeader: _popupHeader, popupFooter: _popupFooter, getItemProps: _getItemProps, highlightMatches: _highlightMatches, loading: _loading, onLoadError: _onLoadError, localeText: localeTextProp, classNames: _classNames, styles: _styles, ...dom } = props;
|
|
26
|
+
const multiple = multipleProp === true;
|
|
27
|
+
const reactId = useId();
|
|
28
|
+
const listId = `${reactId}-listbox`;
|
|
29
|
+
const inputRef = useRef(null);
|
|
30
|
+
const rootRef = useRef(null);
|
|
31
|
+
const chipsRef = useRef(null);
|
|
32
|
+
const composing = useRef(false);
|
|
33
|
+
const [initial] = useState(() => toArray(defaultValue));
|
|
34
|
+
const [values, setValues] = useControllableState(valueProp === undefined ? undefined : toArray(valueProp), initial, onValueChange
|
|
35
|
+
? (next, event) => {
|
|
36
|
+
if (multiple)
|
|
37
|
+
onValueChange?.(next, event);
|
|
38
|
+
else
|
|
39
|
+
onValueChange?.(next[0] ?? null, event);
|
|
40
|
+
}
|
|
41
|
+
: undefined, DEV ? 'Combobox value' : undefined);
|
|
42
|
+
const [open, setOpenState] = useControllableState(openProp, false, onOpenChange, DEV ? 'Combobox open' : undefined);
|
|
43
|
+
const [popupContext, setPopupContext] = useState(null);
|
|
44
|
+
const popupModule = usePopupModule();
|
|
45
|
+
// Typed text: `null` while the input shows the committed value (no filtering).
|
|
46
|
+
const [typed, setTyped] = useState(defaultInputValue ?? null);
|
|
47
|
+
// Inline completion of `autofill` (shown, not searched).
|
|
48
|
+
const [completion, setCompletion] = useState(null);
|
|
49
|
+
const [extraItems, setExtraItems] = useState(() => new Map());
|
|
50
|
+
const [sortBy, setSortBy] = useState(() => (typeof sorting === 'object' && sorting.sortBy ? sorting.sortBy : []));
|
|
51
|
+
const sortByProp = typeof sorting === 'object' ? sorting.sortBy : undefined;
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
// `sorting.sortBy` is reactive: re-applied when it changes.
|
|
54
|
+
if (sortByProp)
|
|
55
|
+
setSortBy(sortByProp);
|
|
56
|
+
}, [sortByProp]);
|
|
57
|
+
const compare = useMemo(() => (columns && sortBy.length ? compareBy(sortBy, columns) : undefined), [columns, sortBy]);
|
|
58
|
+
const searchTextOf = useMemo(() => (columns && searchFields?.length ? (item) => searchFields.map((f) => String(item[f] ?? '')).join(' ') : undefined), [columns, searchFields]);
|
|
59
|
+
const searchText = inputValueProp !== undefined ? (typed !== null ? inputValueProp : '') : (typed ?? '');
|
|
60
|
+
const ctl = useDropdownController({
|
|
61
|
+
kind: 'combobox',
|
|
62
|
+
props,
|
|
63
|
+
localeText: useLocaleText('combobox', localeTextProp),
|
|
64
|
+
locale: useLocale(localeProp),
|
|
65
|
+
multiple,
|
|
66
|
+
values,
|
|
67
|
+
setValues,
|
|
68
|
+
open,
|
|
69
|
+
listId,
|
|
70
|
+
searchText: searchText.length >= minSearchLength ? searchText : '',
|
|
71
|
+
extraItems,
|
|
72
|
+
wantSearch: true,
|
|
73
|
+
defaultOperator: 'startsWith',
|
|
74
|
+
searchTextOf,
|
|
75
|
+
compare,
|
|
76
|
+
sorting: columns && sortBy.length ? sortBy : undefined,
|
|
77
|
+
});
|
|
78
|
+
const { store, text } = ctl;
|
|
79
|
+
const selectedLabel = !multiple && values.length ? ctl.labelFor(values[0]) : '';
|
|
80
|
+
const shown = inputValueProp ?? completion ?? typed ?? (multiple ? '' : selectedLabel);
|
|
81
|
+
// Inline completion: select the completed part after render (never while composing).
|
|
82
|
+
useLayoutEffect(() => {
|
|
83
|
+
const el = inputRef.current;
|
|
84
|
+
if (!el || completion === null || typed === null)
|
|
85
|
+
return;
|
|
86
|
+
if (el.ownerDocument.activeElement === el)
|
|
87
|
+
el.setSelectionRange(typed.length, completion.length, 'forward');
|
|
88
|
+
}, [completion, typed]);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (defaultOpen && openProp === undefined)
|
|
91
|
+
setOpenState(true, Object.freeze({ source: 'api', reason: 'trigger' }));
|
|
92
|
+
// Read once at mount.
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, []);
|
|
95
|
+
useLayoutEffect(() => {
|
|
96
|
+
if (open && !popupContext && rootRef.current)
|
|
97
|
+
setPopupContext(resolvePopupContext('popover', rootRef.current));
|
|
98
|
+
}, [open, popupContext]);
|
|
99
|
+
const wasOpen = useRef(false);
|
|
100
|
+
useLayoutEffect(() => {
|
|
101
|
+
if (open && popupContext && popupModule && !wasOpen.current) {
|
|
102
|
+
wasOpen.current = true;
|
|
103
|
+
store.set({ first: 0, last: 0 });
|
|
104
|
+
if (store.getState().active === -1 && typed === null)
|
|
105
|
+
ctl.setActive(ctl.initialActive());
|
|
106
|
+
else
|
|
107
|
+
ctl.setActive(store.getState().active);
|
|
108
|
+
}
|
|
109
|
+
else if (!open && wasOpen.current) {
|
|
110
|
+
wasOpen.current = false;
|
|
111
|
+
store.set({ active: -1, first: 0, last: 0 });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!open || !popupContext || !popupModule)
|
|
116
|
+
return;
|
|
117
|
+
const sync = () => {
|
|
118
|
+
const el = inputRef.current;
|
|
119
|
+
if (!el)
|
|
120
|
+
return;
|
|
121
|
+
const active = store.getState().active;
|
|
122
|
+
if (active < 0)
|
|
123
|
+
el.removeAttribute('aria-activedescendant');
|
|
124
|
+
else
|
|
125
|
+
el.setAttribute('aria-activedescendant', ctl.optionId(active));
|
|
126
|
+
};
|
|
127
|
+
sync();
|
|
128
|
+
const unsubscribe = store.subscribe(sync);
|
|
129
|
+
return () => {
|
|
130
|
+
unsubscribe();
|
|
131
|
+
inputRef.current?.removeAttribute('aria-activedescendant');
|
|
132
|
+
};
|
|
133
|
+
}, [open, popupContext, popupModule, store, ctl.listId]);
|
|
134
|
+
// A new search resets the window; the first match becomes active with autofill.
|
|
135
|
+
useLayoutEffect(() => {
|
|
136
|
+
if (!open || !popupContext || typed === null)
|
|
137
|
+
return;
|
|
138
|
+
store.set({ active: -1, first: 0, last: 0 });
|
|
139
|
+
if (ctl.listRef.current)
|
|
140
|
+
ctl.listRef.current.scrollTop = 0;
|
|
141
|
+
if (autofill || (columns !== undefined && typed !== ''))
|
|
142
|
+
ctl.setActive(ctl.move('first'));
|
|
143
|
+
// Only when a new result set arrives.
|
|
144
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
145
|
+
}, [ctl.resultKey]);
|
|
146
|
+
const setOpen = (next, source, reason) => {
|
|
147
|
+
if (next === open)
|
|
148
|
+
return;
|
|
149
|
+
if (next) {
|
|
150
|
+
if (disabled || readOnly)
|
|
151
|
+
return;
|
|
152
|
+
if (rootRef.current)
|
|
153
|
+
setPopupContext(resolvePopupContext('popover', rootRef.current));
|
|
154
|
+
}
|
|
155
|
+
setOpenState(next, Object.freeze({ source, reason }));
|
|
156
|
+
};
|
|
157
|
+
const setText = (next, source, reason) => {
|
|
158
|
+
setTyped(next);
|
|
159
|
+
setCompletion(null);
|
|
160
|
+
onInputChange?.(next ?? (multiple ? '' : selectedLabel), Object.freeze({ source, reason }));
|
|
161
|
+
};
|
|
162
|
+
/** Creates (or finds) the item for `raw` text and commits it. */
|
|
163
|
+
const create = (raw, source) => {
|
|
164
|
+
const t = raw.trim();
|
|
165
|
+
if (!t)
|
|
166
|
+
return false;
|
|
167
|
+
// An existing label (case-insensitive) selects that item instead.
|
|
168
|
+
const i = findLabel(t, true);
|
|
169
|
+
if (i >= 0) {
|
|
170
|
+
commitValue(ctl.collection.value(i), source, multiple ? 'add' : 'select');
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
if (!creatable)
|
|
174
|
+
return false;
|
|
175
|
+
const item = onCreateItem ? onCreateItem(t) : t;
|
|
176
|
+
if (item === null || item === undefined)
|
|
177
|
+
return false;
|
|
178
|
+
const value = ctl.valueOf(item);
|
|
179
|
+
if (multiple && maxSelected !== undefined && values.length >= maxSelected && !values.includes(value))
|
|
180
|
+
return false;
|
|
181
|
+
const map = new Map(extraItems);
|
|
182
|
+
map.set(value, item);
|
|
183
|
+
setExtraItems(map);
|
|
184
|
+
if (multiple) {
|
|
185
|
+
if (!values.includes(value))
|
|
186
|
+
ctl.commit([...values, value], 'create', source, [item]);
|
|
187
|
+
}
|
|
188
|
+
else
|
|
189
|
+
ctl.commit([value], 'create', source, [item]);
|
|
190
|
+
return true;
|
|
191
|
+
};
|
|
192
|
+
/** First enabled item whose folded label equals (`exact`) or starts with `text`, or -1. */
|
|
193
|
+
const findLabel = (text, exact) => {
|
|
194
|
+
const q = foldText(text, ignoreAccents, matchCase);
|
|
195
|
+
const n = ctl.collection.size;
|
|
196
|
+
for (let i = 0; i < n; i++) {
|
|
197
|
+
if (ctl.collection.disabled(i))
|
|
198
|
+
continue;
|
|
199
|
+
const l = foldText(ctl.collection.label(i), ignoreAccents, matchCase);
|
|
200
|
+
if (exact ? l === q : l.startsWith(q))
|
|
201
|
+
return i;
|
|
202
|
+
}
|
|
203
|
+
return -1;
|
|
204
|
+
};
|
|
205
|
+
const commitValue = (value, source, reason) => {
|
|
206
|
+
if (multiple) {
|
|
207
|
+
if (!values.includes(value))
|
|
208
|
+
ctl.commit([...values, value], reason, source);
|
|
209
|
+
}
|
|
210
|
+
else if (values[0] !== value)
|
|
211
|
+
ctl.commit([value], 'select', source);
|
|
212
|
+
};
|
|
213
|
+
const chooseRow = (row, source) => {
|
|
214
|
+
const changed = ctl.choose(row, source, multiple ? 'add' : 'select');
|
|
215
|
+
if (!changed)
|
|
216
|
+
return;
|
|
217
|
+
setText(multiple ? '' : null, source, 'select');
|
|
218
|
+
if (closeOnSelect ?? !multiple)
|
|
219
|
+
setOpen(false, source, 'select');
|
|
220
|
+
};
|
|
221
|
+
const onChoose = (row, event) => {
|
|
222
|
+
chooseRow(row, sourceOf(event));
|
|
223
|
+
inputRef.current?.focus({ preventScroll: true });
|
|
224
|
+
};
|
|
225
|
+
/** Focus left the control: commit or revert the typed text, close. */
|
|
226
|
+
const settle = (source) => {
|
|
227
|
+
if (typed !== null) {
|
|
228
|
+
if (multiple) {
|
|
229
|
+
if (commitOnBlur && typed.trim())
|
|
230
|
+
create(typed, source);
|
|
231
|
+
setText(multiple ? '' : null, source, 'blur');
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
const t = typed.trim();
|
|
235
|
+
if (t === '') {
|
|
236
|
+
if (values.length)
|
|
237
|
+
ctl.clear(source);
|
|
238
|
+
}
|
|
239
|
+
else
|
|
240
|
+
create(t, source);
|
|
241
|
+
setText(null, source, 'blur');
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (open)
|
|
245
|
+
setOpen(false, source, 'blur');
|
|
246
|
+
};
|
|
247
|
+
const focusChip = (index) => {
|
|
248
|
+
const buttons = chipsRef.current?.querySelectorAll('.salmon-combobox-chip-remove');
|
|
249
|
+
if (!buttons?.length)
|
|
250
|
+
return;
|
|
251
|
+
const i = Math.max(0, Math.min(buttons.length - 1, index));
|
|
252
|
+
buttons[i]?.focus();
|
|
253
|
+
};
|
|
254
|
+
const onKeyDown = (event) => {
|
|
255
|
+
if (event.defaultPrevented || disabled)
|
|
256
|
+
return;
|
|
257
|
+
// IME composition: no filtering, autofill or Enter commit until it ends.
|
|
258
|
+
if (composing.current || event.nativeEvent.isComposing)
|
|
259
|
+
return;
|
|
260
|
+
const { key, altKey } = event;
|
|
261
|
+
const el = event.currentTarget;
|
|
262
|
+
let handled = true;
|
|
263
|
+
switch (key) {
|
|
264
|
+
case 'ArrowDown':
|
|
265
|
+
if (!open) {
|
|
266
|
+
setOpen(true, 'keyboard', 'keyboard');
|
|
267
|
+
if (!altKey && store.getState().active === -1)
|
|
268
|
+
store.set({ active: -1 });
|
|
269
|
+
}
|
|
270
|
+
else if (!altKey)
|
|
271
|
+
ctl.move('next');
|
|
272
|
+
break;
|
|
273
|
+
case 'ArrowUp':
|
|
274
|
+
if (!open) {
|
|
275
|
+
if (altKey)
|
|
276
|
+
break;
|
|
277
|
+
setOpen(true, 'keyboard', 'keyboard');
|
|
278
|
+
}
|
|
279
|
+
else if (altKey)
|
|
280
|
+
setOpen(false, 'keyboard', 'keyboard');
|
|
281
|
+
else
|
|
282
|
+
ctl.move('prev');
|
|
283
|
+
break;
|
|
284
|
+
case 'PageDown':
|
|
285
|
+
if (!open)
|
|
286
|
+
return;
|
|
287
|
+
ctl.move('pageDown');
|
|
288
|
+
break;
|
|
289
|
+
case 'PageUp':
|
|
290
|
+
if (!open)
|
|
291
|
+
return;
|
|
292
|
+
ctl.move('pageUp');
|
|
293
|
+
break;
|
|
294
|
+
case 'Enter': {
|
|
295
|
+
const active = store.getState().active;
|
|
296
|
+
if (open && active !== -1)
|
|
297
|
+
chooseRow(active, 'keyboard');
|
|
298
|
+
else if (typed !== null && typed.trim()) {
|
|
299
|
+
if (create(typed, 'keyboard')) {
|
|
300
|
+
setText(multiple ? '' : null, 'keyboard', 'select');
|
|
301
|
+
if (closeOnSelect ?? !multiple)
|
|
302
|
+
setOpen(false, 'keyboard', 'select');
|
|
303
|
+
}
|
|
304
|
+
else
|
|
305
|
+
handled = open;
|
|
306
|
+
}
|
|
307
|
+
else
|
|
308
|
+
handled = open;
|
|
309
|
+
if (open && !multiple && active === -1)
|
|
310
|
+
setOpen(false, 'keyboard', 'keyboard');
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case 'Escape':
|
|
314
|
+
if (open) {
|
|
315
|
+
setOpen(false, 'keyboard', 'escape');
|
|
316
|
+
if (completion !== null)
|
|
317
|
+
setCompletion(null);
|
|
318
|
+
}
|
|
319
|
+
else if (shown !== '') {
|
|
320
|
+
// A second Escape clears the input.
|
|
321
|
+
setText(multiple ? '' : null, 'keyboard', 'escape');
|
|
322
|
+
if (!multiple && values.length && clearable)
|
|
323
|
+
ctl.clear('keyboard');
|
|
324
|
+
else if (!multiple && typed !== null)
|
|
325
|
+
setTyped(null);
|
|
326
|
+
}
|
|
327
|
+
else
|
|
328
|
+
handled = false;
|
|
329
|
+
break;
|
|
330
|
+
case 'Tab':
|
|
331
|
+
handled = false;
|
|
332
|
+
break;
|
|
333
|
+
case 'Backspace':
|
|
334
|
+
// Backspace on an empty input removes the last chip.
|
|
335
|
+
if (multiple && el.value === '' && values.length && !readOnly)
|
|
336
|
+
ctl.remove(values[values.length - 1], 'keyboard');
|
|
337
|
+
else
|
|
338
|
+
handled = false;
|
|
339
|
+
break;
|
|
340
|
+
case 'ArrowLeft':
|
|
341
|
+
case 'ArrowRight': {
|
|
342
|
+
const back = isRtl(el) ? 'ArrowRight' : 'ArrowLeft';
|
|
343
|
+
if (multiple && key === back && el.selectionStart === 0 && el.selectionEnd === 0 && values.length)
|
|
344
|
+
focusChip(values.length - 1);
|
|
345
|
+
else
|
|
346
|
+
handled = false;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
default:
|
|
350
|
+
handled = false;
|
|
351
|
+
}
|
|
352
|
+
if (handled) {
|
|
353
|
+
event.preventDefault();
|
|
354
|
+
event.stopPropagation();
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
const onChipKeyDown = (event, index, value) => {
|
|
358
|
+
const el = event.currentTarget;
|
|
359
|
+
const rtl = isRtl(el);
|
|
360
|
+
const prev = rtl ? 'ArrowRight' : 'ArrowLeft';
|
|
361
|
+
const next = rtl ? 'ArrowLeft' : 'ArrowRight';
|
|
362
|
+
let handled = true;
|
|
363
|
+
if (event.key === prev)
|
|
364
|
+
focusChip(index - 1);
|
|
365
|
+
else if (event.key === next) {
|
|
366
|
+
if (index >= values.length - 1)
|
|
367
|
+
inputRef.current?.focus();
|
|
368
|
+
else
|
|
369
|
+
focusChip(index + 1);
|
|
370
|
+
}
|
|
371
|
+
else if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
372
|
+
ctl.remove(value, 'keyboard');
|
|
373
|
+
if (values.length <= 1)
|
|
374
|
+
inputRef.current?.focus();
|
|
375
|
+
else
|
|
376
|
+
queueMicrotask(() => focusChip(event.key === 'Backspace' ? index - 1 : index));
|
|
377
|
+
}
|
|
378
|
+
else if (event.key === 'Escape' || event.key === 'Tab' && !event.shiftKey) {
|
|
379
|
+
handled = event.key === 'Escape';
|
|
380
|
+
inputRef.current?.focus();
|
|
381
|
+
}
|
|
382
|
+
else
|
|
383
|
+
handled = false;
|
|
384
|
+
if (handled) {
|
|
385
|
+
event.preventDefault();
|
|
386
|
+
event.stopPropagation();
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
const setRef = useCallback((el) => assignRef(inputRef, ref, el), [ref]);
|
|
390
|
+
// Chips and the other multiple displays.
|
|
391
|
+
const items = values.map((v) => ctl.itemFor(v));
|
|
392
|
+
const labels = values.map((v, i) => {
|
|
393
|
+
const it = items[i];
|
|
394
|
+
return it === undefined ? String(v) : ctl.labelOf(it);
|
|
395
|
+
});
|
|
396
|
+
let valuesNode = null;
|
|
397
|
+
if (multiple && values.length) {
|
|
398
|
+
{
|
|
399
|
+
const max = maxVisibleValues ?? values.length;
|
|
400
|
+
valuesNode = (_jsxs("span", { ref: chipsRef, role: "list", "aria-label": text.selectedValues, className: "salmon-combobox-chips", children: [values.slice(0, max).map((v, i) => {
|
|
401
|
+
const it = items[i];
|
|
402
|
+
const label = labels[i];
|
|
403
|
+
const extra = it !== undefined ? getChipProps?.(it) : undefined;
|
|
404
|
+
const { className: extraClass, style: extraStyle, ...dataProps } = extra ?? {};
|
|
405
|
+
const remove = () => ctl.remove(v, 'api');
|
|
406
|
+
return (_createElement("span", { ...dataProps, key: String(v), role: "listitem", className: partClass(`salmon-combobox-chip${extraClass ? ` ${extraClass}` : ''}`, props, 'chip'), style: extraStyle || props.styles?.chip ? { ...props.styles?.chip, ...extraStyle } : undefined },
|
|
407
|
+
_jsx("span", { className: "salmon-combobox-chip-label", children: renderChip && it !== undefined ? renderChip({ item: it, label, remove, disabled }) : label }),
|
|
408
|
+
!disabled && !readOnly ? (_jsx("button", { type: "button", tabIndex: -1, className: "salmon-combobox-chip-remove", "aria-label": text.removeValue(label), onPointerDown: preventFocusLoss, onClick: (event) => {
|
|
409
|
+
ctl.remove(v, sourceOf(event));
|
|
410
|
+
inputRef.current?.focus({ preventScroll: true });
|
|
411
|
+
}, onKeyDown: (event) => onChipKeyDown(event, i, v), children: _jsx(Icon, { d: ICON_X, size: 14 }) })) : null));
|
|
412
|
+
}), values.length > max ? (_jsx("span", { role: "listitem", className: "salmon-combobox-chip salmon-combobox-more", children: text.moreValues(values.length - max) })) : null] }));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const labelledBy = dom['aria-labelledby'];
|
|
416
|
+
const label = dom['aria-label'];
|
|
417
|
+
const hasPopup = columns ? 'grid' : 'listbox';
|
|
418
|
+
const empty = values.length === 0;
|
|
419
|
+
const body = columns ? (_jsx(Suspense, { fallback: null, children: _jsx(ColumnsGrid, { ctl: ctl, columns: columns, rowHeight: rowHeight, gridLines: gridLines, striped: striped, sortBy: sortBy, sortable: sorting !== false, multiSort: typeof sorting === 'object' && sorting.multiple === true, onSort: setSortBy, onChoose: onChoose, labelledBy: labelledBy, label: label }) })) : undefined;
|
|
420
|
+
return (_jsxs("div", { ref: rootRef, className: rootClass('salmon-combobox', props.classNames?.root, className), style: style || props.styles?.root ? { ...props.styles?.root, ...style } : undefined, "data-size": size ?? 'md', "data-open": open ? '' : undefined, "data-disabled": disabled ? '' : undefined, "data-readonly": readOnly ? '' : undefined, "data-multiple": multiple ? '' : undefined, "data-empty": empty ? '' : undefined, onPointerDown: (event) => {
|
|
421
|
+
// A press on the field chrome (not the input or a chip button) focuses the input.
|
|
422
|
+
const target = event.target;
|
|
423
|
+
if (target !== inputRef.current && !target.closest('button') && !disabled) {
|
|
424
|
+
event.preventDefault();
|
|
425
|
+
inputRef.current?.focus();
|
|
426
|
+
}
|
|
427
|
+
}, children: [_jsxs("div", { className: partClass('salmon-combobox-field', props, 'trigger'), style: partStyle(props, 'trigger'), children: [valuesNode, _jsx("input", { ...dom, ref: setRef, id: id, type: "text", role: "combobox", "aria-autocomplete": autofill ? 'both' : 'list', "aria-haspopup": hasPopup, "aria-expanded": open, "aria-controls": open && popupContext ? listId : undefined, "aria-readonly": readOnly ? true : undefined, "aria-required": required ? true : undefined, autoComplete: "off", autoCapitalize: "none", spellCheck: false, disabled: disabled, readOnly: readOnly, autoFocus: autoFocus, placeholder: multiple && !empty ? undefined : placeholder, className: partClass('salmon-combobox-input', props, 'input'), style: partStyle(props, 'input'), value: shown, onChange: (event) => {
|
|
428
|
+
const t = event.currentTarget.value;
|
|
429
|
+
const native = event.nativeEvent;
|
|
430
|
+
setText(t, 'keyboard', 'input');
|
|
431
|
+
let nextCompletion = null;
|
|
432
|
+
if (autofill && !composing.current && t && native.inputType?.startsWith('insert')) {
|
|
433
|
+
// Inline completion from the first enabled match.
|
|
434
|
+
const i = findLabel(t, false);
|
|
435
|
+
const l = i >= 0 ? ctl.collection.label(i) : '';
|
|
436
|
+
if (l.length > t.length)
|
|
437
|
+
nextCompletion = t + l.slice(t.length);
|
|
438
|
+
}
|
|
439
|
+
setCompletion(nextCompletion);
|
|
440
|
+
if (!composing.current) {
|
|
441
|
+
if (t.length >= minSearchLength)
|
|
442
|
+
setOpen(true, 'keyboard', 'type');
|
|
443
|
+
else if (open)
|
|
444
|
+
setOpen(false, 'keyboard', 'type');
|
|
445
|
+
}
|
|
446
|
+
}, onCompositionStart: () => {
|
|
447
|
+
composing.current = true;
|
|
448
|
+
}, onCompositionEnd: (event) => {
|
|
449
|
+
composing.current = false;
|
|
450
|
+
// The search runs once composition ends.
|
|
451
|
+
const t = event.currentTarget.value;
|
|
452
|
+
setTyped(t);
|
|
453
|
+
if (t.length >= minSearchLength)
|
|
454
|
+
setOpen(true, 'keyboard', 'type');
|
|
455
|
+
}, onClick: (event) => {
|
|
456
|
+
dom.onClick?.(event);
|
|
457
|
+
if (!event.defaultPrevented && openOnClick && !open && shown.length >= minSearchLength)
|
|
458
|
+
setOpen(true, sourceOf(event), 'trigger');
|
|
459
|
+
}, onKeyDown: (event) => {
|
|
460
|
+
dom.onKeyDown?.(event);
|
|
461
|
+
onKeyDown(event);
|
|
462
|
+
}, onBlur: (event) => {
|
|
463
|
+
dom.onBlur?.(event);
|
|
464
|
+
const next = event.relatedTarget;
|
|
465
|
+
if (next && rootRef.current?.contains(next))
|
|
466
|
+
return;
|
|
467
|
+
settle('keyboard');
|
|
468
|
+
} }), clearable && !disabled && !readOnly && (!empty || shown !== '') ? (_jsx("button", { type: "button", tabIndex: -1, className: "salmon-combobox-clear", "aria-label": text.clear, onPointerDown: preventFocusLoss, onClick: (event) => {
|
|
469
|
+
ctl.clear(sourceOf(event));
|
|
470
|
+
setText(multiple ? '' : null, sourceOf(event), 'clear');
|
|
471
|
+
inputRef.current?.focus({ preventScroll: true });
|
|
472
|
+
}, children: _jsx(Icon, { d: ICON_X }) })) : null, showTrigger ? (_jsx("button", { type: "button", tabIndex: -1, className: "salmon-combobox-trigger", "aria-label": text.toggle, "aria-expanded": open, "aria-controls": open && popupContext ? listId : undefined, disabled: disabled, onPointerDown: preventFocusLoss, onClick: (event) => {
|
|
473
|
+
if (readOnly)
|
|
474
|
+
return;
|
|
475
|
+
inputRef.current?.focus({ preventScroll: true });
|
|
476
|
+
setOpen(!open, sourceOf(event), 'trigger');
|
|
477
|
+
}, children: _jsx(Icon, { d: ICON_CHEVRON }) })) : null] }), name !== undefined ? (_jsx(HiddenSelect, { name: name, values: !multiple && empty && creatable && typed ? [typed] : values, multiple: multiple, required: required, disabled: disabled, form: form, onReset: () => {
|
|
478
|
+
const same = initial.length === values.length && initial.every((v, i) => v === values[i]);
|
|
479
|
+
if (!same && valueProp === undefined)
|
|
480
|
+
setValues(initial, changeEvent('api', 'reset', values, () => ctl.itemsFor(initial)));
|
|
481
|
+
if (inputValueProp === undefined)
|
|
482
|
+
setText(defaultInputValue ?? null, 'api', 'reset');
|
|
483
|
+
}, onInvalid: (event) => (event.preventDefault(), inputRef.current?.focus()) })) : null, open && popupContext && popupModule ? (_jsx(popupModule.DropdownPopup, { ctl: ctl, base: "salmon-combobox", anchorRef: rootRef, context: popupContext, onOutsidePress: () => setOpen(false, 'pointer', 'outside'), onChoose: onChoose, labelledBy: labelledBy, label: label, body: body })) : null] }));
|
|
484
|
+
}
|
|
485
|
+
//# sourceMappingURL=Combobox.js.map
|