@fluentui/react-combobox 9.17.7 → 9.17.8
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/CHANGELOG.md +19 -2
- package/dist/index.d.cts +30 -0
- package/dist/index.d.ts +30 -0
- package/lib/components/Combobox/useCombobox.js +57 -35
- package/lib/components/Combobox/useCombobox.js.map +1 -1
- package/lib/components/Combobox/useComboboxExpandIconSlot.js +40 -0
- package/lib/components/Combobox/useComboboxExpandIconSlot.js.map +1 -0
- package/lib/components/Combobox/useInputTriggerSlot.js +3 -2
- package/lib/components/Combobox/useInputTriggerSlot.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/useComboboxBaseState.js +5 -4
- package/lib/utils/useComboboxBaseState.js.map +1 -1
- package/lib/utils/useTriggerSlot.js +6 -3
- package/lib/utils/useTriggerSlot.js.map +1 -1
- package/lib-commonjs/components/Combobox/useCombobox.cjs +54 -34
- package/lib-commonjs/components/Combobox/useCombobox.cjs.map +1 -1
- package/lib-commonjs/components/Combobox/useComboboxExpandIconSlot.cjs +46 -0
- package/lib-commonjs/components/Combobox/useComboboxExpandIconSlot.cjs.map +1 -0
- package/lib-commonjs/components/Combobox/useInputTriggerSlot.cjs +3 -2
- package/lib-commonjs/components/Combobox/useInputTriggerSlot.cjs.map +1 -1
- package/lib-commonjs/index.cjs +4 -0
- package/lib-commonjs/index.cjs.map +1 -1
- package/lib-commonjs/utils/useComboboxBaseState.cjs +5 -4
- package/lib-commonjs/utils/useComboboxBaseState.cjs.map +1 -1
- package/lib-commonjs/utils/useTriggerSlot.cjs +6 -3
- package/lib-commonjs/utils/useTriggerSlot.cjs.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-combobox
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on
|
|
3
|
+
<!-- This log was last generated on Mon, 19 Oct 2026 14:49:10 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.17.8](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.17.8)
|
|
8
|
+
|
|
9
|
+
Mon, 19 Oct 2026 14:49:10 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.17.7..@fluentui/react-combobox_v9.17.8)
|
|
11
|
+
|
|
12
|
+
### Patches
|
|
13
|
+
|
|
14
|
+
- fix: make the Combobox expand icon keyboard- and click-operable without duplicate pointer toggles or hidden, missing-icon, or duplicate blur interactions ([PR #36574](https://github.com/microsoft/fluentui/pull/36574) by dmytrokirpa@microsoft.com)
|
|
15
|
+
- Bump @fluentui/react-aria to v9.17.16 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
16
|
+
- Bump @fluentui/react-context-selector to v9.2.21 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
17
|
+
- Bump @fluentui/react-field to v9.5.6 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
18
|
+
- Bump @fluentui/react-jsx-runtime to v9.4.7 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
19
|
+
- Bump @fluentui/react-portal to v9.8.17 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
20
|
+
- Bump @fluentui/react-positioning to v9.23.4 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
21
|
+
- Bump @fluentui/react-tabster to v9.26.19 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
22
|
+
- Bump @fluentui/react-utilities to v9.27.0 ([commit](https://github.com/microsoft/fluentui/commit/undefined) by beachball)
|
|
23
|
+
|
|
7
24
|
## [9.17.7](https://github.com/microsoft/fluentui/tree/@fluentui/react-combobox_v9.17.7)
|
|
8
25
|
|
|
9
|
-
Wed, 23 Sep 2026 09:
|
|
26
|
+
Wed, 23 Sep 2026 09:04:33 GMT
|
|
10
27
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-combobox_v9.17.6..@fluentui/react-combobox_v9.17.7)
|
|
11
28
|
|
|
12
29
|
### Patches
|
package/dist/index.d.cts
CHANGED
|
@@ -597,6 +597,28 @@ export declare const useComboboxBaseState: (props: ComboboxBaseProps & {
|
|
|
597
597
|
|
|
598
598
|
export declare function useComboboxContextValues(state: Omit<ComboboxBaseState, 'freeform'> & Pick<ComboboxState, 'activeDescendantController'>): ComboboxBaseContextValues;
|
|
599
599
|
|
|
600
|
+
/**
|
|
601
|
+
* Creates the `expandIcon` slot of a combobox: button semantics plus the default accessible name.
|
|
602
|
+
*
|
|
603
|
+
* @internal
|
|
604
|
+
*/
|
|
605
|
+
export declare function useComboboxExpandIconSlot(expandIconFromProps: Slot<'span'> | undefined | null, options: UseComboboxExpandIconSlotOptions): SlotComponentType<ExtractSlotProps<Slot<'span'>>> | undefined;
|
|
606
|
+
|
|
607
|
+
declare type UseComboboxExpandIconSlotOptions = {
|
|
608
|
+
/** Whether the combobox trigger is disabled. */
|
|
609
|
+
disabled?: boolean;
|
|
610
|
+
/** Whether the expand icon is visually hidden by the clear icon. */
|
|
611
|
+
hideFromTabOrder?: boolean;
|
|
612
|
+
/** Whether the listbox is currently open. */
|
|
613
|
+
open: boolean;
|
|
614
|
+
/** `aria-label` passed to the combobox. */
|
|
615
|
+
'aria-label'?: string;
|
|
616
|
+
/** `aria-labelledby` passed to the combobox. */
|
|
617
|
+
'aria-labelledby'?: string;
|
|
618
|
+
/** `aria-labelledby` of the resolved input trigger, used to build the labelling chain. */
|
|
619
|
+
triggerLabelledBy?: string;
|
|
620
|
+
};
|
|
621
|
+
|
|
600
622
|
/**
|
|
601
623
|
* @internal
|
|
602
624
|
*/
|
|
@@ -666,6 +688,7 @@ declare type UseInputTriggerSlotOptions = {
|
|
|
666
688
|
freeform: boolean | undefined;
|
|
667
689
|
defaultProps?: Partial<ComboboxProps>;
|
|
668
690
|
activeDescendantController: ActiveDescendantImperativeRef;
|
|
691
|
+
shouldCloseOnBlur?: UseTriggerSlotOptions['shouldCloseOnBlur'];
|
|
669
692
|
};
|
|
670
693
|
|
|
671
694
|
/**
|
|
@@ -742,6 +765,13 @@ export declare const useOptionGroupStyles_unstable: (state: OptionGroupState) =>
|
|
|
742
765
|
*/
|
|
743
766
|
export declare const useOptionStyles_unstable: (state: OptionState) => OptionState;
|
|
744
767
|
|
|
768
|
+
declare type UseTriggerSlotOptions = {
|
|
769
|
+
state: UseTriggerSlotState;
|
|
770
|
+
defaultProps: unknown;
|
|
771
|
+
activeDescendantController: ActiveDescendantImperativeRef;
|
|
772
|
+
shouldCloseOnBlur?: (event: React_2.FocusEvent<HTMLButtonElement> & React_2.FocusEvent<HTMLInputElement>) => boolean;
|
|
773
|
+
};
|
|
774
|
+
|
|
745
775
|
declare type UseTriggerSlotState = Pick<ComboboxBaseState, 'open' | 'getOptionById' | 'selectOption' | 'setOpen' | 'multiselect' | 'setHasFocus'>;
|
|
746
776
|
|
|
747
777
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -597,6 +597,28 @@ export declare const useComboboxBaseState: (props: ComboboxBaseProps & {
|
|
|
597
597
|
|
|
598
598
|
export declare function useComboboxContextValues(state: Omit<ComboboxBaseState, 'freeform'> & Pick<ComboboxState, 'activeDescendantController'>): ComboboxBaseContextValues;
|
|
599
599
|
|
|
600
|
+
/**
|
|
601
|
+
* Creates the `expandIcon` slot of a combobox: button semantics plus the default accessible name.
|
|
602
|
+
*
|
|
603
|
+
* @internal
|
|
604
|
+
*/
|
|
605
|
+
export declare function useComboboxExpandIconSlot(expandIconFromProps: Slot<'span'> | undefined | null, options: UseComboboxExpandIconSlotOptions): SlotComponentType<ExtractSlotProps<Slot<'span'>>> | undefined;
|
|
606
|
+
|
|
607
|
+
declare type UseComboboxExpandIconSlotOptions = {
|
|
608
|
+
/** Whether the combobox trigger is disabled. */
|
|
609
|
+
disabled?: boolean;
|
|
610
|
+
/** Whether the expand icon is visually hidden by the clear icon. */
|
|
611
|
+
hideFromTabOrder?: boolean;
|
|
612
|
+
/** Whether the listbox is currently open. */
|
|
613
|
+
open: boolean;
|
|
614
|
+
/** `aria-label` passed to the combobox. */
|
|
615
|
+
'aria-label'?: string;
|
|
616
|
+
/** `aria-labelledby` passed to the combobox. */
|
|
617
|
+
'aria-labelledby'?: string;
|
|
618
|
+
/** `aria-labelledby` of the resolved input trigger, used to build the labelling chain. */
|
|
619
|
+
triggerLabelledBy?: string;
|
|
620
|
+
};
|
|
621
|
+
|
|
600
622
|
/**
|
|
601
623
|
* @internal
|
|
602
624
|
*/
|
|
@@ -666,6 +688,7 @@ declare type UseInputTriggerSlotOptions = {
|
|
|
666
688
|
freeform: boolean | undefined;
|
|
667
689
|
defaultProps?: Partial<ComboboxProps>;
|
|
668
690
|
activeDescendantController: ActiveDescendantImperativeRef;
|
|
691
|
+
shouldCloseOnBlur?: UseTriggerSlotOptions['shouldCloseOnBlur'];
|
|
669
692
|
};
|
|
670
693
|
|
|
671
694
|
/**
|
|
@@ -742,6 +765,13 @@ export declare const useOptionGroupStyles_unstable: (state: OptionGroupState) =>
|
|
|
742
765
|
*/
|
|
743
766
|
export declare const useOptionStyles_unstable: (state: OptionState) => OptionState;
|
|
744
767
|
|
|
768
|
+
declare type UseTriggerSlotOptions = {
|
|
769
|
+
state: UseTriggerSlotState;
|
|
770
|
+
defaultProps: unknown;
|
|
771
|
+
activeDescendantController: ActiveDescendantImperativeRef;
|
|
772
|
+
shouldCloseOnBlur?: (event: React_2.FocusEvent<HTMLButtonElement> & React_2.FocusEvent<HTMLInputElement>) => boolean;
|
|
773
|
+
};
|
|
774
|
+
|
|
745
775
|
declare type UseTriggerSlotState = Pick<ComboboxBaseState, 'open' | 'getOptionById' | 'selectOption' | 'setOpen' | 'multiselect' | 'setHasFocus'>;
|
|
746
776
|
|
|
747
777
|
export { }
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import { useActiveDescendant } from "@fluentui/react-aria";
|
|
4
4
|
import { useFieldContext_unstable, useFieldControlProps_unstable } from "@fluentui/react-field";
|
|
5
5
|
import { ChevronDownRegular as ChevronDownIcon, DismissRegular as DismissIcon } from "@fluentui/react-icons";
|
|
6
|
-
import { getPartitionedNativeProps, mergeCallbacks, useEventCallback,
|
|
6
|
+
import { getPartitionedNativeProps, mergeCallbacks, useEventCallback, useMergedRefs, slot, useOnClickOutside } from "@fluentui/react-utilities";
|
|
7
7
|
import { useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts";
|
|
8
8
|
import { useComboboxBaseState } from "../../utils/useComboboxBaseState.js";
|
|
9
9
|
import { useComboboxPositioning } from "../../utils/useComboboxPositioning.js";
|
|
@@ -12,13 +12,14 @@ import { useListboxSlot } from "../../utils/useListboxSlot.js";
|
|
|
12
12
|
import { useInputTriggerSlot } from "./useInputTriggerSlot.js";
|
|
13
13
|
import { isComboboxOptionElement } from "../../utils/isComboboxOptionElement.js";
|
|
14
14
|
import { useTabsterEscapeIgnore } from "../../hooks/useTabsterEscapeIgnore.js";
|
|
15
|
+
import { useComboboxExpandIconSlot } from "./useComboboxExpandIconSlot.js";
|
|
15
16
|
/**
|
|
16
17
|
* Create the base state required to render Combobox, without design-only props.
|
|
17
18
|
*
|
|
18
19
|
* @param props - props from this instance of Combobox (without appearance and size)
|
|
19
20
|
* @param ref - reference to root HTMLInputElement of Combobox
|
|
20
21
|
*/ export const useComboboxBase_unstable = (props, ref)=>{
|
|
21
|
-
var _state_clearIcon, _state_clearIcon1;
|
|
22
|
+
var _state_expandIcon, _state_expandIcon1, _state_expandIcon2, _state_clearIcon, _state_clearIcon1;
|
|
22
23
|
// Merge props from surrounding <Field>, if any
|
|
23
24
|
props = useFieldControlProps_unstable(props, {
|
|
24
25
|
supportsLabelFor: true,
|
|
@@ -36,7 +37,7 @@ import { useTabsterEscapeIgnore } from "../../hooks/useTabsterEscapeIgnore.js";
|
|
|
36
37
|
const { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } = baseState;
|
|
37
38
|
const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);
|
|
38
39
|
const { disableAutoFocus = false, freeform, inlinePopup } = props;
|
|
39
|
-
const
|
|
40
|
+
const expandIconRef = React.useRef(null);
|
|
40
41
|
const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({
|
|
41
42
|
props,
|
|
42
43
|
primarySlotTagName: 'input',
|
|
@@ -63,7 +64,8 @@ import { useTabsterEscapeIgnore } from "../../hooks/useTabsterEscapeIgnore.js";
|
|
|
63
64
|
'aria-controls': open ? listbox === null || listbox === void 0 ? void 0 : listbox.id : undefined,
|
|
64
65
|
...triggerNativeProps
|
|
65
66
|
},
|
|
66
|
-
activeDescendantController
|
|
67
|
+
activeDescendantController,
|
|
68
|
+
shouldCloseOnBlur: (event)=>!expandIconRef.current || event.relatedTarget !== expandIconRef.current
|
|
67
69
|
});
|
|
68
70
|
const rootSlot = slot.always(props.root, {
|
|
69
71
|
defaultProps: {
|
|
@@ -73,6 +75,14 @@ import { useTabsterEscapeIgnore } from "../../hooks/useTabsterEscapeIgnore.js";
|
|
|
73
75
|
elementType: 'div'
|
|
74
76
|
});
|
|
75
77
|
rootSlot.ref = useMergedRefs(rootSlot.ref, comboboxTargetRef);
|
|
78
|
+
rootSlot.onBlur = mergeCallbacks(rootSlot.onBlur, (event)=>{
|
|
79
|
+
if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {
|
|
80
|
+
if (event.target !== event.currentTarget.querySelector('input')) {
|
|
81
|
+
comboboxInternalState.setOpen(event, false);
|
|
82
|
+
}
|
|
83
|
+
comboboxInternalState.setHasFocus(false);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
76
86
|
const showClearIcon = selectedOptions.length > 0 && !disabled && clearable && !multiselect;
|
|
77
87
|
const state = {
|
|
78
88
|
components: {
|
|
@@ -92,14 +102,13 @@ import { useTabsterEscapeIgnore } from "../../hooks/useTabsterEscapeIgnore.js";
|
|
|
92
102
|
elementType: 'span',
|
|
93
103
|
renderByDefault: true
|
|
94
104
|
}),
|
|
95
|
-
expandIcon:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
elementType: 'span'
|
|
105
|
+
expandIcon: useComboboxExpandIconSlot(props.expandIcon, {
|
|
106
|
+
disabled,
|
|
107
|
+
hideFromTabOrder: showClearIcon,
|
|
108
|
+
open,
|
|
109
|
+
'aria-label': props['aria-label'],
|
|
110
|
+
'aria-labelledby': props['aria-labelledby'],
|
|
111
|
+
triggerLabelledBy: triggerSlot['aria-labelledby']
|
|
103
112
|
}),
|
|
104
113
|
showClearIcon,
|
|
105
114
|
activeDescendantController,
|
|
@@ -121,33 +130,46 @@ import { useTabsterEscapeIgnore } from "../../hooks/useTabsterEscapeIgnore.js";
|
|
|
121
130
|
mergeCallbacks(onIconMouseDown, (event)=>{
|
|
122
131
|
var _triggerRef_current;
|
|
123
132
|
event.preventDefault();
|
|
124
|
-
|
|
133
|
+
if (!state.disabled) {
|
|
134
|
+
state.setOpen(event, !state.open);
|
|
135
|
+
}
|
|
125
136
|
(_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
126
137
|
}));
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const hasExpandLabel = state.expandIcon['aria-label'] || state.expandIcon['aria-labelledby'];
|
|
136
|
-
const defaultOpenString = 'Open'; // this is english-only since it is the fallback
|
|
137
|
-
if (!hasExpandLabel) {
|
|
138
|
-
if (props['aria-labelledby']) {
|
|
139
|
-
var _state_expandIcon_id;
|
|
140
|
-
const chevronId = (_state_expandIcon_id = state.expandIcon.id) !== null && _state_expandIcon_id !== void 0 ? _state_expandIcon_id : `${comboId}-chevron`;
|
|
141
|
-
const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;
|
|
142
|
-
state.expandIcon['aria-label'] = defaultOpenString;
|
|
143
|
-
state.expandIcon.id = chevronId;
|
|
144
|
-
state.expandIcon['aria-labelledby'] = chevronLabelledBy;
|
|
145
|
-
} else if (props['aria-label']) {
|
|
146
|
-
state.expandIcon['aria-label'] = `${defaultOpenString} ${props['aria-label']}`;
|
|
147
|
-
} else {
|
|
148
|
-
state.expandIcon['aria-label'] = defaultOpenString;
|
|
138
|
+
const onExpandIconClick = useEventCallback(// eslint-disable-next-line react-hooks/refs
|
|
139
|
+
mergeCallbacks((_state_expandIcon = state.expandIcon) === null || _state_expandIcon === void 0 ? void 0 : _state_expandIcon.onClick, (event)=>{
|
|
140
|
+
// Pointer clicks already toggle on mousedown; click-only activation has detail 0.
|
|
141
|
+
if (event.detail === 0) {
|
|
142
|
+
var _triggerRef_current;
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
if (!state.disabled) {
|
|
145
|
+
state.setOpen(event, !state.open);
|
|
149
146
|
}
|
|
147
|
+
(_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
148
|
+
}
|
|
149
|
+
}));
|
|
150
|
+
const onExpandIconKeyDown = useEventCallback(// eslint-disable-next-line react-hooks/refs
|
|
151
|
+
mergeCallbacks((_state_expandIcon1 = state.expandIcon) === null || _state_expandIcon1 === void 0 ? void 0 : _state_expandIcon1.onKeyDown, (event)=>{
|
|
152
|
+
if (state.open && event.key === 'Escape') {
|
|
153
|
+
var _triggerRef_current;
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
event.stopPropagation();
|
|
156
|
+
state.setOpen(event, false);
|
|
157
|
+
(_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.focus();
|
|
158
|
+
return;
|
|
150
159
|
}
|
|
160
|
+
if (!state.disabled && (event.key === 'Enter' || event.key === ' ')) {
|
|
161
|
+
var _triggerRef_current1;
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
state.setOpen(event, !state.open);
|
|
164
|
+
(_triggerRef_current1 = triggerRef.current) === null || _triggerRef_current1 === void 0 ? void 0 : _triggerRef_current1.focus();
|
|
165
|
+
}
|
|
166
|
+
}));
|
|
167
|
+
const expandIconSlotRef = useMergedRefs((_state_expandIcon2 = state.expandIcon) === null || _state_expandIcon2 === void 0 ? void 0 : _state_expandIcon2.ref, expandIconRef);
|
|
168
|
+
if (state.expandIcon) {
|
|
169
|
+
state.expandIcon.ref = expandIconSlotRef;
|
|
170
|
+
state.expandIcon.onMouseDown = onExpandIconMouseDown;
|
|
171
|
+
state.expandIcon.onClick = onExpandIconClick;
|
|
172
|
+
state.expandIcon.onKeyDown = onExpandIconKeyDown;
|
|
151
173
|
}
|
|
152
174
|
const onClearIconMouseDown = useEventCallback(mergeCallbacks((_state_clearIcon = state.clearIcon) === null || _state_clearIcon === void 0 ? void 0 : _state_clearIcon.onMouseDown, (ev)=>{
|
|
153
175
|
ev.preventDefault();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useActiveDescendant } from '@fluentui/react-aria';\nimport { useFieldContext_unstable, useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon, DismissRegular as DismissIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n useEventCallback,\n useId,\n useMergedRefs,\n slot,\n useOnClickOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { Listbox } from '../Listbox/Listbox';\nimport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxState,\n} from './Combobox.types';\nimport { useListboxSlot } from '../../utils/useListboxSlot';\nimport { useInputTriggerSlot } from './useInputTriggerSlot';\nimport { isComboboxOptionElement } from '../../utils/isComboboxOptionElement';\nimport { useTabsterEscapeIgnore } from '../../hooks/useTabsterEscapeIgnore';\n\n/**\n * Create the base state required to render Combobox, without design-only props.\n *\n * @param props - props from this instance of Combobox (without appearance and size)\n * @param ref - reference to root HTMLInputElement of Combobox\n */\nexport const useComboboxBase_unstable = (\n props: BaseComboboxProps,\n ref: React.Ref<HTMLInputElement>,\n): BaseComboboxState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n const {\n listboxRef: activeDescendantListboxRef,\n activeParentRef,\n controller: activeDescendantController,\n } = useActiveDescendant<HTMLInputElement, HTMLDivElement>({\n matchOption: isComboboxOptionElement,\n });\n const comboboxInternalState = useComboboxBaseState({ ...props, editable: true, activeDescendantController });\n const { appearance: _appearance, size: _size, ...baseState } = comboboxInternalState;\n\n const { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } =\n baseState;\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n const { disableAutoFocus = false, freeform, inlinePopup } = props;\n const comboId = useId('combobox-');\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children'],\n });\n\n const triggerRef = React.useRef<HTMLInputElement>(null);\n\n const listbox = useListboxSlot(props.listbox, useMergedRefs(comboboxPopupRef, activeDescendantListboxRef), {\n state: comboboxInternalState,\n triggerRef,\n defaultProps: {\n children: props.children,\n disableAutoFocus,\n },\n });\n\n const triggerSlot = useInputTriggerSlot(props.input ?? {}, useMergedRefs(triggerRef, activeParentRef, ref), {\n state: comboboxInternalState,\n freeform,\n defaultProps: {\n type: 'text',\n value: value ?? '',\n 'aria-controls': open ? listbox?.id : undefined,\n ...triggerNativeProps,\n },\n activeDescendantController,\n });\n\n const rootSlot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': !inlinePopup && open ? listbox?.id : undefined,\n ...rootNativeProps,\n },\n elementType: 'div',\n });\n rootSlot.ref = useMergedRefs(rootSlot.ref, comboboxTargetRef);\n\n const showClearIcon = selectedOptions.length > 0 && !disabled && clearable && !multiselect;\n const state: BaseComboboxState = {\n components: { root: 'div', input: 'input', expandIcon: 'span', listbox: Listbox, clearIcon: 'span' },\n root: rootSlot,\n input: triggerSlot,\n listbox: open || hasFocus ? listbox : undefined,\n clearIcon: slot.optional(props.clearIcon, {\n defaultProps: {\n 'aria-hidden': 'true',\n },\n elementType: 'span',\n renderByDefault: true,\n }),\n expandIcon: slot.optional(props.expandIcon, {\n renderByDefault: true,\n defaultProps: {\n 'aria-disabled': disabled ? 'true' : undefined,\n 'aria-expanded': open,\n role: 'button',\n },\n elementType: 'span',\n }),\n showClearIcon,\n activeDescendantController,\n ...baseState,\n };\n\n const { targetDocument } = useFluent();\n\n useOnClickOutside({\n element: targetDocument,\n callback: event => setOpen(event as unknown as ComboboxOpenEvents, false),\n refs: [triggerRef, comboboxPopupRef, comboboxTargetRef],\n disabled: !open,\n });\n\n /* handle open/close + focus change when clicking expandIcon */\n const { onMouseDown: onIconMouseDown } = state.expandIcon || {};\n\n const onExpandIconMouseDown = useEventCallback(\n // eslint-disable-next-line react-hooks/refs\n mergeCallbacks(onIconMouseDown, (event: React.MouseEvent<HTMLSpanElement>) => {\n event.preventDefault();\n state.setOpen(event, !state.open);\n triggerRef.current?.focus();\n }),\n );\n\n if (state.expandIcon) {\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n\n // If there is no explicit aria-label, calculate default accName attribute for expandIcon button,\n // using the following steps:\n // 1. If there is an aria-label, it is \"Open [aria-label]\"\n // 2. If there is an aria-labelledby, it is \"Open [aria-labelledby target]\" (using aria-labelledby + ids)\n // 3. If there is no aria-label/ledby attr, it falls back to \"Open\"\n // We can't fall back to a label/htmlFor name because of https://github.com/w3c/accname/issues/179\n const hasExpandLabel = state.expandIcon['aria-label'] || state.expandIcon['aria-labelledby'];\n const defaultOpenString = 'Open'; // this is english-only since it is the fallback\n if (!hasExpandLabel) {\n if (props['aria-labelledby']) {\n const chevronId = state.expandIcon.id ?? `${comboId}-chevron`;\n const chevronLabelledBy = `${chevronId} ${state.input['aria-labelledby']}`;\n\n state.expandIcon['aria-label'] = defaultOpenString;\n state.expandIcon.id = chevronId;\n state.expandIcon['aria-labelledby'] = chevronLabelledBy;\n } else if (props['aria-label']) {\n state.expandIcon['aria-label'] = `${defaultOpenString} ${props['aria-label']}`;\n } else {\n state.expandIcon['aria-label'] = defaultOpenString;\n }\n }\n }\n\n const onClearIconMouseDown = useEventCallback(\n mergeCallbacks(state.clearIcon?.onMouseDown, (ev: React.MouseEvent<HTMLSpanElement>) => {\n ev.preventDefault();\n }),\n );\n const onClearIconClick = useEventCallback(\n mergeCallbacks(state.clearIcon?.onClick, (ev: React.MouseEvent<HTMLSpanElement>) => {\n clearSelection(ev);\n }),\n );\n\n if (state.clearIcon) {\n state.clearIcon.onMouseDown = onClearIconMouseDown;\n state.clearIcon.onClick = onClearIconClick;\n }\n\n // Heads up! We don't support \"clearable\" in multiselect mode, so we should never display a slot\n if (multiselect) {\n state.clearIcon = undefined;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- \"process.env\" does not change in runtime\n React.useEffect(() => {\n if (clearable && multiselect) {\n // eslint-disable-next-line no-console\n console.error(`[@fluentui/react-combobox] \"clearable\" prop is not supported in multiselect mode.`);\n }\n }, [clearable, multiselect]);\n }\n\n return state;\n};\n\n/**\n * Create the state required to render Combobox.\n *\n * The returned state can be modified with hooks such as useComboboxStyles_unstable,\n * before being passed to renderCombobox_unstable.\n *\n * @param props - props from this instance of Combobox\n * @param ref - reference to root HTMLElement of Combobox\n */\nexport const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLInputElement>): ComboboxState => {\n const fieldContext = useFieldContext_unstable();\n const { appearance = 'outline', size = fieldContext?.size ?? 'medium', ...baseProps } = props;\n const baseState = useComboboxBase_unstable(baseProps, ref);\n\n if (baseState.clearIcon) {\n baseState.clearIcon.children ??= <DismissIcon />;\n }\n\n if (baseState.expandIcon) {\n baseState.expandIcon.children ??= <ChevronDownIcon />;\n }\n\n return {\n ...baseState,\n appearance,\n size,\n input: {\n ...useTabsterEscapeIgnore(baseState.input, baseState.open),\n ...baseState.input,\n },\n };\n};\n"],"names":["React","useActiveDescendant","useFieldContext_unstable","useFieldControlProps_unstable","ChevronDownRegular","ChevronDownIcon","DismissRegular","DismissIcon","getPartitionedNativeProps","mergeCallbacks","useEventCallback","useId","useMergedRefs","slot","useOnClickOutside","useFluent_unstable","useFluent","useComboboxBaseState","useComboboxPositioning","Listbox","useListboxSlot","useInputTriggerSlot","isComboboxOptionElement","useTabsterEscapeIgnore","useComboboxBase_unstable","props","ref","state","supportsLabelFor","supportsRequired","listboxRef","activeDescendantListboxRef","activeParentRef","controller","activeDescendantController","matchOption","comboboxInternalState","editable","appearance","_appearance","size","_size","baseState","clearable","clearSelection","disabled","multiselect","open","selectedOptions","setOpen","value","hasFocus","comboboxPopupRef","comboboxTargetRef","disableAutoFocus","freeform","inlinePopup","comboId","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","triggerRef","useRef","listbox","defaultProps","children","triggerSlot","input","type","id","undefined","rootSlot","always","elementType","showClearIcon","length","components","expandIcon","clearIcon","optional","renderByDefault","role","targetDocument","element","callback","event","refs","onMouseDown","onIconMouseDown","onExpandIconMouseDown","preventDefault","current","focus","hasExpandLabel","defaultOpenString","chevronId","chevronLabelledBy","onClearIconMouseDown","ev","onClearIconClick","onClick","process","env","NODE_ENV","useEffect","console","error","useCombobox_unstable","fieldContext","baseProps"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,mBAAmB,QAAQ,uB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C7B;IAEA,OAAOnB;AACT,EAAE;AAEF;;;;;;;;CAQC,GACD,OAAO,MAAMmF,uBAAuB,CAACrF,OAAsBC;IACzD,MAAMqF,eAAe7G;QACkB6G;IAAvC,MAAM,EAAEzE,aAAa,SAAS,EAAEE,OAAOuE,CAAAA,qBAAAA,yBAAAA,mCAAAA,aAAcvE,IAAI,cAAlBuE,gCAAAA,qBAAsB,QAAQ,EAAE,GAAGC,WAAW,GAAGvF;IACxF,MAAMiB,YAAYlB,yBAAyBwF,WAAWtF;IAEtD,IAAIgB,UAAUuC,SAAS,EAAE;YACvBvC;;QAAAA,cAAAA,uBAAAA,UAAUuC,SAAS,EAACb,yDAApB1B,qBAAoB0B,yBAAa,oBAAC7D;IACpC;IAEA,IAAImC,UAAUsC,UAAU,EAAE;YACxBtC;;QAAAA,eAAAA,wBAAAA,UAAUsC,UAAU,EAACZ,2DAArB1B,sBAAqB0B,yBAAa,oBAAC/D;IACrC;IAEA,OAAO;QACL,GAAGqC,SAAS;QACZJ;QACAE;QACA8B,OAAO;YACL,GAAG/C,uBAAuBmB,UAAU4B,KAAK,EAAE5B,UAAUK,IAAI,CAAC;YAC1D,GAAGL,UAAU4B,KAAK;QACpB;IACF;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../src/components/Combobox/useCombobox.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useActiveDescendant } from '@fluentui/react-aria';\nimport { useFieldContext_unstable, useFieldControlProps_unstable } from '@fluentui/react-field';\nimport { ChevronDownRegular as ChevronDownIcon, DismissRegular as DismissIcon } from '@fluentui/react-icons';\nimport {\n getPartitionedNativeProps,\n mergeCallbacks,\n useEventCallback,\n useMergedRefs,\n slot,\n useOnClickOutside,\n} from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useComboboxBaseState } from '../../utils/useComboboxBaseState';\nimport { useComboboxPositioning } from '../../utils/useComboboxPositioning';\nimport { Listbox } from '../Listbox/Listbox';\nimport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxState,\n} from './Combobox.types';\nimport { useListboxSlot } from '../../utils/useListboxSlot';\nimport { useInputTriggerSlot } from './useInputTriggerSlot';\nimport { isComboboxOptionElement } from '../../utils/isComboboxOptionElement';\nimport { useTabsterEscapeIgnore } from '../../hooks/useTabsterEscapeIgnore';\nimport { useComboboxExpandIconSlot } from './useComboboxExpandIconSlot';\n\n/**\n * Create the base state required to render Combobox, without design-only props.\n *\n * @param props - props from this instance of Combobox (without appearance and size)\n * @param ref - reference to root HTMLInputElement of Combobox\n */\nexport const useComboboxBase_unstable = (\n props: BaseComboboxProps,\n ref: React.Ref<HTMLInputElement>,\n): BaseComboboxState => {\n // Merge props from surrounding <Field>, if any\n props = useFieldControlProps_unstable(props, { supportsLabelFor: true, supportsRequired: true });\n const {\n listboxRef: activeDescendantListboxRef,\n activeParentRef,\n controller: activeDescendantController,\n } = useActiveDescendant<HTMLInputElement, HTMLDivElement>({\n matchOption: isComboboxOptionElement,\n });\n const comboboxInternalState = useComboboxBaseState({ ...props, editable: true, activeDescendantController });\n const { appearance: _appearance, size: _size, ...baseState } = comboboxInternalState;\n\n const { clearable, clearSelection, disabled, multiselect, open, selectedOptions, setOpen, value, hasFocus } =\n baseState;\n const [comboboxPopupRef, comboboxTargetRef] = useComboboxPositioning(props);\n const { disableAutoFocus = false, freeform, inlinePopup } = props;\n const expandIconRef = React.useRef<HTMLSpanElement>(null);\n\n const { primary: triggerNativeProps, root: rootNativeProps } = getPartitionedNativeProps({\n props,\n primarySlotTagName: 'input',\n excludedPropNames: ['children'],\n });\n\n const triggerRef = React.useRef<HTMLInputElement>(null);\n\n const listbox = useListboxSlot(props.listbox, useMergedRefs(comboboxPopupRef, activeDescendantListboxRef), {\n state: comboboxInternalState,\n triggerRef,\n defaultProps: {\n children: props.children,\n disableAutoFocus,\n },\n });\n\n const triggerSlot = useInputTriggerSlot(props.input ?? {}, useMergedRefs(triggerRef, activeParentRef, ref), {\n state: comboboxInternalState,\n freeform,\n defaultProps: {\n type: 'text',\n value: value ?? '',\n 'aria-controls': open ? listbox?.id : undefined,\n ...triggerNativeProps,\n },\n activeDescendantController,\n shouldCloseOnBlur: event => !expandIconRef.current || event.relatedTarget !== expandIconRef.current,\n });\n\n const rootSlot = slot.always(props.root, {\n defaultProps: {\n 'aria-owns': !inlinePopup && open ? listbox?.id : undefined,\n ...rootNativeProps,\n },\n elementType: 'div',\n });\n rootSlot.ref = useMergedRefs(rootSlot.ref, comboboxTargetRef);\n rootSlot.onBlur = mergeCallbacks(rootSlot.onBlur, event => {\n if (!event.relatedTarget || !event.currentTarget.contains(event.relatedTarget)) {\n if (event.target !== event.currentTarget.querySelector('input')) {\n comboboxInternalState.setOpen(event as unknown as ComboboxOpenEvents, false);\n }\n comboboxInternalState.setHasFocus(false);\n }\n });\n\n const showClearIcon = selectedOptions.length > 0 && !disabled && clearable && !multiselect;\n const state: BaseComboboxState = {\n components: { root: 'div', input: 'input', expandIcon: 'span', listbox: Listbox, clearIcon: 'span' },\n root: rootSlot,\n input: triggerSlot,\n listbox: open || hasFocus ? listbox : undefined,\n clearIcon: slot.optional(props.clearIcon, {\n defaultProps: {\n 'aria-hidden': 'true',\n },\n elementType: 'span',\n renderByDefault: true,\n }),\n expandIcon: useComboboxExpandIconSlot(props.expandIcon, {\n disabled,\n hideFromTabOrder: showClearIcon,\n open,\n 'aria-label': props['aria-label'],\n 'aria-labelledby': props['aria-labelledby'],\n triggerLabelledBy: triggerSlot['aria-labelledby'],\n }),\n showClearIcon,\n activeDescendantController,\n ...baseState,\n };\n\n const { targetDocument } = useFluent();\n\n useOnClickOutside({\n element: targetDocument,\n callback: event => setOpen(event as unknown as ComboboxOpenEvents, false),\n refs: [triggerRef, comboboxPopupRef, comboboxTargetRef],\n disabled: !open,\n });\n\n /* handle open/close + focus change when clicking expandIcon */\n const { onMouseDown: onIconMouseDown } = state.expandIcon || {};\n\n const onExpandIconMouseDown = useEventCallback(\n // eslint-disable-next-line react-hooks/refs\n mergeCallbacks(onIconMouseDown, (event: React.MouseEvent<HTMLSpanElement>) => {\n event.preventDefault();\n if (!state.disabled) {\n state.setOpen(event, !state.open);\n }\n triggerRef.current?.focus();\n }),\n );\n\n const onExpandIconClick = useEventCallback(\n // eslint-disable-next-line react-hooks/refs\n mergeCallbacks(state.expandIcon?.onClick, (event: React.MouseEvent<HTMLSpanElement>) => {\n // Pointer clicks already toggle on mousedown; click-only activation has detail 0.\n if (event.detail === 0) {\n event.preventDefault();\n if (!state.disabled) {\n state.setOpen(event, !state.open);\n }\n triggerRef.current?.focus();\n }\n }),\n );\n\n const onExpandIconKeyDown = useEventCallback(\n // eslint-disable-next-line react-hooks/refs\n mergeCallbacks(state.expandIcon?.onKeyDown, event => {\n if (state.open && event.key === 'Escape') {\n event.preventDefault();\n event.stopPropagation();\n state.setOpen(event, false);\n triggerRef.current?.focus();\n return;\n }\n\n if (!state.disabled && (event.key === 'Enter' || event.key === ' ')) {\n event.preventDefault();\n state.setOpen(event, !state.open);\n triggerRef.current?.focus();\n }\n }),\n );\n const expandIconSlotRef = useMergedRefs(state.expandIcon?.ref, expandIconRef);\n\n if (state.expandIcon) {\n state.expandIcon.ref = expandIconSlotRef;\n state.expandIcon.onMouseDown = onExpandIconMouseDown;\n state.expandIcon.onClick = onExpandIconClick;\n state.expandIcon.onKeyDown = onExpandIconKeyDown;\n }\n\n const onClearIconMouseDown = useEventCallback(\n mergeCallbacks(state.clearIcon?.onMouseDown, (ev: React.MouseEvent<HTMLSpanElement>) => {\n ev.preventDefault();\n }),\n );\n const onClearIconClick = useEventCallback(\n mergeCallbacks(state.clearIcon?.onClick, (ev: React.MouseEvent<HTMLSpanElement>) => {\n clearSelection(ev);\n }),\n );\n\n if (state.clearIcon) {\n state.clearIcon.onMouseDown = onClearIconMouseDown;\n state.clearIcon.onClick = onClearIconClick;\n }\n\n // Heads up! We don't support \"clearable\" in multiselect mode, so we should never display a slot\n if (multiselect) {\n state.clearIcon = undefined;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- \"process.env\" does not change in runtime\n React.useEffect(() => {\n if (clearable && multiselect) {\n // eslint-disable-next-line no-console\n console.error(`[@fluentui/react-combobox] \"clearable\" prop is not supported in multiselect mode.`);\n }\n }, [clearable, multiselect]);\n }\n\n return state;\n};\n\n/**\n * Create the state required to render Combobox.\n *\n * The returned state can be modified with hooks such as useComboboxStyles_unstable,\n * before being passed to renderCombobox_unstable.\n *\n * @param props - props from this instance of Combobox\n * @param ref - reference to root HTMLElement of Combobox\n */\nexport const useCombobox_unstable = (props: ComboboxProps, ref: React.Ref<HTMLInputElement>): ComboboxState => {\n const fieldContext = useFieldContext_unstable();\n const { appearance = 'outline', size = fieldContext?.size ?? 'medium', ...baseProps } = props;\n const baseState = useComboboxBase_unstable(baseProps, ref);\n\n if (baseState.clearIcon) {\n baseState.clearIcon.children ??= <DismissIcon />;\n }\n\n if (baseState.expandIcon) {\n baseState.expandIcon.children ??= <ChevronDownIcon />;\n }\n\n return {\n ...baseState,\n appearance,\n size,\n input: {\n ...useTabsterEscapeIgnore(baseState.input, baseState.open),\n ...baseState.input,\n },\n };\n};\n"],"names":["React","useActiveDescendant","useFieldContext_unstable","useFieldControlProps_unstable","ChevronDownRegular","ChevronDownIcon","DismissRegular","DismissIcon","getPartitionedNativeProps","mergeCallbacks","useEventCallback","useMergedRefs","slot","useOnClickOutside","useFluent_unstable","useFluent","useComboboxBaseState","useComboboxPositioning","Listbox","useListboxSlot","useInputTriggerSlot","isComboboxOptionElement","useTabsterEscapeIgnore","useComboboxExpandIconSlot","useComboboxBase_unstable","props","ref","state","supportsLabelFor","supportsRequired","listboxRef","activeDescendantListboxRef","activeParentRef","controller","activeDescendantController","matchOption","comboboxInternalState","editable","appearance","_appearance","size","_size","baseState","clearable","clearSelection","disabled","multiselect","open","selectedOptions","setOpen","value","hasFocus","comboboxPopupRef","comboboxTargetRef","disableAutoFocus","freeform","inlinePopup","expandIconRef","useRef","primary","triggerNativeProps","root","rootNativeProps","primarySlotTagName","excludedPropNames","triggerRef","listbox","defaultProps","children","triggerSlot","input","type","id","undefined","shouldCloseOnBlur","event","current","relatedTarget","rootSlot","always","elementType","onBlur","currentTarget","contains","target","querySelector","setHasFocus","showClearIcon","length","components","expandIcon","clearIcon","optional","renderByDefault","hideFromTabOrder","triggerLabelledBy","targetDocument","element","callback","refs","onMouseDown","onIconMouseDown","onExpandIconMouseDown","preventDefault","focus","onExpandIconClick","onClick","detail","onExpandIconKeyDown","onKeyDown","key","stopPropagation","expandIconSlotRef","onClearIconMouseDown","ev","onClearIconClick","process","env","NODE_ENV","useEffect","console","error","useCombobox_unstable","fieldContext","baseProps"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,wBAAwB,EAAEC,6BAA6B,QAAQ,wBAAwB;AAChG,SAASC,sBAAsBC,eAAe,EAAEC,kBAAkBC,WAAW,QAAQ,wBAAwB;AAC7G,SACEC,yBAAyB,EACzBC,cAAc,EACdC,gBAAgB,EAChBC,aAAa,EACbC,IAAI,EACJC,iBAAiB,QACZ,4BAA4B;AACnC,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,oBAAoB,QAAQ,sCAAmC;AACxE,SAASC,sBAAsB,QAAQ,wCAAqC;AAC5E,SAASC,OAAO,QAAQ,wBAAqB;AAQ7C,SAASC,cAAc,QAAQ,gCAA6B;AAC5D,SAASC,mBAAmB,QAAQ,2BAAwB;AAC5D,SAASC,uBAAuB,QAAQ,yCAAsC;AAC9E,SAASC,sBAAsB,QAAQ,wCAAqC;AAC5E,SAASC,yBAAyB,QAAQ,iCAA8B;AAExE;;;;;CAKC,GACD,OAAO,MAAMC,2BAA2B,CACtCC,OACAC;QAsHiBC,mBAcAA,oBAgBuBA,oBAUvBA,kBAKAA;IAjKjB,+C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EA,gGAAgG;IAChG,IAAIrE,aAAa;QACfnB,MAAMgE,SAAS,GAAGlB;IACpB;IAEA,IAAI2C,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,kGAAkG;QAClGtH,MAAMuH,SAAS,CAAC;YACd,IAAI5E,aAAaG,aAAa;gBAC5B,sCAAsC;gBACtC0E,QAAQC,KAAK,CAAC,CAAC,iFAAiF,CAAC;YACnG;QACF,GAAG;YAAC9E;YAAWG;SAAY;IAC7B;IAEA,OAAOnB;AACT,EAAE;AAEF;;;;;;;;CAQC,GACD,OAAO,MAAM+F,uBAAuB,CAACjG,OAAsBC;IACzD,MAAMiG,eAAezH;QACkByH;IAAvC,MAAM,EAAErF,aAAa,SAAS,EAAEE,OAAOmF,CAAAA,qBAAAA,yBAAAA,mCAAAA,aAAcnF,IAAI,cAAlBmF,gCAAAA,qBAAsB,QAAQ,EAAE,GAAGC,WAAW,GAAGnG;IACxF,MAAMiB,YAAYlB,yBAAyBoG,WAAWlG;IAEtD,IAAIgB,UAAUiD,SAAS,EAAE;YACvBjD;;QAAAA,cAAAA,uBAAAA,UAAUiD,SAAS,EAACvB,yDAApB1B,qBAAoB0B,yBAAa,oBAAC7D;IACpC;IAEA,IAAImC,UAAUgD,UAAU,EAAE;YACxBhD;;QAAAA,eAAAA,wBAAAA,UAAUgD,UAAU,EAACtB,2DAArB1B,sBAAqB0B,yBAAa,oBAAC/D;IACrC;IAEA,OAAO;QACL,GAAGqC,SAAS;QACZJ;QACAE;QACA8B,OAAO;YACL,GAAGhD,uBAAuBoB,UAAU4B,KAAK,EAAE5B,UAAUK,IAAI,CAAC;YAC1D,GAAGL,UAAU4B,KAAK;QACpB;IACF;AACF,EAAE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { slot, useId } from "@fluentui/react-utilities";
|
|
2
|
+
/**
|
|
3
|
+
* Creates the `expandIcon` slot of a combobox: button semantics plus the default accessible name.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/ export function useComboboxExpandIconSlot(expandIconFromProps, options) {
|
|
7
|
+
const defaultExpandIconId = useId('combobox-chevron-');
|
|
8
|
+
const { disabled, hideFromTabOrder, open, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, triggerLabelledBy } = options;
|
|
9
|
+
const expandIcon = slot.optional(expandIconFromProps, {
|
|
10
|
+
renderByDefault: true,
|
|
11
|
+
defaultProps: {
|
|
12
|
+
'aria-disabled': disabled ? 'true' : undefined,
|
|
13
|
+
'aria-expanded': open,
|
|
14
|
+
role: 'button',
|
|
15
|
+
tabIndex: disabled ? -1 : 0
|
|
16
|
+
},
|
|
17
|
+
elementType: 'span'
|
|
18
|
+
});
|
|
19
|
+
if (!expandIcon) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (disabled || hideFromTabOrder) {
|
|
23
|
+
expandIcon.tabIndex = -1;
|
|
24
|
+
}
|
|
25
|
+
const hasExpandLabel = expandIcon['aria-label'] || expandIcon['aria-labelledby'];
|
|
26
|
+
if (!hasExpandLabel) {
|
|
27
|
+
if (triggerLabelledBy || ariaLabelledBy) {
|
|
28
|
+
var _expandIcon_id;
|
|
29
|
+
const expandIconId = (_expandIcon_id = expandIcon.id) !== null && _expandIcon_id !== void 0 ? _expandIcon_id : defaultExpandIconId;
|
|
30
|
+
expandIcon.id = expandIconId;
|
|
31
|
+
expandIcon['aria-labelledby'] = `${expandIcon.id} ${triggerLabelledBy !== null && triggerLabelledBy !== void 0 ? triggerLabelledBy : ariaLabelledBy}`.trim();
|
|
32
|
+
expandIcon['aria-label'] = 'Open';
|
|
33
|
+
} else if (ariaLabel) {
|
|
34
|
+
expandIcon['aria-label'] = `Open ${ariaLabel}`;
|
|
35
|
+
} else {
|
|
36
|
+
expandIcon['aria-label'] = 'Open';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return expandIcon;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Combobox/useComboboxExpandIconSlot.ts"],"sourcesContent":["import { slot, useId } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\n\ntype UseComboboxExpandIconSlotOptions = {\n /** Whether the combobox trigger is disabled. */\n disabled?: boolean;\n /** Whether the expand icon is visually hidden by the clear icon. */\n hideFromTabOrder?: boolean;\n /** Whether the listbox is currently open. */\n open: boolean;\n /** `aria-label` passed to the combobox. */\n 'aria-label'?: string;\n /** `aria-labelledby` passed to the combobox. */\n 'aria-labelledby'?: string;\n /** `aria-labelledby` of the resolved input trigger, used to build the labelling chain. */\n triggerLabelledBy?: string;\n};\n\n/**\n * Creates the `expandIcon` slot of a combobox: button semantics plus the default accessible name.\n *\n * @internal\n */\nexport function useComboboxExpandIconSlot(\n expandIconFromProps: Slot<'span'> | undefined | null,\n options: UseComboboxExpandIconSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'span'>>> | undefined {\n const defaultExpandIconId = useId('combobox-chevron-');\n const {\n disabled,\n hideFromTabOrder,\n open,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n triggerLabelledBy,\n } = options;\n const expandIcon = slot.optional(expandIconFromProps, {\n renderByDefault: true,\n defaultProps: {\n 'aria-disabled': disabled ? 'true' : undefined,\n 'aria-expanded': open,\n role: 'button',\n tabIndex: disabled ? -1 : 0,\n },\n elementType: 'span',\n });\n\n if (!expandIcon) {\n return undefined;\n }\n\n if (disabled || hideFromTabOrder) {\n expandIcon.tabIndex = -1;\n }\n\n const hasExpandLabel = expandIcon['aria-label'] || expandIcon['aria-labelledby'];\n\n if (!hasExpandLabel) {\n if (triggerLabelledBy || ariaLabelledBy) {\n const expandIconId = expandIcon.id ?? defaultExpandIconId;\n expandIcon.id = expandIconId;\n expandIcon['aria-labelledby'] = `${expandIcon.id} ${triggerLabelledBy ?? ariaLabelledBy}`.trim();\n expandIcon['aria-label'] = 'Open';\n } else if (ariaLabel) {\n expandIcon['aria-label'] = `Open ${ariaLabel}`;\n } else {\n expandIcon['aria-label'] = 'Open';\n }\n }\n\n return expandIcon;\n}\n"],"names":["slot","useId","useComboboxExpandIconSlot","expandIconFromProps","options","defaultExpandIconId","disabled","hideFromTabOrder","open","ariaLabel","ariaLabelledBy","triggerLabelledBy","expandIcon","optional","renderByDefault","defaultProps","undefined","role","tabIndex","elementType","hasExpandLabel","expandIconId","id","trim"],"mappings":"AAAA,SAASA,IAAI,EAAEC,KAAK,QAAQ,4BAA4B;AAkBxD;;;;CAIC,GACD,OAAO,SAASC,0BACdC,mBAAoD,EACpDC,OAAyC;IAEzC,MAAMC,sBAAsBJ,MAAM;IAClC,MAAM,EACJK,QAAQ,EACRC,gBAAgB,EAChBC,IAAI,EACJ,cAAcC,SAAS,EACvB,mBAAmBC,cAAc,EACjCC,iBAAiB,EAClB,GAAGP;IACJ,MAAMQ,aAAaZ,KAAKa,QAAQ,CAACV,qBAAqB;QACpDW,iBAAiB;QACjBC,cAAc;YACZ,iBAAiBT,WAAW,SAASU;YACrC,iBAAiBR;YACjBS,MAAM;YACNC,UAAUZ,WAAW,CAAC,IAAI;QAC5B;QACAa,aAAa;IACf;IAEA,IAAI,CAACP,YAAY;QACf,OAAOI;IACT;IAEA,IAAIV,YAAYC,kBAAkB;QAChCK,WAAWM,QAAQ,GAAG,CAAC;IACzB;IAEA,MAAME,iBAAiBR,UAAU,CAAC,aAAa,IAAIA,UAAU,CAAC,kBAAkB;IAEhF,IAAI,CAACQ,gBAAgB;QACnB,IAAIT,qBAAqBD,gBAAgB;gBAClBE;YAArB,MAAMS,eAAeT,CAAAA,iBAAAA,WAAWU,EAAE,cAAbV,4BAAAA,iBAAiBP;YACtCO,WAAWU,EAAE,GAAGD;YAChBT,UAAU,CAAC,kBAAkB,GAAG,GAAGA,WAAWU,EAAE,CAAC,CAAC,EAAEX,8BAAAA,+BAAAA,oBAAqBD,gBAAgB,CAACa,IAAI;YAC9FX,UAAU,CAAC,aAAa,GAAG;QAC7B,OAAO,IAAIH,WAAW;YACpBG,UAAU,CAAC,aAAa,GAAG,CAAC,KAAK,EAAEH,WAAW;QAChD,OAAO;YACLG,UAAU,CAAC,aAAa,GAAG;QAC7B;IACF;IAEA,OAAOA;AACT"}
|
|
@@ -11,7 +11,7 @@ import { getDropdownActionFromKey } from "../../utils/dropdownKeyActions.js";
|
|
|
11
11
|
*
|
|
12
12
|
* @internal
|
|
13
13
|
*/ export function useInputTriggerSlot(triggerFromProps, ref, options) {
|
|
14
|
-
const { state: { open, value, selectOption, setValue, multiselect, selectedOptions, clearSelection, getOptionById, setOpen }, freeform, defaultProps, activeDescendantController } = options;
|
|
14
|
+
const { state: { open, value, selectOption, setValue, multiselect, selectedOptions, clearSelection, getOptionById, setOpen }, freeform, defaultProps, activeDescendantController, shouldCloseOnBlur } = options;
|
|
15
15
|
const onBlur = (event)=>{
|
|
16
16
|
// handle selection and updating value if freeform is false
|
|
17
17
|
if (!open && !freeform) {
|
|
@@ -58,7 +58,8 @@ import { getDropdownActionFromKey } from "../../utils/dropdownKeyActions.js";
|
|
|
58
58
|
state: options.state,
|
|
59
59
|
defaultProps,
|
|
60
60
|
elementType: 'input',
|
|
61
|
-
activeDescendantController
|
|
61
|
+
activeDescendantController,
|
|
62
|
+
shouldCloseOnBlur
|
|
62
63
|
});
|
|
63
64
|
// eslint-disable-next-line react-hooks/immutability
|
|
64
65
|
trigger.onChange = mergeCallbacks(trigger.onChange, onChange);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Combobox/useInputTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport type { ComboboxProps } from '../Combobox/Combobox.types';\nimport type { UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { useTriggerSlot } from '../../utils/useTriggerSlot';\nimport type { ComboboxBaseState } from '../../utils/ComboboxBase.types';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxBaseState, 'value' | 'setValue' | 'selectedOptions' | 'clearSelection' | 'getOptionById'>;\n\ntype UseInputTriggerSlotOptions = {\n state: UsedComboboxState;\n freeform: boolean | undefined;\n defaultProps?: Partial<ComboboxProps>;\n activeDescendantController: ActiveDescendantImperativeRef;\n};\n\n/**\n * useInputTriggerSlot returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n *\n * @internal\n */\nexport function useInputTriggerSlot(\n triggerFromProps: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseInputTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n const {\n state: {\n open,\n value,\n selectOption,\n setValue,\n multiselect,\n selectedOptions,\n clearSelection,\n getOptionById,\n setOpen,\n },\n freeform,\n defaultProps,\n activeDescendantController,\n } = options;\n\n const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n // handle selection and updating value if freeform is false\n if (!open && !freeform) {\n const activeOptionId = activeDescendantController.active();\n const activeOption = activeOptionId ? getOptionById(activeOptionId) : null;\n // select matching option, if the value fully matches\n if (value && activeOption && value.trim().toLowerCase() === activeOption?.text.toLowerCase()) {\n selectOption(event, activeOption);\n }\n\n // reset typed value when the input loses focus while collapsed, unless freeform is true\n setValue(undefined);\n }\n };\n\n const getOptionFromInput = (inputValue: string): OptionValue | undefined => {\n const searchString = inputValue?.trim().toLowerCase();\n\n if (!searchString || searchString.length === 0) {\n activeDescendantController.blur();\n return;\n }\n\n const matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString) === 0;\n const match = activeDescendantController.find(id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n\n if (!match) {\n activeDescendantController.blur();\n return undefined;\n }\n\n return getOptionById(match);\n };\n\n // update value and active option based on input\n const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = event.target.value;\n // update uncontrolled value\n setValue(inputValue);\n\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\n\n // clear selection for single-select if the input value no longer matches the selection\n if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {\n clearSelection(event);\n }\n };\n\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'input',\n activeDescendantController,\n });\n\n // eslint-disable-next-line react-hooks/immutability\n trigger.onChange = mergeCallbacks(trigger.onChange, onChange);\n // eslint-disable-next-line react-hooks/immutability\n trigger.onBlur = mergeCallbacks(trigger.onBlur, onBlur);\n\n // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set\n // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows\n // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888\n const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);\n // save the typing vs. navigating options state, as the space key should behave differently in each case\n // we do not want to update the combobox when this changes, just save the value between renders\n const isTyping = React.useRef(false);\n\n /**\n * Freeform combobox should not select\n */\n const defaultOnKeyDown = trigger.onKeyDown;\n const onKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(event) === 'Type') {\n setOpen(event, true);\n }\n\n // clear activedescendant when moving the text insertion cursor\n if (event.key === ArrowLeft || event.key === ArrowRight) {\n setHideActiveDescendant(true);\n } else {\n setHideActiveDescendant(false);\n }\n\n // update typing state to true if the user is typing\n const action = getDropdownActionFromKey(event, { open, multiselect });\n if (action === 'Type') {\n isTyping.current = true;\n }\n // otherwise, update the typing state to false if opening or navigating dropdown options\n // other actions, like closing the dropdown, should not impact typing state.\n else if (\n (action === 'Open' && event.key !== ' ') ||\n action === 'Next' ||\n action === 'Previous' ||\n action === 'First' ||\n action === 'Last' ||\n action === 'PageUp' ||\n action === 'PageDown'\n ) {\n isTyping.current = false;\n }\n\n // allow space to insert a character if freeform & the last action was typing, or if the popup is closed\n if ((isTyping.current || !open) && event.key === ' ') {\n triggerFromProps?.onKeyDown?.(event);\n return;\n }\n\n defaultOnKeyDown?.(event);\n });\n\n // eslint-disable-next-line react-hooks/immutability\n trigger.onKeyDown = onKeyDown;\n\n if (hideActiveDescendant) {\n // eslint-disable-next-line react-hooks/immutability\n trigger['aria-activedescendant'] = undefined;\n }\n\n return trigger;\n}\n"],"names":["React","mergeCallbacks","useEventCallback","ArrowLeft","ArrowRight","useTriggerSlot","getDropdownActionFromKey","useInputTriggerSlot","triggerFromProps","ref","options","state","open","value","selectOption","setValue","multiselect","selectedOptions","clearSelection","getOptionById","setOpen","freeform","defaultProps","activeDescendantController","onBlur","event","activeOptionId","active","activeOption","trim","toLowerCase","text","undefined","getOptionFromInput","inputValue","searchString","length","blur","matcher","optionText","indexOf","match","find","id","option","onChange","target","matchingOption","trigger","elementType","hideActiveDescendant","setHideActiveDescendant","useState","isTyping","useRef","defaultOnKeyDown","onKeyDown","key","action","current"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,4BAA4B;AAE7E,SAASC,SAAS,EAAEC,UAAU,QAAQ,0BAA0B;AAGhE,SAASC,cAAc,QAAQ,gCAA6B;AAG5D,SAASC,wBAAwB,QAAQ,oCAAiC;AAY1E;;;;;;CAMC,GACD,OAAO,SAASC,oBACdC,gBAA4C,EAC5CC,GAAgC,EAChCC,OAAmC;IAEnC,MAAM,EACJC,OAAO,EACLC,IAAI,EACJC,KAAK,EACLC,YAAY,EACZC,QAAQ,EACRC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,aAAa,EACbC,OA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kBAA8BiB;YAC9B;QACF;QAEA8B,6BAAAA,uCAAAA,iBAAmB9B;IACrB;IAEA,oDAAoD;IACpDuB,QAAQQ,SAAS,GAAGA;IAEpB,IAAIN,sBAAsB;QACxB,oDAAoD;QACpDF,OAAO,CAAC,wBAAwB,GAAGhB;IACrC;IAEA,OAAOgB;AACT"}
|
|
1
|
+
{"version":3,"sources":["../src/components/Combobox/useInputTriggerSlot.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { ActiveDescendantImperativeRef } from '@fluentui/react-aria';\nimport { mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';\nimport type { ExtractSlotProps, Slot, SlotComponentType } from '@fluentui/react-utilities';\nimport { ArrowLeft, ArrowRight } from '@fluentui/keyboard-keys';\nimport type { ComboboxProps } from '../Combobox/Combobox.types';\nimport type { UseTriggerSlotOptions, UseTriggerSlotState } from '../../utils/useTriggerSlot';\nimport { useTriggerSlot } from '../../utils/useTriggerSlot';\nimport type { ComboboxBaseState } from '../../utils/ComboboxBase.types';\nimport type { OptionValue } from '../../utils/OptionCollection.types';\nimport { getDropdownActionFromKey } from '../../utils/dropdownKeyActions';\n\ntype UsedComboboxState = UseTriggerSlotState &\n Pick<ComboboxBaseState, 'value' | 'setValue' | 'selectedOptions' | 'clearSelection' | 'getOptionById'>;\n\ntype UseInputTriggerSlotOptions = {\n state: UsedComboboxState;\n freeform: boolean | undefined;\n defaultProps?: Partial<ComboboxProps>;\n activeDescendantController: ActiveDescendantImperativeRef;\n shouldCloseOnBlur?: UseTriggerSlotOptions['shouldCloseOnBlur'];\n};\n\n/**\n * useInputTriggerSlot returns a tuple of trigger/listbox shorthand,\n * with the semantics and event handlers needed for the Combobox and Dropdown components.\n * The element type of the ref should always match the element type used in the trigger shorthand.\n *\n * @internal\n */\nexport function useInputTriggerSlot(\n triggerFromProps: NonNullable<Slot<'input'>>,\n ref: React.Ref<HTMLInputElement>,\n options: UseInputTriggerSlotOptions,\n): SlotComponentType<ExtractSlotProps<Slot<'input'>>> {\n const {\n state: {\n open,\n value,\n selectOption,\n setValue,\n multiselect,\n selectedOptions,\n clearSelection,\n getOptionById,\n setOpen,\n },\n freeform,\n defaultProps,\n activeDescendantController,\n shouldCloseOnBlur,\n } = options;\n\n const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n // handle selection and updating value if freeform is false\n if (!open && !freeform) {\n const activeOptionId = activeDescendantController.active();\n const activeOption = activeOptionId ? getOptionById(activeOptionId) : null;\n // select matching option, if the value fully matches\n if (value && activeOption && value.trim().toLowerCase() === activeOption?.text.toLowerCase()) {\n selectOption(event, activeOption);\n }\n\n // reset typed value when the input loses focus while collapsed, unless freeform is true\n setValue(undefined);\n }\n };\n\n const getOptionFromInput = (inputValue: string): OptionValue | undefined => {\n const searchString = inputValue?.trim().toLowerCase();\n\n if (!searchString || searchString.length === 0) {\n activeDescendantController.blur();\n return;\n }\n\n const matcher = (optionText: string) => optionText.toLowerCase().indexOf(searchString) === 0;\n const match = activeDescendantController.find(id => {\n const option = getOptionById(id);\n return !!option && matcher(option.text);\n });\n\n if (!match) {\n activeDescendantController.blur();\n return undefined;\n }\n\n return getOptionById(match);\n };\n\n // update value and active option based on input\n const onChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const inputValue = event.target.value;\n // update uncontrolled value\n setValue(inputValue);\n\n // handle updating active option based on input\n const matchingOption = getOptionFromInput(inputValue);\n\n // clear selection for single-select if the input value no longer matches the selection\n if (!multiselect && selectedOptions.length === 1 && (inputValue.length < 1 || !matchingOption)) {\n clearSelection(event);\n }\n };\n\n const trigger = useTriggerSlot(triggerFromProps, ref, {\n state: options.state,\n defaultProps,\n elementType: 'input',\n activeDescendantController,\n shouldCloseOnBlur,\n });\n\n // eslint-disable-next-line react-hooks/immutability\n trigger.onChange = mergeCallbacks(trigger.onChange, onChange);\n // eslint-disable-next-line react-hooks/immutability\n trigger.onBlur = mergeCallbacks(trigger.onBlur, onBlur);\n\n // NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set\n // To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows\n // ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888\n const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);\n // save the typing vs. navigating options state, as the space key should behave differently in each case\n // we do not want to update the combobox when this changes, just save the value between renders\n const isTyping = React.useRef(false);\n\n /**\n * Freeform combobox should not select\n */\n const defaultOnKeyDown = trigger.onKeyDown;\n const onKeyDown = useEventCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!open && getDropdownActionFromKey(event) === 'Type') {\n setOpen(event, true);\n }\n\n // clear activedescendant when moving the text insertion cursor\n if (event.key === ArrowLeft || event.key === ArrowRight) {\n setHideActiveDescendant(true);\n } else {\n setHideActiveDescendant(false);\n }\n\n // update typing state to true if the user is typing\n const action = getDropdownActionFromKey(event, { open, multiselect });\n if (action === 'Type') {\n isTyping.current = true;\n }\n // otherwise, update the typing state to false if opening or navigating dropdown options\n // other actions, like closing the dropdown, should not impact typing state.\n else if (\n (action === 'Open' && event.key !== ' ') ||\n action === 'Next' ||\n action === 'Previous' ||\n action === 'First' ||\n action === 'Last' ||\n action === 'PageUp' ||\n action === 'PageDown'\n ) {\n isTyping.current = false;\n }\n\n // allow space to insert a character if freeform & the last action was typing, or if the popup is closed\n if ((isTyping.current || !open) && event.key === ' ') {\n triggerFromProps?.onKeyDown?.(event);\n return;\n }\n\n defaultOnKeyDown?.(event);\n });\n\n // eslint-disable-next-line react-hooks/immutability\n trigger.onKeyDown = onKeyDown;\n\n if (hideActiveDescendant) {\n // eslint-disable-next-line react-hooks/immutability\n trigger['aria-activedescendant'] = undefined;\n }\n\n return trigger;\n}\n"],"names":["React","mergeCallbacks","useEventCallback","ArrowLeft","ArrowRight","useTriggerSlot","getDropdownActionFromKey","useInputTriggerSlot","triggerFromProps","ref","options","state","open","value","selectOption","setValue","multiselect","selectedOptions","clearSelection","getOptionById","setOpen","freeform","defaultProps","activeDescendantController","shouldCloseOnBlur","onBlur","event","activeOptionId","active","activeOption","trim","toLowerCase","text","undefined","getOptionFromInput","inputValue","searchString","length","blur","matcher","optionText","indexOf","match","find","id","option","onChange","target","matchingOption","trigger","elementType","hideActiveDescendant","setHideActiveDescendant","useState","isTyping","useRef","defaultOnKeyDown","onKeyDown","key","action","current"],"mappings":"AAAA;AAEA,YAAYA,WAAW,QAAQ;AAE/B,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,4BAA4B;AAE7E,SAASC,SAAS,EAAEC,UAAU,QAAQ,0BAA0B;AAGhE,SAASC,cAAc,QAAQ,gCAA6B;AAG5D,SAASC,wBAAwB,QAAQ,oCAAiC;AAa1E;;;;;;CAMC,GACD,OAAO,SAASC,oBACdC,gBAA4C,EAC5CC,GAAgC,EAChCC,OAAmC;IAEnC,MAAM,EACJC,OAAO,EACLC,IAAI,EACJC,KAAK,EACLC,YAAY,EACZC,QAAQ,EACRC,WAAW,EACXC,eAAe,EACfC,cAAc,EACdC,aAAa,EACbC,OAAO,EACR,EACDC,QAAQ,EACRC,YAAY,EACZC,0BAA0B,EAC1BC,iBAAiB,EAClB,GAAGd;IAEJ,MAAMe,SAAS,CAACC;QACd,2DAA2D;QAC3D,IAAI,CAACd,QAAQ,CAACS,UAAU;YACtB,MAAMM,iBAAiBJ,2BAA2BK,MAAM;YACxD,MAAMC,eAAeF,iBAAiBR,cAAcQ,kBAAkB;YACtE,qDAAqD;YACrD,IAAId,SAASgB,gBAAgBhB,MAAMiB,IAAI,GAAGC,WAAW,QAAOF,yBAAAA,mCAAAA,aAAcG,IAAI,CAACD,WAAW,KAAI;gBAC5FjB,aAAaY,OAAOG;YACtB;YAEA,wFAAwF;YACxFd,SAASkB;QACX;IACF;IAEA,MAAMC,qBAAqB,CAACC;QAC1B,MAAMC,eAAeD,uBAAAA,iCAAAA,WAAYL,IAAI,GAAGC,WAAW;QAEnD,IAAI,CAACK,gBAAgBA,aAAaC,MAAM,KAAK,GAAG;YAC9Cd,2BAA2Be,I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ACvDN,QAAQM,OAAO;QACjB;QAEA,+DAA+D;QAC/D,IAAIA,MAAMgC,GAAG,KAAKvD,aAAauB,MAAMgC,GAAG,KAAKtD,YAAY;YACvDgD,wBAAwB;QAC1B,OAAO;YACLA,wBAAwB;QAC1B;QAEA,oDAAoD;QACpD,MAAMO,SAASrD,yBAAyBoB,OAAO;YAAEd;YAAMI;QAAY;QACnE,IAAI2C,WAAW,QAAQ;YACrBL,SAASM,OAAO,GAAG;QACrB,OAGK,IACH,AAACD,WAAW,UAAUjC,MAAMgC,GAAG,KAAK,OACpCC,WAAW,UACXA,WAAW,cACXA,WAAW,WACXA,WAAW,UACXA,WAAW,YACXA,WAAW,YACX;YACAL,SAASM,OAAO,GAAG;QACrB;QAEA,wGAAwG;QACxG,IAAI,AAACN,CAAAA,SAASM,OAAO,IAAI,CAAChD,IAAG,KAAMc,MAAMgC,GAAG,KAAK,KAAK;gBACpDlD;YAAAA,6BAAAA,wCAAAA,8BAAAA,iBAAkBiD,SAAS,cAA3BjD,kDAAAA,iCAAAA,kBAA8BkB;YAC9B;QACF;QAEA8B,6BAAAA,uCAAAA,iBAAmB9B;IACrB;IAEA,oDAAoD;IACpDuB,QAAQQ,SAAS,GAAGA;IAEpB,IAAIN,sBAAsB;QACxB,oDAAoD;QACpDF,OAAO,CAAC,wBAAwB,GAAGhB;IACrC;IAEA,OAAOgB;AACT"}
|
package/lib/index.js
CHANGED
|
@@ -13,5 +13,6 @@ export { useComboboxFilter } from "./hooks/useComboboxFilter.js";
|
|
|
13
13
|
export { useComboboxBaseState } from "./utils/useComboboxBaseState.js";
|
|
14
14
|
export { useButtonTriggerSlot } from "./components/Dropdown/useButtonTriggerSlot.js";
|
|
15
15
|
export { useInputTriggerSlot } from "./components/Combobox/useInputTriggerSlot.js";
|
|
16
|
+
export { useComboboxExpandIconSlot } from "./components/Combobox/useComboboxExpandIconSlot.js";
|
|
16
17
|
export { useListboxSlot } from "./utils/useListboxSlot.js";
|
|
17
18
|
export { isComboboxOptionElement } from "./utils/isComboboxOptionElement.js";
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport { ComboboxProvider } from './contexts/ComboboxContext';\nexport type { ComboboxContextValue } from './contexts/ComboboxContext';\nexport { ListboxProvider, useListboxContext_unstable } from './contexts/ListboxContext';\nexport type { ListboxContextValue } from './contexts/ListboxContext';\nexport { useComboboxContextValues } from './contexts/useComboboxContextValues';\nexport { useListboxContextValues } from './contexts/useListboxContextValues';\nexport {\n Listbox,\n listboxClassNames,\n renderListbox_unstable,\n useListboxStyles_unstable,\n useListbox_unstable,\n} from './Listbox';\nexport type { ListboxContextValues, ListboxProps, ListboxSlots, ListboxState } from './Listbox';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n useOptionBase_unstable,\n} from './Option';\nexport type { OptionProps, OptionSlots, OptionState } from './Option';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useComboboxBase_unstable,\n useCombobox_unstable,\n} from './Combobox';\nexport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdownBase_unstable,\n useDropdown_unstable,\n} from './Dropdown';\nexport type {\n DropdownBaseHookProps,\n DropdownBaseHookState,\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown';\nexport {\n OptionGroup,\n optionGroupClassNames,\n renderOptionGroup_unstable,\n useOptionGroupStyles_unstable,\n useOptionGroup_unstable,\n} from './OptionGroup';\nexport type { OptionGroupProps, OptionGroupSlots, OptionGroupState } from './OptionGroup';\nexport type { OptionOnSelectData, SelectionEvents } from './Selection';\n\nexport { useComboboxFilter } from './hooks/useComboboxFilter';\n\n// internals splitting the combobox logic into state hook and slot hooks\nexport { useComboboxBaseState } from './utils/useComboboxBaseState';\nexport { useButtonTriggerSlot } from './components/Dropdown/useButtonTriggerSlot';\nexport { useInputTriggerSlot } from './components/Combobox/useInputTriggerSlot';\nexport { useListboxSlot } from './utils/useListboxSlot';\nexport type { ComboboxBaseState, ComboboxBaseProps } from './utils/ComboboxBase.types';\nexport { isComboboxOptionElement } from './utils/isComboboxOptionElement';\n"],"names":["ComboboxProvider","ListboxProvider","useListboxContext_unstable","useComboboxContextValues","useListboxContextValues","Listbox","listboxClassNames","renderListbox_unstable","useListboxStyles_unstable","useListbox_unstable","Option","optionClassNames","renderOption_unstable","useOptionStyles_unstable","useOption_unstable","useOptionBase_unstable","Combobox","comboboxClassNames","renderCombobox_unstable","useComboboxStyles_unstable","useComboboxBase_unstable","useCombobox_unstable","Dropdown","dropdownClassNames","renderDropdown_unstable","useDropdownStyles_unstable","useDropdownBase_unstable","useDropdown_unstable","OptionGroup","optionGroupClassNames","renderOptionGroup_unstable","useOptionGroupStyles_unstable","useOptionGroup_unstable","useComboboxFilter","useComboboxBaseState","useButtonTriggerSlot","useInputTriggerSlot","useListboxSlot","isComboboxOptionElement"],"mappings":"AAAA,4DAA4D;AAC5D,SAASA,gBAAgB,QAAQ,gCAA6B;AAE9D,SAASC,eAAe,EAAEC,0BAA0B,QAAQ,+BAA4B;AAExF,SAASC,wBAAwB,QAAQ,yCAAsC;AAC/E,SAASC,uBAAuB,QAAQ,wCAAqC;AAC7E,SACEC,OAAO,EACPC,iBAAiB,EACjBC,sBAAsB,EACtBC,yBAAyB,EACzBC,mBAAmB,QACd,eAAY;AAEnB,SACEC,MAAM,EACNC,gBAAgB,EAChBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,EAClBC,sBAAsB,QACjB,cAAW;AAElB,SACEC,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,wBAAwB,EACxBC,oBAAoB,QACf,gBAAa;AAWpB,SACEC,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,wBAAwB,EACxBC,oBAAoB,QACf,gBAAa;AAWpB,SACEC,WAAW,EACXC,qBAAqB,EACrBC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,uBAAuB,QAClB,mBAAgB;AAIvB,SAASC,iBAAiB,QAAQ,+BAA4B;AAE9D,wEAAwE;AACxE,SAASC,oBAAoB,QAAQ,kCAA+B;AACpE,SAASC,oBAAoB,QAAQ,gDAA6C;AAClF,SAASC,mBAAmB,QAAQ,+CAA4C;AAChF,SAASC,cAAc,QAAQ,4BAAyB;AAExD,SAASC,uBAAuB,QAAQ,qCAAkC"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-deprecated\nexport { ComboboxProvider } from './contexts/ComboboxContext';\nexport type { ComboboxContextValue } from './contexts/ComboboxContext';\nexport { ListboxProvider, useListboxContext_unstable } from './contexts/ListboxContext';\nexport type { ListboxContextValue } from './contexts/ListboxContext';\nexport { useComboboxContextValues } from './contexts/useComboboxContextValues';\nexport { useListboxContextValues } from './contexts/useListboxContextValues';\nexport {\n Listbox,\n listboxClassNames,\n renderListbox_unstable,\n useListboxStyles_unstable,\n useListbox_unstable,\n} from './Listbox';\nexport type { ListboxContextValues, ListboxProps, ListboxSlots, ListboxState } from './Listbox';\nexport {\n Option,\n optionClassNames,\n renderOption_unstable,\n useOptionStyles_unstable,\n useOption_unstable,\n useOptionBase_unstable,\n} from './Option';\nexport type { OptionProps, OptionSlots, OptionState } from './Option';\nexport {\n Combobox,\n comboboxClassNames,\n renderCombobox_unstable,\n useComboboxStyles_unstable,\n useComboboxBase_unstable,\n useCombobox_unstable,\n} from './Combobox';\nexport type {\n BaseComboboxProps,\n BaseComboboxState,\n ComboboxContextValues,\n ComboboxOpenChangeData,\n ComboboxOpenEvents,\n ComboboxProps,\n ComboboxSlots,\n ComboboxState,\n} from './Combobox';\nexport {\n Dropdown,\n dropdownClassNames,\n renderDropdown_unstable,\n useDropdownStyles_unstable,\n useDropdownBase_unstable,\n useDropdown_unstable,\n} from './Dropdown';\nexport type {\n DropdownBaseHookProps,\n DropdownBaseHookState,\n DropdownContextValues,\n DropdownOpenChangeData,\n DropdownOpenEvents,\n DropdownProps,\n DropdownSlots,\n DropdownState,\n} from './Dropdown';\nexport {\n OptionGroup,\n optionGroupClassNames,\n renderOptionGroup_unstable,\n useOptionGroupStyles_unstable,\n useOptionGroup_unstable,\n} from './OptionGroup';\nexport type { OptionGroupProps, OptionGroupSlots, OptionGroupState } from './OptionGroup';\nexport type { OptionOnSelectData, SelectionEvents } from './Selection';\n\nexport { useComboboxFilter } from './hooks/useComboboxFilter';\n\n// internals splitting the combobox logic into state hook and slot hooks\nexport { useComboboxBaseState } from './utils/useComboboxBaseState';\nexport { useButtonTriggerSlot } from './components/Dropdown/useButtonTriggerSlot';\nexport { useInputTriggerSlot } from './components/Combobox/useInputTriggerSlot';\nexport { useComboboxExpandIconSlot } from './components/Combobox/useComboboxExpandIconSlot';\nexport { useListboxSlot } from './utils/useListboxSlot';\nexport type { ComboboxBaseState, ComboboxBaseProps } from './utils/ComboboxBase.types';\nexport { isComboboxOptionElement } from './utils/isComboboxOptionElement';\n"],"names":["ComboboxProvider","ListboxProvider","useListboxContext_unstable","useComboboxContextValues","useListboxContextValues","Listbox","listboxClassNames","renderListbox_unstable","useListboxStyles_unstable","useListbox_unstable","Option","optionClassNames","renderOption_unstable","useOptionStyles_unstable","useOption_unstable","useOptionBase_unstable","Combobox","comboboxClassNames","renderCombobox_unstable","useComboboxStyles_unstable","useComboboxBase_unstable","useCombobox_unstable","Dropdown","dropdownClassNames","renderDropdown_unstable","useDropdownStyles_unstable","useDropdownBase_unstable","useDropdown_unstable","OptionGroup","optionGroupClassNames","renderOptionGroup_unstable","useOptionGroupStyles_unstable","useOptionGroup_unstable","useComboboxFilter","useComboboxBaseState","useButtonTriggerSlot","useInputTriggerSlot","useComboboxExpandIconSlot","useListboxSlot","isComboboxOptionElement"],"mappings":"AAAA,4DAA4D;AAC5D,SAASA,gBAAgB,QAAQ,gCAA6B;AAE9D,SAASC,eAAe,EAAEC,0BAA0B,QAAQ,+BAA4B;AAExF,SAASC,wBAAwB,QAAQ,yCAAsC;AAC/E,SAASC,uBAAuB,QAAQ,wCAAqC;AAC7E,SACEC,OAAO,EACPC,iBAAiB,EACjBC,sBAAsB,EACtBC,yBAAyB,EACzBC,mBAAmB,QACd,eAAY;AAEnB,SACEC,MAAM,EACNC,gBAAgB,EAChBC,qBAAqB,EACrBC,wBAAwB,EACxBC,kBAAkB,EAClBC,sBAAsB,QACjB,cAAW;AAElB,SACEC,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,wBAAwB,EACxBC,oBAAoB,QACf,gBAAa;AAWpB,SACEC,QAAQ,EACRC,kBAAkB,EAClBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,wBAAwB,EACxBC,oBAAoB,QACf,gBAAa;AAWpB,SACEC,WAAW,EACXC,qBAAqB,EACrBC,0BAA0B,EAC1BC,6BAA6B,EAC7BC,uBAAuB,QAClB,mBAAgB;AAIvB,SAASC,iBAAiB,QAAQ,+BAA4B;AAE9D,wEAAwE;AACxE,SAASC,oBAAoB,QAAQ,kCAA+B;AACpE,SAASC,oBAAoB,QAAQ,gDAA6C;AAClF,SAASC,mBAAmB,QAAQ,+CAA4C;AAChF,SAASC,yBAAyB,QAAQ,qDAAkD;AAC5F,SAASC,cAAc,QAAQ,4BAAyB;AAExD,SAASC,uBAAuB,QAAQ,qCAAkC"}
|
|
@@ -98,7 +98,7 @@ import { useSelection } from "./useSelection.js";
|
|
|
98
98
|
initialState: false
|
|
99
99
|
});
|
|
100
100
|
const setOpen = React.useCallback((event, newState)=>{
|
|
101
|
-
if (disabled) {
|
|
101
|
+
if (disabled || newState === open) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
|
|
@@ -111,11 +111,12 @@ import { useSelection } from "./useSelection.js";
|
|
|
111
111
|
setOpenState(newState);
|
|
112
112
|
});
|
|
113
113
|
}, [
|
|
114
|
+
disabled,
|
|
115
|
+
freeform,
|
|
114
116
|
onOpenChange,
|
|
117
|
+
open,
|
|
115
118
|
setOpenState,
|
|
116
|
-
setValue
|
|
117
|
-
freeform,
|
|
118
|
-
disabled
|
|
119
|
+
setValue
|
|
119
120
|
]);
|
|
120
121
|
// update active option based on change in open state
|
|
121
122
|
React.useEffect(()=>{
|