@fluentui-copilot/react-prompt-listbox 0.8.1-hotfix.1 → 0.8.1-hotfix.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +4 -4
- package/CHANGELOG.md +5 -5
- package/lib/PromptListbox.js +1 -0
- package/lib/PromptOption.js +1 -0
- package/lib/components/PromptListbox/PromptListbox.js +7 -5
- package/lib/components/PromptListbox/PromptListbox.types.js +2 -1
- package/lib/components/PromptListbox/index.js +1 -0
- package/lib/components/PromptListbox/renderPromptListbox.js +21 -17
- package/lib/components/PromptListbox/usePromptListbox.js +67 -53
- package/lib/components/PromptListbox/usePromptListboxContextValues.js +30 -22
- package/lib/components/PromptListbox/usePromptListboxStyles.styles.raw.js +25 -21
- package/lib/components/PromptOption/PromptOption.js +6 -4
- package/lib/components/PromptOption/PromptOption.types.js +2 -1
- package/lib/components/PromptOption/index.js +1 -0
- package/lib/components/PromptOption/renderPromptOption.js +6 -4
- package/lib/components/PromptOption/usePromptOption.js +84 -84
- package/lib/components/PromptOption/usePromptOptionStyles.styles.raw.js +60 -54
- package/lib/components/motion/PromptListboxMotion.js +50 -52
- package/lib/components/utils/OptionCollection.types.js +2 -1
- package/lib/components/utils/PromptListboxFunctionality.types.js +2 -1
- package/lib/components/utils/Selection.types.js +2 -1
- package/lib/components/utils/dropdownKeyActions.js +60 -49
- package/lib/components/utils/useListboxPositioning.js +24 -22
- package/lib/components/utils/useOptionCollection.js +32 -30
- package/lib/components/utils/usePromptListboxFunctionality.js +123 -121
- package/lib/components/utils/usePromptListboxFunctionalityV2.js +124 -109
- package/lib/components/utils/useSelection.js +49 -57
- package/lib/components/utils/useTriggerKeyDown.js +133 -124
- package/lib/index.js +1 -0
- package/lib/plugins/CursorPositionPlugin.js +39 -39
- package/lib-commonjs/PromptListbox.js +1 -0
- package/lib-commonjs/PromptOption.js +1 -0
- package/lib-commonjs/components/PromptListbox/PromptListbox.js +1 -1
- package/lib-commonjs/components/PromptListbox/PromptListbox.js.map +1 -1
- package/lib-commonjs/components/PromptListbox/PromptListbox.types.js +1 -0
- package/lib-commonjs/components/PromptListbox/index.js +1 -0
- package/lib-commonjs/components/PromptListbox/renderPromptListbox.js +1 -1
- package/lib-commonjs/components/PromptListbox/renderPromptListbox.js.map +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListbox.js +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListbox.js.map +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListboxContextValues.js +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListboxContextValues.js.map +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.raw.js +1 -1
- package/lib-commonjs/components/PromptListbox/usePromptListboxStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/PromptOption/PromptOption.js +1 -1
- package/lib-commonjs/components/PromptOption/PromptOption.js.map +1 -1
- package/lib-commonjs/components/PromptOption/PromptOption.types.js +1 -0
- package/lib-commonjs/components/PromptOption/index.js +1 -0
- package/lib-commonjs/components/PromptOption/renderPromptOption.js +1 -1
- package/lib-commonjs/components/PromptOption/renderPromptOption.js.map +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOption.js +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOption.js.map +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.raw.js +1 -1
- package/lib-commonjs/components/PromptOption/usePromptOptionStyles.styles.raw.js.map +1 -1
- package/lib-commonjs/components/motion/PromptListboxMotion.js +1 -1
- package/lib-commonjs/components/motion/PromptListboxMotion.js.map +1 -1
- package/lib-commonjs/components/utils/OptionCollection.types.js +1 -0
- package/lib-commonjs/components/utils/PromptListboxFunctionality.types.js +1 -0
- package/lib-commonjs/components/utils/Selection.types.js +1 -0
- package/lib-commonjs/components/utils/dropdownKeyActions.js +1 -1
- package/lib-commonjs/components/utils/dropdownKeyActions.js.map +1 -1
- package/lib-commonjs/components/utils/useListboxPositioning.js +1 -1
- package/lib-commonjs/components/utils/useListboxPositioning.js.map +1 -1
- package/lib-commonjs/components/utils/useOptionCollection.js +1 -1
- package/lib-commonjs/components/utils/useOptionCollection.js.map +1 -1
- package/lib-commonjs/components/utils/usePromptListboxFunctionality.js +1 -1
- package/lib-commonjs/components/utils/usePromptListboxFunctionality.js.map +1 -1
- package/lib-commonjs/components/utils/usePromptListboxFunctionalityV2.js +1 -1
- package/lib-commonjs/components/utils/usePromptListboxFunctionalityV2.js.map +1 -1
- package/lib-commonjs/components/utils/useSelection.js +1 -1
- package/lib-commonjs/components/utils/useSelection.js.map +1 -1
- package/lib-commonjs/components/utils/useTriggerKeyDown.js +1 -1
- package/lib-commonjs/components/utils/useTriggerKeyDown.js.map +1 -1
- package/lib-commonjs/index.js +1 -0
- package/lib-commonjs/plugins/CursorPositionPlugin.js +1 -1
- package/lib-commonjs/plugins/CursorPositionPlugin.js.map +1 -1
- package/package.json +10 -10
|
@@ -11,131 +11,133 @@ import { promptOptionClassNames } from '../PromptOption';
|
|
|
11
11
|
import { PromptListboxMotion } from '../motion/PromptListboxMotion';
|
|
12
12
|
/**
|
|
13
13
|
* @deprecated -- use usePromptListboxFunctionality from usePromptListboxFunctionalityV2.tsx instead
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
*/
|
|
15
|
+
export function usePromptListboxFunctionality(params) {
|
|
16
|
+
const {
|
|
17
|
+
positioning,
|
|
18
|
+
onOpenChange,
|
|
19
|
+
onSelectionModeChange,
|
|
20
|
+
listboxProps,
|
|
21
|
+
fluid = false,
|
|
22
|
+
allowArrowUpNavigation = false
|
|
23
|
+
} = params;
|
|
24
|
+
const {
|
|
25
|
+
listboxRef: activeDescendantListboxRef,
|
|
26
|
+
activeParentRef,
|
|
27
|
+
controller: activeDescendantController
|
|
28
|
+
} = useActiveDescendant({
|
|
29
|
+
matchOption: el => el.classList.contains(promptOptionClassNames.root)
|
|
30
|
+
});
|
|
31
|
+
// useMergedRefs to normalize the ref into a React.RefObject type
|
|
32
|
+
const triggerRef = useMergedRefs(activeParentRef);
|
|
33
|
+
const selectionState = useSelection(listboxProps !== null && listboxProps !== void 0 ? listboxProps : {});
|
|
34
|
+
const {
|
|
35
|
+
selectOption
|
|
36
|
+
} = selectionState;
|
|
37
|
+
const optionCollection = useOptionCollection();
|
|
38
|
+
const {
|
|
39
|
+
getOptionById
|
|
40
|
+
} = optionCollection;
|
|
41
|
+
const [cursorPosition, setCursorPosition] = React.useState('end');
|
|
42
|
+
const [isInSelectionMode, setIsInSelectionMode] = React.useState(false);
|
|
43
|
+
const [open, setOpen] = useControllableState({
|
|
44
|
+
state: params.open,
|
|
45
|
+
defaultState: params.defaultOpen,
|
|
46
|
+
initialState: false
|
|
47
|
+
});
|
|
48
|
+
const setSelectionMode = React.useCallback(selectionMode => {
|
|
49
|
+
if (selectionMode === false) {
|
|
50
|
+
activeDescendantController.blur();
|
|
51
|
+
setHideActiveDescendant(true);
|
|
52
|
+
} else {
|
|
53
|
+
setHideActiveDescendant(false);
|
|
54
|
+
}
|
|
55
|
+
setIsInSelectionMode(selectionMode);
|
|
56
|
+
onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(selectionMode);
|
|
57
|
+
}, [activeDescendantController, onSelectionModeChange]);
|
|
58
|
+
const onBlur = event => {
|
|
59
|
+
setOpen(false);
|
|
60
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
|
|
61
|
+
event,
|
|
62
|
+
type: 'focus',
|
|
63
|
+
open: false
|
|
18
64
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const cursorPositionPlugin = /*#__PURE__*/ React.createElement(CursorPositionPlugin, {
|
|
65
|
-
setCursorPosition: setCursorPosition
|
|
66
|
-
});
|
|
67
|
-
const onListboxBlur = React.useCallback(()=>{
|
|
68
|
-
setSelectionMode(false);
|
|
69
|
-
onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(false);
|
|
70
|
-
}, [
|
|
71
|
-
onSelectionModeChange,
|
|
72
|
-
setSelectionMode
|
|
73
|
-
]);
|
|
74
|
-
// handle combobox keyboard interaction
|
|
75
|
-
const onKeyDown = useTriggerKeydown({
|
|
76
|
-
...optionCollection,
|
|
77
|
-
allowArrowUpNavigation,
|
|
78
|
-
activeDescendantController,
|
|
79
|
-
getOptionById,
|
|
80
|
-
onBlur: onListboxBlur,
|
|
81
|
-
selectOption,
|
|
82
|
-
cursorPosition,
|
|
83
|
-
open,
|
|
84
|
-
multiselect: false,
|
|
85
|
-
isInSelectionMode,
|
|
86
|
-
setSelectionMode
|
|
87
|
-
});
|
|
88
|
-
// NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set
|
|
89
|
-
// To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows
|
|
90
|
-
// ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888
|
|
91
|
-
const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);
|
|
92
|
-
React.useEffect(()=>{
|
|
93
|
-
if (hideActiveDescendant) {
|
|
94
|
-
var _triggerRef_current;
|
|
95
|
-
(_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.removeAttribute('aria-activedescendant');
|
|
96
|
-
}
|
|
65
|
+
setSelectionMode(false);
|
|
66
|
+
};
|
|
67
|
+
const onFocus = event => {
|
|
68
|
+
if (event.target === event.currentTarget) {
|
|
69
|
+
setOpen(true);
|
|
70
|
+
onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(event, {
|
|
71
|
+
event,
|
|
72
|
+
type: 'focus',
|
|
73
|
+
open: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const cursorPositionPlugin = /*#__PURE__*/React.createElement(CursorPositionPlugin, {
|
|
78
|
+
setCursorPosition: setCursorPosition
|
|
79
|
+
});
|
|
80
|
+
const onListboxBlur = React.useCallback(() => {
|
|
81
|
+
setSelectionMode(false);
|
|
82
|
+
onSelectionModeChange === null || onSelectionModeChange === void 0 ? void 0 : onSelectionModeChange(false);
|
|
83
|
+
}, [onSelectionModeChange, setSelectionMode]);
|
|
84
|
+
// handle combobox keyboard interaction
|
|
85
|
+
const onKeyDown = useTriggerKeydown({
|
|
86
|
+
...optionCollection,
|
|
87
|
+
allowArrowUpNavigation,
|
|
88
|
+
activeDescendantController,
|
|
89
|
+
getOptionById,
|
|
90
|
+
onBlur: onListboxBlur,
|
|
91
|
+
selectOption,
|
|
92
|
+
cursorPosition,
|
|
93
|
+
open,
|
|
94
|
+
multiselect: false,
|
|
95
|
+
isInSelectionMode,
|
|
96
|
+
setSelectionMode
|
|
97
|
+
});
|
|
98
|
+
// NVDA and JAWS have bugs that suppress reading the input value text when aria-activedescendant is set
|
|
99
|
+
// To prevent this, we clear the HTML attribute (but save the state) when a user presses left/right arrows
|
|
100
|
+
// ref: https://github.com/microsoft/fluentui/issues/26359#issuecomment-1397759888
|
|
101
|
+
const [hideActiveDescendant, setHideActiveDescendant] = React.useState(false);
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
if (hideActiveDescendant) {
|
|
104
|
+
var _triggerRef_current;
|
|
105
|
+
(_triggerRef_current = triggerRef.current) === null || _triggerRef_current === void 0 ? void 0 : _triggerRef_current.removeAttribute('aria-activedescendant');
|
|
106
|
+
}
|
|
97
107
|
// We only want to run this when the hideActiveDescendant changes, if the triggerRef
|
|
98
108
|
// is undefined, there's no need to remove theAttribute and we shouldn't be adding
|
|
99
109
|
// refs as dependencies since it can blow up the number of runs.
|
|
100
110
|
// eslint-disable-next-line react-compiler/react-compiler
|
|
101
111
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
ref: triggerRef,
|
|
133
|
-
onBlur,
|
|
134
|
-
onFocus,
|
|
135
|
-
onKeyDown,
|
|
136
|
-
isInSelectionMode
|
|
137
|
-
},
|
|
138
|
-
containerRef: comboboxTargetRef,
|
|
139
|
-
cursorPositionPlugin
|
|
140
|
-
};
|
|
112
|
+
}, [hideActiveDescendant]);
|
|
113
|
+
const [comboboxPopupRef, comboboxTargetRef] = useListboxPositioning({
|
|
114
|
+
positioning,
|
|
115
|
+
fluid
|
|
116
|
+
});
|
|
117
|
+
const listboxMergedRef = useMergedRefs(comboboxPopupRef, activeDescendantListboxRef, listboxProps === null || listboxProps === void 0 ? void 0 : listboxProps.ref);
|
|
118
|
+
const listbox = React.useMemo(() => {
|
|
119
|
+
return /*#__PURE__*/React.createElement(PromptListboxMotion, {
|
|
120
|
+
visible: open
|
|
121
|
+
}, /*#__PURE__*/React.createElement(PromptListbox, {
|
|
122
|
+
open: open,
|
|
123
|
+
...listboxProps,
|
|
124
|
+
...optionCollection,
|
|
125
|
+
...selectionState,
|
|
126
|
+
ref: listboxMergedRef,
|
|
127
|
+
activeDescendantController: activeDescendantController
|
|
128
|
+
}));
|
|
129
|
+
}, [activeDescendantController, listboxMergedRef, listboxProps, open, optionCollection, selectionState]);
|
|
130
|
+
return {
|
|
131
|
+
promptListbox: listbox,
|
|
132
|
+
triggerProps: {
|
|
133
|
+
ref: triggerRef,
|
|
134
|
+
onBlur,
|
|
135
|
+
onFocus,
|
|
136
|
+
onKeyDown,
|
|
137
|
+
isInSelectionMode
|
|
138
|
+
},
|
|
139
|
+
containerRef: comboboxTargetRef,
|
|
140
|
+
cursorPositionPlugin
|
|
141
|
+
};
|
|
141
142
|
}
|
|
143
|
+
//# sourceMappingURL=usePromptListboxFunctionality.js.map
|
|
@@ -6,119 +6,134 @@ import { CursorPositionPlugin } from '../../plugins/CursorPositionPlugin';
|
|
|
6
6
|
import { useListboxPositioning } from './useListboxPositioning';
|
|
7
7
|
import { Portal } from '@fluentui/react-components';
|
|
8
8
|
export function usePromptListboxFunctionality(params) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
var _params_listboxProps, _params_listboxProps1;
|
|
10
|
+
const {
|
|
11
|
+
fluid = false,
|
|
12
|
+
allowArrowUpNavigation = false,
|
|
13
|
+
onSelectionModeChange
|
|
14
|
+
} = params;
|
|
15
|
+
const [open, setOpen] = useControllableState({
|
|
16
|
+
state: params.open,
|
|
17
|
+
defaultState: params.defaultOpen,
|
|
18
|
+
initialState: false
|
|
19
|
+
});
|
|
20
|
+
const [cursorPosition, setCursorPosition] = React.useState('end');
|
|
21
|
+
const overrideActionHandler = (e, {
|
|
22
|
+
activeOption,
|
|
23
|
+
action,
|
|
24
|
+
activeDescendantController,
|
|
25
|
+
isInSelectionMode
|
|
26
|
+
}) => {
|
|
27
|
+
var _params_overrideActionHandler;
|
|
28
|
+
const atStart = allowArrowUpNavigation && (cursorPosition === 'start' || cursorPosition === 'start-end');
|
|
29
|
+
const atEnd = cursorPosition === 'end' || cursorPosition === 'start-end';
|
|
30
|
+
let newAction = undefined;
|
|
31
|
+
let newIsInSelection = undefined;
|
|
32
|
+
const firstOption = activeDescendantController.first({
|
|
33
|
+
passive: true
|
|
15
34
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let newAction = undefined;
|
|
22
|
-
let newIsInSelection = undefined;
|
|
23
|
-
const firstOption = activeDescendantController.first({
|
|
24
|
-
passive: true
|
|
25
|
-
});
|
|
26
|
-
switch(action){
|
|
27
|
-
case 'Next':
|
|
28
|
-
if (!isInSelectionMode && !atEnd) {
|
|
29
|
-
newAction = 'Type';
|
|
30
|
-
newIsInSelection = false;
|
|
31
|
-
}
|
|
32
|
-
break;
|
|
33
|
-
case 'Previous':
|
|
34
|
-
if (!isInSelectionMode && !atStart) {
|
|
35
|
-
newAction = 'Type';
|
|
36
|
-
newIsInSelection = false;
|
|
37
|
-
} else if (isInSelectionMode && !allowArrowUpNavigation && atEnd && activeOption !== undefined && activeOption.id === firstOption) {
|
|
38
|
-
newAction = 'Type';
|
|
39
|
-
newIsInSelection = false;
|
|
40
|
-
e.preventDefault();
|
|
41
|
-
}
|
|
42
|
-
break;
|
|
43
|
-
case 'First':
|
|
44
|
-
case 'Last':
|
|
45
|
-
case 'PageDown':
|
|
46
|
-
case 'PageUp':
|
|
47
|
-
if (!isInSelectionMode) {
|
|
48
|
-
newAction = 'Type';
|
|
49
|
-
newIsInSelection = false;
|
|
50
|
-
}
|
|
51
|
-
break;
|
|
35
|
+
switch (action) {
|
|
36
|
+
case 'Next':
|
|
37
|
+
if (!isInSelectionMode && !atEnd) {
|
|
38
|
+
newAction = 'Type';
|
|
39
|
+
newIsInSelection = false;
|
|
52
40
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
...userOverrides
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
const baseListboxFunctionality = useInputListboxFunctionality({
|
|
66
|
-
...params,
|
|
67
|
-
onSelectionModeChange,
|
|
68
|
-
overrideActionHandler
|
|
69
|
-
});
|
|
70
|
-
const { onBlur: baseOnBlur, onKeyDown: baseOnKeyDown, ref: triggerRef, isInSelectionMode } = baseListboxFunctionality.triggerProps;
|
|
71
|
-
const onFocus = (event)=>{
|
|
72
|
-
if (event.target === event.currentTarget) {
|
|
73
|
-
var _params_onOpenChange;
|
|
74
|
-
setOpen(true);
|
|
75
|
-
(_params_onOpenChange = params.onOpenChange) === null || _params_onOpenChange === void 0 ? void 0 : _params_onOpenChange.call(params, event, {
|
|
76
|
-
event,
|
|
77
|
-
type: 'focus',
|
|
78
|
-
open: true
|
|
79
|
-
});
|
|
41
|
+
break;
|
|
42
|
+
case 'Previous':
|
|
43
|
+
if (!isInSelectionMode && !atStart) {
|
|
44
|
+
newAction = 'Type';
|
|
45
|
+
newIsInSelection = false;
|
|
46
|
+
} else if (isInSelectionMode && !allowArrowUpNavigation && atEnd && activeOption !== undefined && activeOption.id === firstOption) {
|
|
47
|
+
newAction = 'Type';
|
|
48
|
+
newIsInSelection = false;
|
|
49
|
+
e.preventDefault();
|
|
80
50
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
setCursorPosition: setCursorPosition
|
|
98
|
-
});
|
|
99
|
-
const innerListbox = /*#__PURE__*/ React.createElement(InputListbox, {
|
|
100
|
-
...params.listboxProps,
|
|
101
|
-
...baseListboxFunctionality.inputListboxProps,
|
|
102
|
-
id: listboxId,
|
|
103
|
-
ref: useMergedRefs(baseListboxFunctionality.inputListboxProps.ref, listboxRef, (_params_listboxProps1 = params.listboxProps) === null || _params_listboxProps1 === void 0 ? void 0 : _params_listboxProps1.ref)
|
|
51
|
+
break;
|
|
52
|
+
case 'First':
|
|
53
|
+
case 'Last':
|
|
54
|
+
case 'PageDown':
|
|
55
|
+
case 'PageUp':
|
|
56
|
+
if (!isInSelectionMode) {
|
|
57
|
+
newAction = 'Type';
|
|
58
|
+
newIsInSelection = false;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
const userOverrides = (_params_overrideActionHandler = params.overrideActionHandler) === null || _params_overrideActionHandler === void 0 ? void 0 : _params_overrideActionHandler.call(params, e, {
|
|
63
|
+
activeOption,
|
|
64
|
+
action,
|
|
65
|
+
activeDescendantController,
|
|
66
|
+
isInSelectionMode
|
|
104
67
|
});
|
|
105
|
-
const listbox = /*#__PURE__*/ React.createElement(PromptListboxMotion, {
|
|
106
|
-
visible: open
|
|
107
|
-
}, /*#__PURE__*/ React.createElement("span", {
|
|
108
|
-
"aria-owns": open ? listboxId : undefined
|
|
109
|
-
}, open && (params.inline ? innerListbox : /*#__PURE__*/ React.createElement(Portal, {
|
|
110
|
-
mountNode: params.mountNode
|
|
111
|
-
}, innerListbox))));
|
|
112
68
|
return {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
ref: triggerRef,
|
|
117
|
-
isInSelectionMode,
|
|
118
|
-
onFocus,
|
|
119
|
-
onKeyDown: baseOnKeyDown,
|
|
120
|
-
onBlur
|
|
121
|
-
},
|
|
122
|
-
containerRef: anchorRef
|
|
69
|
+
action: newAction,
|
|
70
|
+
isInSelectionMode: newIsInSelection,
|
|
71
|
+
...userOverrides
|
|
123
72
|
};
|
|
73
|
+
};
|
|
74
|
+
const baseListboxFunctionality = useInputListboxFunctionality({
|
|
75
|
+
...params,
|
|
76
|
+
onSelectionModeChange,
|
|
77
|
+
overrideActionHandler
|
|
78
|
+
});
|
|
79
|
+
const {
|
|
80
|
+
onBlur: baseOnBlur,
|
|
81
|
+
onKeyDown: baseOnKeyDown,
|
|
82
|
+
ref: triggerRef,
|
|
83
|
+
isInSelectionMode
|
|
84
|
+
} = baseListboxFunctionality.triggerProps;
|
|
85
|
+
const onFocus = event => {
|
|
86
|
+
if (event.target === event.currentTarget) {
|
|
87
|
+
var _params_onOpenChange;
|
|
88
|
+
setOpen(true);
|
|
89
|
+
(_params_onOpenChange = params.onOpenChange) === null || _params_onOpenChange === void 0 ? void 0 : _params_onOpenChange.call(params, event, {
|
|
90
|
+
event,
|
|
91
|
+
type: 'focus',
|
|
92
|
+
open: true
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const onBlur = useEventCallback(mergeCallbacks(baseOnBlur, e => {
|
|
97
|
+
var _params_onOpenChange;
|
|
98
|
+
setOpen(false);
|
|
99
|
+
(_params_onOpenChange = params.onOpenChange) === null || _params_onOpenChange === void 0 ? void 0 : _params_onOpenChange.call(params, e, {
|
|
100
|
+
event: e,
|
|
101
|
+
type: 'focus',
|
|
102
|
+
open: false
|
|
103
|
+
});
|
|
104
|
+
}));
|
|
105
|
+
const [listboxRef, anchorRef] = useListboxPositioning({
|
|
106
|
+
fluid,
|
|
107
|
+
positioning: params.positioning
|
|
108
|
+
});
|
|
109
|
+
const listboxId = useId('prompt-listbox', (_params_listboxProps = params.listboxProps) === null || _params_listboxProps === void 0 ? void 0 : _params_listboxProps.id);
|
|
110
|
+
const cursorPositionPlugin = /*#__PURE__*/React.createElement(CursorPositionPlugin, {
|
|
111
|
+
setCursorPosition: setCursorPosition
|
|
112
|
+
});
|
|
113
|
+
const innerListbox = /*#__PURE__*/React.createElement(InputListbox, {
|
|
114
|
+
...params.listboxProps,
|
|
115
|
+
...baseListboxFunctionality.inputListboxProps,
|
|
116
|
+
id: listboxId,
|
|
117
|
+
ref: useMergedRefs(baseListboxFunctionality.inputListboxProps.ref, listboxRef, (_params_listboxProps1 = params.listboxProps) === null || _params_listboxProps1 === void 0 ? void 0 : _params_listboxProps1.ref)
|
|
118
|
+
});
|
|
119
|
+
const listbox = /*#__PURE__*/React.createElement(PromptListboxMotion, {
|
|
120
|
+
visible: open
|
|
121
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
122
|
+
"aria-owns": open ? listboxId : undefined
|
|
123
|
+
}, open && (params.inline ? innerListbox : /*#__PURE__*/React.createElement(Portal, {
|
|
124
|
+
mountNode: params.mountNode
|
|
125
|
+
}, innerListbox))));
|
|
126
|
+
return {
|
|
127
|
+
promptListbox: listbox,
|
|
128
|
+
cursorPositionPlugin,
|
|
129
|
+
triggerProps: {
|
|
130
|
+
ref: triggerRef,
|
|
131
|
+
isInSelectionMode,
|
|
132
|
+
onFocus,
|
|
133
|
+
onKeyDown: baseOnKeyDown,
|
|
134
|
+
onBlur
|
|
135
|
+
},
|
|
136
|
+
containerRef: anchorRef
|
|
137
|
+
};
|
|
124
138
|
}
|
|
139
|
+
//# sourceMappingURL=usePromptListboxFunctionalityV2.js.map
|
|
@@ -1,62 +1,54 @@
|
|
|
1
1
|
// Brought from Fluent UI
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
3
|
import { useControllableState } from '@fluentui/react-utilities';
|
|
4
|
-
export const useSelection =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export const useSelection = props => {
|
|
5
|
+
const {
|
|
6
|
+
defaultSelectedOptions,
|
|
7
|
+
multiselect,
|
|
8
|
+
onOptionSelect
|
|
9
|
+
} = props;
|
|
10
|
+
const [selectedOptions, setSelectedOptions] = useControllableState({
|
|
11
|
+
state: props.selectedOptions,
|
|
12
|
+
defaultState: defaultSelectedOptions,
|
|
13
|
+
initialState: []
|
|
14
|
+
});
|
|
15
|
+
const selectOption = useCallback((event, option) => {
|
|
16
|
+
// if the option is disabled, do nothing
|
|
17
|
+
if (option.disabled) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// for single-select, always return the selected option
|
|
21
|
+
let newSelection = [option.value];
|
|
22
|
+
// toggle selected state of the option for multiselect
|
|
23
|
+
if (multiselect) {
|
|
24
|
+
const selectedIndex = selectedOptions.findIndex(o => o === option.value);
|
|
25
|
+
if (selectedIndex > -1) {
|
|
26
|
+
// deselect option
|
|
27
|
+
newSelection = [...selectedOptions.slice(0, selectedIndex), ...selectedOptions.slice(selectedIndex + 1)];
|
|
28
|
+
} else {
|
|
29
|
+
// select option
|
|
30
|
+
newSelection = [...selectedOptions, option.value];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
setSelectedOptions(newSelection);
|
|
34
|
+
onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
|
|
35
|
+
optionValue: option.value,
|
|
36
|
+
optionText: option.text,
|
|
37
|
+
selectedOptions: newSelection
|
|
10
38
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
newSelection = [
|
|
26
|
-
...selectedOptions.slice(0, selectedIndex),
|
|
27
|
-
...selectedOptions.slice(selectedIndex + 1)
|
|
28
|
-
];
|
|
29
|
-
} else {
|
|
30
|
-
// select option
|
|
31
|
-
newSelection = [
|
|
32
|
-
...selectedOptions,
|
|
33
|
-
option.value
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
setSelectedOptions(newSelection);
|
|
38
|
-
onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
|
|
39
|
-
optionValue: option.value,
|
|
40
|
-
optionText: option.text,
|
|
41
|
-
selectedOptions: newSelection
|
|
42
|
-
});
|
|
43
|
-
}, [
|
|
44
|
-
onOptionSelect,
|
|
45
|
-
multiselect,
|
|
46
|
-
selectedOptions,
|
|
47
|
-
setSelectedOptions
|
|
48
|
-
]);
|
|
49
|
-
const clearSelection = (event)=>{
|
|
50
|
-
setSelectedOptions([]);
|
|
51
|
-
onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
|
|
52
|
-
optionValue: undefined,
|
|
53
|
-
optionText: undefined,
|
|
54
|
-
selectedOptions: []
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
return {
|
|
58
|
-
clearSelection,
|
|
59
|
-
selectOption,
|
|
60
|
-
selectedOptions
|
|
61
|
-
};
|
|
39
|
+
}, [onOptionSelect, multiselect, selectedOptions, setSelectedOptions]);
|
|
40
|
+
const clearSelection = event => {
|
|
41
|
+
setSelectedOptions([]);
|
|
42
|
+
onOptionSelect === null || onOptionSelect === void 0 ? void 0 : onOptionSelect(event, {
|
|
43
|
+
optionValue: undefined,
|
|
44
|
+
optionText: undefined,
|
|
45
|
+
selectedOptions: []
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return {
|
|
49
|
+
clearSelection,
|
|
50
|
+
selectOption,
|
|
51
|
+
selectedOptions
|
|
52
|
+
};
|
|
62
53
|
};
|
|
54
|
+
//# sourceMappingURL=useSelection.js.map
|