@qualtrics/ui-react 2.19.0 → 2.19.1
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 +16 -0
- package/dist/__shared/cjs/{index-4e4cc354.js → index-384184bd.js} +994 -1872
- package/dist/__shared/cjs/{index-bf07471d.js → index-4a5425cc.js} +10 -7
- package/dist/components/Accordion/Accordion.js +1 -5
- package/dist/components/Accordion/Accordion2.js +3 -3
- package/dist/components/Accordion/AccordionHeader.js +4 -8
- package/dist/components/Accordion/AccordionPanel.js +3 -3
- package/dist/components/BreakpointSwitch/Breakpoint.js +0 -2
- package/dist/components/BreakpointSwitch/BreakpointSwitch.js +0 -3
- package/dist/components/Button/Button.js +3 -3
- package/dist/components/Button/Button2.js +2 -7
- package/dist/components/ButtonGroup/ButtonGroup.js +1 -2
- package/dist/components/ButtonGroup/ButtonGroup2.js +3 -3
- package/dist/components/Checkbox/Checkbox.js +11 -11
- package/dist/components/Checkbox/Checkbox2.js +3 -3
- package/dist/components/Checkbox/VisualCheckbox.js +1 -1
- package/dist/components/Checkbox/VisualCheckbox2.js +3 -3
- package/dist/components/ColorPicker/Alpha.js +9 -30
- package/dist/components/ColorPicker/ColorPicker.js +33 -42
- package/dist/components/ColorPicker/ColorPicker2.js +3 -3
- package/dist/components/ColorPicker/ColorPickerFlyout.js +2 -1
- package/dist/components/ColorPicker/ColorPickerFlyoutInputs.js +20 -23
- package/dist/components/ColorPicker/Hue.js +2 -19
- package/dist/components/ColorPicker/Palette.js +7 -27
- package/dist/components/ColorPicker/Saturation.js +8 -29
- package/dist/components/ColorPicker/utils/calculateTargetId.js +10 -20
- package/dist/components/ColorPicker/utils/getMousePosition.js +4 -3
- package/dist/components/ColorPicker/utils/hexToHsv.js +0 -5
- package/dist/components/ColorPicker/utils/hexToRgbaString.js +2 -4
- package/dist/components/ColorPicker/utils/hsvToHex.js +0 -3
- package/dist/components/ColorPicker/utils/rgbToHex.js +1 -1
- package/dist/components/ColorPicker/utils/validateHex.js +12 -19
- package/dist/components/Combobox/Combobox.js +57 -127
- package/dist/components/Combobox/Combobox2.js +3 -3
- package/dist/components/Combobox/ComboboxHeader.js +1 -1
- package/dist/components/Combobox/ComboboxIcon.js +2 -4
- package/dist/components/Combobox/ComboboxInput.js +4 -5
- package/dist/components/Combobox/ComboboxList.js +2 -2
- package/dist/components/ConfigPane/ConfigPane.js +0 -7
- package/dist/components/ConfigPane/ConfigPane2.js +3 -3
- package/dist/components/Divider/Divider2.js +3 -3
- package/dist/components/Dropdown/ChildIndexContext/index.js +0 -1
- package/dist/components/Dropdown/ChildIndexContext/reach-descendants.js +34 -30
- package/dist/components/Dropdown/Dropdown.js +17 -68
- package/dist/components/Dropdown/Dropdown2.js +3 -3
- package/dist/components/Dropdown/DropdownButton.js +23 -33
- package/dist/components/Dropdown/DropdownHeader.js +2 -1
- package/dist/components/Dropdown/DropdownList.js +8 -7
- package/dist/components/Dropdown/DropdownOption.js +3 -10
- package/dist/components/Dropdown/DropdownSearch.js +6 -24
- package/dist/components/FilePicker/FilePicker.js +15 -26
- package/dist/components/FilePicker/FilePicker2.js +3 -3
- package/dist/components/FormField/Caption.js +3 -3
- package/dist/components/FormField/FormField.js +2 -2
- package/dist/components/FormField/FormField2.js +3 -3
- package/dist/components/FormField/FormFieldContext.js +3 -6
- package/dist/components/FormField/ReadOnlyText.js +2 -1
- package/dist/components/FullScreenTakeover/FullScreenTakeover.js +5 -11
- package/dist/components/FullScreenTakeover/FullScreenTakeover2.js +3 -3
- package/dist/components/Icon/Icon.js +3 -6
- package/dist/components/Icon/IconTypes.js +1 -0
- package/dist/components/IconButton/IconButton.js +1 -6
- package/dist/components/IconButton/IconButton2.js +3 -3
- package/dist/components/InlineInput/InlineInput.js +16 -33
- package/dist/components/InlineInput/InlineInput2.js +3 -3
- package/dist/components/Input/Input.js +3 -2
- package/dist/components/Input/Input2.js +3 -3
- package/dist/components/Input/InputField.js +2 -5
- package/dist/components/InputGroup/InputGroup2.js +3 -3
- package/dist/components/InputGroup/InputGroupProvider.js +0 -2
- package/dist/components/Label/Label2.js +3 -3
- package/dist/components/Link/Link2.js +3 -3
- package/dist/components/LoadingSpinner/LoadingSpinner.js +1 -1
- package/dist/components/LoadingSpinner/LoadingSpinner2.js +3 -3
- package/dist/components/LogicEditor/ConditionContainer.js +0 -2
- package/dist/components/LogicEditor/ConditionSet.js +8 -25
- package/dist/components/LogicEditor/Controls.js +2 -2
- package/dist/components/LogicEditor/LogicEditor.js +3 -12
- package/dist/components/LogicEditor/LogicEditor2.js +3 -3
- package/dist/components/LogicEditor/utils.js +9 -34
- package/dist/components/Modal/Modal.js +22 -35
- package/dist/components/Modal/Modal2.js +3 -3
- package/dist/components/NewMenu/BaseMenu.js +43 -108
- package/dist/components/NewMenu/NewMenu.js +3 -3
- package/dist/components/NewMenu/SelectMenu/SelectMenu.js +2 -3
- package/dist/components/NewMenu/parts/ArrowNav/ArrowNav.js +20 -32
- package/dist/components/NewMenu/parts/MenuItem.js +2 -3
- package/dist/components/NewMenu/parts/MenuSearchBox.js +2 -1
- package/dist/components/NumberStepper/NumberStepper.js +29 -44
- package/dist/components/NumberStepper/NumberStepper2.js +3 -3
- package/dist/components/NumberStepper/NumberStepperDecrement.js +6 -5
- package/dist/components/NumberStepper/NumberStepperIncrement.js +6 -5
- package/dist/components/NumberStepper/NumberStepperInput.js +10 -12
- package/dist/components/PageLayout/PageLayout.js +3 -3
- package/dist/components/Pagination/Pagination.js +10 -6
- package/dist/components/Pagination/Pagination2.js +3 -3
- package/dist/components/Pagination/PaginationNextButton.js +8 -8
- package/dist/components/Pagination/PaginationPageInput.js +17 -22
- package/dist/components/Pagination/PaginationPreviousButton.js +8 -8
- package/dist/components/Popover/Popover.js +9 -18
- package/dist/components/Popover/Popover2.js +3 -3
- package/dist/components/QuickSearch/QuickSearch.js +3 -5
- package/dist/components/QuickSearch/QuickSearch2.js +3 -3
- package/dist/components/QuickSearch/QuickSearchInput.js +6 -23
- package/dist/components/Radio/Radio.js +11 -13
- package/dist/components/Radio/Radio2.js +3 -3
- package/dist/components/SearchInput/SearchInput.js +5 -11
- package/dist/components/SearchInput/SearchInput2.js +3 -3
- package/dist/components/SidebarNav/ExpandCollapseButton.js +0 -2
- package/dist/components/SidebarNav/SidebarNav.js +5 -4
- package/dist/components/SidebarNav/SidebarNav2.js +3 -3
- package/dist/components/SidebarNav/SidebarNavLink.js +1 -4
- package/dist/components/Slider/RangeSlider.js +8 -22
- package/dist/components/Slider/Slider.js +7 -26
- package/dist/components/Slider/Slider2.js +3 -3
- package/dist/components/Slider/SliderButton.js +7 -9
- package/dist/components/Switch/Switch.js +11 -11
- package/dist/components/Switch/Switch2.js +3 -3
- package/dist/components/Table/Table2.js +3 -3
- package/dist/components/Tabs/Tab.js +3 -3
- package/dist/components/Tabs/TabContextProvider.js +1 -1
- package/dist/components/Tabs/TabList.js +9 -17
- package/dist/components/Tabs/TabPanel.js +3 -3
- package/dist/components/Tabs/TabPanels.js +0 -2
- package/dist/components/Tabs/Tabs2.js +3 -3
- package/dist/components/Tooltip/Tooltip.js +12 -41
- package/dist/components/Tooltip/Tooltip2.js +3 -3
- package/dist/components/UIProvider/PortalTargetContext.js +0 -1
- package/dist/components/UIProvider/UIProvider.js +2 -2
- package/dist/components/deprecated_ColorPicker/Alpha.js +4 -11
- package/dist/components/deprecated_ColorPicker/Color.js +9 -66
- package/dist/components/deprecated_ColorPicker/ColorPicker.js +2 -8
- package/dist/components/deprecated_ColorPicker/ColorPicker2.js +3 -3
- package/dist/components/deprecated_ColorPicker/HexInput.js +1 -7
- package/dist/components/deprecated_ColorPicker/Hue.js +3 -10
- package/dist/components/deprecated_ColorPicker/Saturation.js +7 -14
- package/dist/components/deprecated_ColorPicker/Swatch.js +2 -6
- package/dist/components/deprecated_ColorPicker/useMouseDrag.js +0 -3
- package/dist/components/deprecated_NumberStepper/NumberStepper.js +14 -20
- package/dist/components/deprecated_NumberStepper/NumberStepper2.js +3 -3
- package/dist/components/deprecated_NumberStepper/NumberStepperDecrement.js +7 -6
- package/dist/components/deprecated_NumberStepper/NumberStepperIncrement.js +7 -6
- package/dist/components/deprecated_NumberStepper/NumberStepperInput.js +16 -17
- package/dist/components/deprecated_Tabs/Tabs.js +9 -25
- package/dist/components/deprecated_Tabs/Tabs2.js +3 -3
- package/dist/components/deprecated_Toolbar/Toolbar2.js +3 -3
- package/dist/components/deprecated_Toolbar/ToolbarPanel.js +3 -3
- package/dist/components/deprecated_Toolbar/ToolbarPanels.js +3 -17
- package/dist/components/deprecated_Toolbar/ToolbarTab.js +10 -26
- package/dist/components/deprecated_Toolbar/ToolbarTabs.js +6 -18
- package/dist/hooks/useBreakpoints/useBreakpoints.js +3 -4
- package/dist/hooks/useClickOutside/useClickOutside.js +2 -7
- package/dist/hooks/useClickOutsidePortals/useClickOutsidePortals.js +3 -6
- package/dist/hooks/useControllableState/useControllableState.js +5 -10
- package/dist/hooks/useDidUpdate/useDidUpdate.js +2 -4
- package/dist/hooks/useEventCallback/useEventCallback.js +2 -1
- package/dist/hooks/useEventListener/useEventListener.js +1 -4
- package/dist/hooks/useFocusSequence/useFocusSequence.js +10 -17
- package/dist/hooks/useId/useId.js +1 -2
- package/dist/hooks/useIsFocused/useIsFocused.js +0 -1
- package/dist/hooks/useIsHovered/useIsHovered.js +0 -1
- package/dist/hooks/useIsTruncated/useIsTruncated.js +4 -3
- package/dist/hooks/useLatest/useLatest.js +0 -1
- package/dist/hooks/useMounted/useMounted.js +0 -1
- package/dist/hooks/useMouseDrag/useMouseDrag.js +0 -4
- package/dist/hooks/useOverlay/useOverlay.js +4 -10
- package/dist/hooks/useOverlay/useOverlay2.js +3 -3
- package/dist/hooks/usePrevious/usePrevious.js +0 -1
- package/dist/hooks/useResponsiveValue/useResponsiveValue.js +1 -4
- package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement.js +11 -16
- package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement2.js +3 -3
- package/dist/icons/Icon.js +3 -3
- package/dist/icons/components/HeadsetIcon.js +6 -0
- package/dist/icons/components/PauseCircleIcon.js +1 -1
- package/dist/icons/createIconComponent.js +2 -3
- package/dist/icons/index.d.ts +2 -0
- package/dist/icons/index.es.js +1 -0
- package/dist/icons/index.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +4 -3
- package/dist/index.js +6 -5
- package/dist/next/AdvancedTable/AdvancedTable.js +82 -188
- package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
- package/dist/next/AdvancedTable/AdvancedTableCell.js +4 -14
- package/dist/next/AdvancedTable/AdvancedTableCheckbox.js +0 -1
- package/dist/next/AdvancedTable/AdvancedTableColumnHeader.js +11 -41
- package/dist/next/AdvancedTable/AdvancedTableColumnHeaderMenu.js +8 -14
- package/dist/next/AdvancedTable/AdvancedTableDragPreview.js +4 -6
- package/dist/next/AdvancedTable/AdvancedTablePagination.js +1 -4
- package/dist/next/AdvancedTable/AdvancedTableRowExpandButton.js +0 -1
- package/dist/next/AdvancedTable/AdvancedTableTypes.js +1 -3
- package/dist/next/AdvancedTable/useAdvancedTableDragAndDrop.js +8 -13
- package/dist/next/AdvancedTable/useComputedWidth.js +1 -1
- package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput.js +5 -20
- package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput2.js +3 -3
- package/dist/next/CollapsibleSearchInput/CollapsibleSearchInputIconButton.js +1 -1
- package/dist/next/Combobox/Combobox2.js +3 -3
- package/dist/next/Combobox/ComboboxFlyout.js +3 -3
- package/dist/next/Combobox/ComboboxGroup.js +1 -1
- package/dist/next/Combobox/ComboboxInput.js +7 -20
- package/dist/next/Combobox/ComboboxOption.js +5 -6
- package/dist/next/Combobox/hooks/useComboboxFilteredGroup/useComboboxFilteredGroup.js +4 -5
- package/dist/next/Combobox/hooks/useComboboxFocusSequence/useComboboxFocusSequence.js +37 -54
- package/dist/next/Combobox/hooks/useComboboxLoadingState/useComboboxLoadingState.js +4 -5
- package/dist/next/Combobox/hooks/useComboboxValue/useComboboxValue.js +5 -3
- package/dist/next/Combobox/hooks/useListboxFlyoutDimensions/useListboxFlyoutDimensions.js +10 -10
- package/dist/next/Combobox/hooks/useSelectedOptionScroll/useSelectedOptionScroll.js +1 -6
- package/dist/next/Combobox/hooks/useShouldRenderGroupHeader/useShouldRenderGroupHeader.js +6 -6
- package/dist/next/Combobox/utils/nodeRegistration/nodeRegistration.js +4 -6
- package/dist/next/Drawer/Drawer.js +5 -16
- package/dist/next/Drawer/Drawer2.js +3 -3
- package/dist/next/FilterAnchor/FilterAnchor.js +7 -5
- package/dist/next/FilterAnchor/FilterAnchor2.js +3 -3
- package/dist/next/Input/Input.js +5 -8
- package/dist/next/Input/Input2.js +3 -3
- package/dist/next/Menu/Menu.js +10 -23
- package/dist/next/Menu/Menu2.js +3 -3
- package/dist/next/Menu/MenuContext.js +0 -2
- package/dist/next/Menu/MenuItem.js +11 -15
- package/dist/next/Menu/MenuPane.js +11 -25
- package/dist/next/Menu/MenuSearch.js +15 -22
- package/dist/next/Menu/SubMenu.js +10 -27
- package/dist/next/Menu/usePaneSearch.js +2 -1
- package/dist/next/PhoneNumberInput/PhoneNumberInput.js +12 -19
- package/dist/next/PhoneNumberInput/PhoneNumberInput2.js +3 -3
- package/dist/next/SplitButton/SplitButton.js +6 -12
- package/dist/next/SplitButton/SplitButton2.js +3 -3
- package/dist/next/Stack/Stack.js +0 -3
- package/dist/next/TimePicker/TimeDropdown.js +4 -5
- package/dist/next/TimePicker/TimeInput.js +4 -5
- package/dist/next/TimePicker/TimePicker.js +12 -30
- package/dist/next/TimePicker/TimePicker2.js +3 -3
- package/dist/next/TimePicker/TimePickerIcon.js +1 -3
- package/dist/next/TimePicker/utils.js +12 -52
- package/dist/next/ToggleButton/ToggleButton.js +0 -5
- package/dist/next/ToggleButton/ToggleButtonGroup.js +2 -1
- package/dist/next/ToggleButton/styles.js +3 -3
- package/dist/next/index.js +376 -748
- package/dist/utils/Flyout/Flyout.js +4 -5
- package/dist/utils/Flyout/Flyout2.js +3 -3
- package/dist/utils/Popper/Popper.js +18 -25
- package/dist/utils/Portal/Portal.js +2 -1
- package/dist/utils/TextOverflowTooltip/TextOverflowTooltip.js +4 -4
- package/dist/utils/Translation/Translate.js +0 -4
- package/dist/utils/Translation/TranslationProvider.js +0 -1
- package/dist/utils/Translation/containsComponentOrElement.js +1 -5
- package/dist/utils/Translation/insertPlaceholders.js +0 -1
- package/dist/utils/Translation/useTranslation.js +7 -14
- package/dist/utils/concatIds/concatIds.js +0 -1
- package/dist/utils/constants.js +2 -2
- package/dist/utils/createContextUtilities/createContextUtilities.js +0 -4
- package/dist/utils/filterChildren/filterChildren.js +8 -17
- package/dist/utils/getSubDataTestId/getSubDataTestId.js +1 -2
- package/dist/utils/keyboardUser/keyboardUser.js +0 -1
- package/dist/utils/mediaQueryManager/mediaQueryManager.js +1 -12
- package/dist/utils/mergeRefs/mergeRefs.js +1 -2
- package/dist/utils/wrapAround/wrapAround.js +1 -2
- package/dist/utils/wrapEvent/wrapEvent.js +2 -4
- package/icons/package.json +2 -1
- package/next/package.json +5 -1
- package/package.json +9 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import styleInject from './../../__node_modules/style-inject/dist/style-inject.es.js';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".
|
|
4
|
-
var styles = {"divider":"
|
|
5
|
-
var stylesheet=".
|
|
3
|
+
var css_248z = "._Bqwo6{border:none;height:1px;margin:0;flex-shrink:0;background-color:#e5e5e5}";
|
|
4
|
+
var styles = {"divider":"_Bqwo6"};
|
|
5
|
+
var stylesheet="._Bqwo6{border:none;height:1px;margin:0;flex-shrink:0;background-color:#e5e5e5}";
|
|
6
6
|
styleInject(css_248z);
|
|
7
7
|
|
|
8
8
|
export { styles as default, stylesheet };
|
|
@@ -3,7 +3,6 @@ import { DescendantProvider, useDescendant } from './reach-descendants.js';
|
|
|
3
3
|
|
|
4
4
|
const noop = param => {}; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
const ChildIndexContext = /*#__PURE__*/createContext({
|
|
8
7
|
descendants: [],
|
|
9
8
|
registerDescendant: noop,
|
|
@@ -4,7 +4,6 @@ import usePrevious from '../../../hooks/usePrevious/usePrevious.js';
|
|
|
4
4
|
import useSSRLayoutEffect from '../../../hooks/useSSRLayoutEffect/useSSRLayoutEffect.js';
|
|
5
5
|
|
|
6
6
|
/* eslint-disable @typescript-eslint/no-shadow */
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* This hook registers our descendant by passing it into an array. We can then
|
|
10
9
|
* search that array by to find its index when registering it in the component.
|
|
@@ -34,31 +33,32 @@ function useDescendant(descendant, context, indexProp) {
|
|
|
34
33
|
registerDescendant,
|
|
35
34
|
unregisterDescendant,
|
|
36
35
|
descendants
|
|
37
|
-
} = useContext(context);
|
|
36
|
+
} = useContext(context);
|
|
37
|
+
|
|
38
|
+
// This will initially return -1 because we haven't registered the descendant
|
|
38
39
|
// on the first render. After we register, this will then return the correct
|
|
39
40
|
// index on the following render and we will re-register descendants
|
|
40
41
|
// so that everything is up-to-date before the user interacts with a
|
|
41
42
|
// collection.
|
|
43
|
+
const index = indexProp ?? descendants.findIndex(item => item.element === descendant.element);
|
|
44
|
+
const previousDescendants = usePrevious(descendants);
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
const previousDescendants = usePrevious(descendants); // We also need to re-register descendants any time ANY of the other
|
|
46
|
+
// We also need to re-register descendants any time ANY of the other
|
|
45
47
|
// descendants have changed. My brain was melting when I wrote this and it
|
|
46
48
|
// feels a little off, but checking in render and using the result in the
|
|
47
49
|
// effect's dependency array works well enough.
|
|
50
|
+
const someDescendantsHaveChanged = descendants.some((descendant, index) => descendant.element !== previousDescendants?.[index]?.element);
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
var _previousDescendants$;
|
|
51
|
-
|
|
52
|
-
return descendant.element !== (previousDescendants === null || previousDescendants === void 0 ? void 0 : (_previousDescendants$ = previousDescendants[index]) === null || _previousDescendants$ === void 0 ? void 0 : _previousDescendants$.element);
|
|
53
|
-
}); // Prevent any flashing
|
|
54
|
-
|
|
52
|
+
// Prevent any flashing
|
|
55
53
|
useSSRLayoutEffect(() => {
|
|
56
54
|
if (!descendant.element) forceUpdate({});
|
|
57
|
-
registerDescendant({
|
|
55
|
+
registerDescendant({
|
|
56
|
+
...descendant,
|
|
58
57
|
index
|
|
59
58
|
});
|
|
60
59
|
return () => unregisterDescendant(descendant.element); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
-
}, [registerDescendant, unregisterDescendant, index, someDescendantsHaveChanged,
|
|
60
|
+
}, [registerDescendant, unregisterDescendant, index, someDescendantsHaveChanged,
|
|
61
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
62
|
...Object.values(descendant)]);
|
|
63
63
|
return index;
|
|
64
64
|
}
|
|
@@ -78,23 +78,23 @@ function DescendantProvider(_ref) {
|
|
|
78
78
|
index: explicitIndex,
|
|
79
79
|
...rest
|
|
80
80
|
} = _ref2;
|
|
81
|
-
|
|
82
81
|
if (!element) {
|
|
83
82
|
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
83
|
+
}
|
|
86
84
|
|
|
85
|
+
// eslint-disable-next-line no-shadow
|
|
87
86
|
set(items => {
|
|
88
87
|
let newItems;
|
|
89
|
-
|
|
90
88
|
if (explicitIndex != null) {
|
|
91
|
-
newItems = [...items, {
|
|
89
|
+
newItems = [...items, {
|
|
90
|
+
...rest,
|
|
92
91
|
element,
|
|
93
92
|
index: explicitIndex
|
|
94
93
|
}];
|
|
95
94
|
} else if (items.length === 0) {
|
|
96
95
|
// If there are no items, register at index 0 and bail.
|
|
97
|
-
newItems = [...items, {
|
|
96
|
+
newItems = [...items, {
|
|
97
|
+
...rest,
|
|
98
98
|
element,
|
|
99
99
|
index: 0
|
|
100
100
|
}];
|
|
@@ -117,32 +117,35 @@ function DescendantProvider(_ref) {
|
|
|
117
117
|
const index = items.findIndex(item => {
|
|
118
118
|
if (!item.element || !element) {
|
|
119
119
|
return false;
|
|
120
|
-
}
|
|
120
|
+
}
|
|
121
|
+
// Does this element's DOM node appear before another item in the
|
|
121
122
|
// array in our DOM tree? If so, return true to grab the index at
|
|
122
123
|
// this point in the array so we know where to insert the new
|
|
123
124
|
// element.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return Boolean( // eslint-disable-next-line no-bitwise
|
|
125
|
+
return Boolean(
|
|
126
|
+
// eslint-disable-next-line no-bitwise
|
|
127
127
|
item.element.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_PRECEDING);
|
|
128
128
|
});
|
|
129
|
-
const newItem = {
|
|
129
|
+
const newItem = {
|
|
130
|
+
...rest,
|
|
130
131
|
element,
|
|
131
132
|
index
|
|
132
|
-
};
|
|
133
|
+
};
|
|
133
134
|
|
|
135
|
+
// If an index is not found we will push the element to the end.
|
|
134
136
|
if (index === -1) {
|
|
135
137
|
newItems = [...items, newItem];
|
|
136
138
|
} else {
|
|
137
139
|
newItems = [...items.slice(0, index), newItem, ...items.slice(index)];
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
return newItems.map((item, index) => ({
|
|
143
|
+
...item,
|
|
142
144
|
index
|
|
143
145
|
}));
|
|
144
146
|
});
|
|
145
|
-
},
|
|
147
|
+
},
|
|
148
|
+
// set is a state setter initialized by the useDescendants hook.
|
|
146
149
|
// We can safely ignore the lint warning here because it will not change
|
|
147
150
|
// between renders.
|
|
148
151
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -150,11 +153,12 @@ function DescendantProvider(_ref) {
|
|
|
150
153
|
const unregisterDescendant = useCallback(element => {
|
|
151
154
|
if (!element) {
|
|
152
155
|
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
156
|
+
}
|
|
155
157
|
|
|
158
|
+
// eslint-disable-next-line no-shadow
|
|
156
159
|
set(items => items.filter(item => element !== item.element));
|
|
157
|
-
},
|
|
160
|
+
},
|
|
161
|
+
// set is a state setter initialized by the useDescendants hook.
|
|
158
162
|
// We can safely ignore the lint warning here because it will not change
|
|
159
163
|
// between renders.
|
|
160
164
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -13,8 +13,6 @@ import { useDidUpdate } from '../../hooks/useDidUpdate/useDidUpdate.js';
|
|
|
13
13
|
import useClickOutside from '../../hooks/useClickOutside/useClickOutside.js';
|
|
14
14
|
|
|
15
15
|
const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
16
|
-
var _ref2, _dropdownButton$props, _dropdownButton$props2, _dropdownButton$props3, _dropdownList$props$i, _dropdownList$props;
|
|
17
|
-
|
|
18
16
|
let {
|
|
19
17
|
className,
|
|
20
18
|
children,
|
|
@@ -49,24 +47,22 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
49
47
|
const [searchHeight, setSearchHeight] = useState();
|
|
50
48
|
React__default.Children.forEach(children, child => {
|
|
51
49
|
if ( /*#__PURE__*/React__default.isValidElement(child)) {
|
|
52
|
-
switch (child
|
|
50
|
+
switch (child?.type) {
|
|
53
51
|
case DropdownButton:
|
|
54
52
|
dropdownButton = child;
|
|
55
53
|
break;
|
|
56
|
-
|
|
57
54
|
case DropdownList:
|
|
58
55
|
dropdownList = child;
|
|
59
56
|
break;
|
|
60
|
-
|
|
61
57
|
default:
|
|
62
58
|
break;
|
|
63
59
|
}
|
|
64
60
|
}
|
|
65
61
|
});
|
|
66
62
|
const containerId = useId(id);
|
|
67
|
-
const buttonId =
|
|
68
|
-
const dialogId =
|
|
69
|
-
const listboxId =
|
|
63
|
+
const buttonId = dropdownButton.props.children?.props?.id ?? dropdownButton.props.id ?? `${containerId}-button`;
|
|
64
|
+
const dialogId = dropdownList.props?.id ?? `${containerId}-list`;
|
|
65
|
+
const listboxId = `${containerId}-listbox`;
|
|
70
66
|
const [isOpen, setIsOpen] = useControllableState(false, onIsOpenChange, externalIsOpen);
|
|
71
67
|
const [value, setValue] = useControllableState(defaultValue, onChange, externalValue);
|
|
72
68
|
const [isKeyboardUser, setIsKeyboardUser] = useState(false);
|
|
@@ -83,41 +79,29 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
83
79
|
setIsOpen(false);
|
|
84
80
|
setHighlightedIndex(-1);
|
|
85
81
|
}, [setIsOpen, setHighlightedIndex]);
|
|
86
|
-
|
|
87
82
|
const findOptionAndHighlight = char => {
|
|
88
83
|
const lowerCaseChar = char.toLowerCase();
|
|
89
84
|
let index = -1;
|
|
90
85
|
let currentIndex = (highlightedIndex + 1) % options.length; // start at next index
|
|
91
|
-
|
|
92
86
|
let count = 0;
|
|
93
|
-
|
|
94
87
|
while (count < options.length) {
|
|
95
|
-
var _option$label;
|
|
96
|
-
|
|
97
88
|
const option = options[currentIndex];
|
|
98
|
-
|
|
99
|
-
if ((_option$label = option.label) !== null && _option$label !== void 0 && _option$label.toLowerCase().startsWith(lowerCaseChar)) {
|
|
89
|
+
if (option.label?.toLowerCase().startsWith(lowerCaseChar)) {
|
|
100
90
|
index = currentIndex;
|
|
101
91
|
break;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
92
|
+
}
|
|
93
|
+
// increment currentIndex (wrap)
|
|
105
94
|
currentIndex = (currentIndex + 1) % options.length;
|
|
106
95
|
count += 1;
|
|
107
96
|
}
|
|
108
|
-
|
|
109
97
|
if (index !== -1) {
|
|
110
98
|
setHighlightedIndex(index);
|
|
111
99
|
}
|
|
112
100
|
};
|
|
113
|
-
|
|
114
101
|
const selectHighlightedItem = e => {
|
|
115
|
-
var _option$handleSelect;
|
|
116
|
-
|
|
117
102
|
const option = options[highlightedIndex];
|
|
118
|
-
option
|
|
103
|
+
option?.handleSelect?.(e);
|
|
119
104
|
};
|
|
120
|
-
|
|
121
105
|
useClickOutside([buttonRef, listRef], handleClose);
|
|
122
106
|
useEffect(() => {
|
|
123
107
|
const newSelectedIndex = Math.max(options.findIndex(option => option.isSelected), 0);
|
|
@@ -128,29 +112,23 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
128
112
|
setValue(prevValue => {
|
|
129
113
|
const valueArray = prevValue || prevValue === 0 ? [].concat(prevValue) : [];
|
|
130
114
|
const i = valueArray.findIndex(v => v === newValue);
|
|
131
|
-
|
|
132
115
|
if (i !== -1) {
|
|
133
116
|
valueArray.splice(i, 1);
|
|
134
117
|
} else {
|
|
135
118
|
valueArray.push(newValue);
|
|
136
119
|
}
|
|
137
|
-
|
|
138
120
|
return valueArray;
|
|
139
121
|
});
|
|
140
122
|
} else {
|
|
141
|
-
var _buttonRef$current;
|
|
142
|
-
|
|
143
123
|
setValue(newValue);
|
|
144
124
|
handleClose();
|
|
145
|
-
|
|
125
|
+
buttonRef.current?.focus();
|
|
146
126
|
}
|
|
147
127
|
}, [isMultiSelect, handleClose, setValue]);
|
|
148
|
-
|
|
149
128
|
const onKeyDownButton = e => {
|
|
150
129
|
setIsKeyboardUser(true);
|
|
151
130
|
let newHighlightedIndex;
|
|
152
131
|
if (disabled) return;
|
|
153
|
-
|
|
154
132
|
switch (e.key) {
|
|
155
133
|
case 'Enter':
|
|
156
134
|
case ' ':
|
|
@@ -158,134 +136,105 @@ const Dropdown = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
158
136
|
setIsOpen(true);
|
|
159
137
|
setHighlightedIndex(selectedIndex);
|
|
160
138
|
e.preventDefault(); // prevent scroll
|
|
161
|
-
|
|
162
139
|
break;
|
|
163
|
-
|
|
164
140
|
case 'ArrowDown':
|
|
165
141
|
// Open and focus first option. This will either be the search input, or the unfiltered first option.
|
|
166
142
|
setIsOpen(true);
|
|
167
143
|
setHighlightedIndex(0);
|
|
168
144
|
e.preventDefault(); // prevent scroll
|
|
169
|
-
|
|
170
145
|
break;
|
|
171
|
-
|
|
172
146
|
case 'ArrowUp':
|
|
173
147
|
// Open and focus last option
|
|
174
148
|
setIsOpen(true);
|
|
175
149
|
newHighlightedIndex = options.map(element => element.isVisible).lastIndexOf(true);
|
|
176
|
-
|
|
177
150
|
if (newHighlightedIndex !== -1) {
|
|
178
151
|
setHighlightedIndex(newHighlightedIndex);
|
|
179
152
|
}
|
|
180
|
-
|
|
181
153
|
e.preventDefault(); // prevent scroll
|
|
182
|
-
|
|
183
154
|
break;
|
|
184
|
-
|
|
185
155
|
case 'Escape':
|
|
186
156
|
case 'Tab':
|
|
187
157
|
// close
|
|
188
158
|
handleClose();
|
|
189
159
|
break;
|
|
190
|
-
|
|
191
160
|
default:
|
|
192
161
|
break;
|
|
193
162
|
}
|
|
194
163
|
};
|
|
195
|
-
|
|
196
164
|
const onKeyDownList = e => {
|
|
197
|
-
var _buttonRef$current2, _buttonRef$current3;
|
|
198
|
-
|
|
199
165
|
setIsKeyboardUser(true);
|
|
200
166
|
let newHighlightedIndex;
|
|
201
167
|
if (disabled) return;
|
|
202
|
-
|
|
203
168
|
switch (e.key) {
|
|
204
169
|
case 'Enter':
|
|
205
170
|
case ' ':
|
|
206
171
|
// select option
|
|
207
172
|
selectHighlightedItem(e);
|
|
208
173
|
e.preventDefault(); // prevent scroll/button click
|
|
209
|
-
|
|
210
174
|
break;
|
|
211
|
-
|
|
212
175
|
case 'ArrowDown':
|
|
213
176
|
// highlight next option
|
|
214
177
|
newHighlightedIndex = options.map(element => element.isVisible).indexOf(true, highlightedIndex + 1);
|
|
215
|
-
|
|
216
178
|
if (newHighlightedIndex !== -1) {
|
|
217
179
|
setHighlightedIndex(newHighlightedIndex);
|
|
218
180
|
}
|
|
219
|
-
|
|
220
181
|
if (newHighlightedIndex !== highlightedIndex) {
|
|
221
182
|
e.preventDefault(); // prevent scroll
|
|
222
183
|
}
|
|
223
184
|
|
|
224
185
|
break;
|
|
225
|
-
|
|
226
186
|
case 'ArrowUp':
|
|
227
187
|
// highlight previous option
|
|
228
188
|
newHighlightedIndex = options.map(element => element.isVisible).lastIndexOf(true, Math.max(highlightedIndex - 1, 0));
|
|
229
|
-
|
|
230
189
|
if (newHighlightedIndex !== -1) {
|
|
231
190
|
setHighlightedIndex(newHighlightedIndex);
|
|
232
|
-
}
|
|
233
|
-
|
|
191
|
+
}
|
|
234
192
|
|
|
193
|
+
// scrolls first-item headers into view
|
|
235
194
|
if (newHighlightedIndex === 0 && listRef.current) {
|
|
236
195
|
listRef.current.scrollTop = 0;
|
|
237
196
|
}
|
|
238
|
-
|
|
239
197
|
if (newHighlightedIndex !== highlightedIndex) {
|
|
240
198
|
e.preventDefault(); // prevent scroll
|
|
241
199
|
}
|
|
242
200
|
|
|
243
201
|
break;
|
|
244
|
-
|
|
245
202
|
case 'Escape':
|
|
246
203
|
// close, focus button, and don't let event bubble up
|
|
247
204
|
e.stopPropagation();
|
|
248
205
|
handleClose();
|
|
249
|
-
|
|
206
|
+
buttonRef.current?.focus();
|
|
250
207
|
break;
|
|
251
|
-
|
|
252
208
|
case 'Tab':
|
|
253
209
|
// close and focus next focusable element
|
|
254
210
|
handleClose();
|
|
255
|
-
|
|
211
|
+
buttonRef.current?.focus();
|
|
256
212
|
break;
|
|
257
|
-
|
|
258
213
|
case 'PageUp':
|
|
259
214
|
case 'Home':
|
|
260
215
|
// highlight first option. This will either be the search input, or the unfiltered first option.
|
|
261
|
-
setHighlightedIndex(0);
|
|
216
|
+
setHighlightedIndex(0);
|
|
262
217
|
|
|
218
|
+
// scrolls first-item headers into view
|
|
263
219
|
if (listRef.current) {
|
|
264
220
|
listRef.current.scrollTop = 0;
|
|
265
221
|
}
|
|
266
|
-
|
|
267
222
|
e.preventDefault(); // prevent scroll
|
|
268
|
-
|
|
269
223
|
break;
|
|
270
|
-
|
|
271
224
|
case 'PageDown':
|
|
272
225
|
case 'End':
|
|
273
|
-
newHighlightedIndex = options.map(element => element.isVisible).lastIndexOf(true);
|
|
274
|
-
|
|
226
|
+
newHighlightedIndex = options.map(element => element.isVisible).lastIndexOf(true);
|
|
227
|
+
// highlight last option
|
|
275
228
|
if (newHighlightedIndex !== -1) {
|
|
276
229
|
setHighlightedIndex(newHighlightedIndex);
|
|
277
230
|
}
|
|
278
|
-
|
|
279
231
|
e.preventDefault(); // prevent scroll
|
|
280
|
-
|
|
281
232
|
break;
|
|
282
|
-
|
|
283
233
|
default:
|
|
284
234
|
findOptionAndHighlight(e.key);
|
|
285
235
|
break;
|
|
286
236
|
}
|
|
287
237
|
};
|
|
288
|
-
|
|
289
238
|
return /*#__PURE__*/React__default.createElement(DropdownContextProvider, {
|
|
290
239
|
value: {
|
|
291
240
|
value,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import styleInject from './../../__node_modules/style-inject/dist/style-inject.es.js';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".
|
|
4
|
-
var styles = {"container":"
|
|
5
|
-
var stylesheet=".
|
|
3
|
+
var css_248z = "._hiv2a{max-width:100%;position:relative;display:inline-block}._5Ym5W{display:inline-flex;justify-content:space-between;align-items:center;background-color:#fafafa;border:1px solid #898989;border-radius:4px;height:36px;color:#515559;outline:none;cursor:pointer}._5Ym5W:hover:not([aria-disabled=true]){cursor:pointer;background-color:#f5f5f5}._5Ym5W:focus{box-shadow:0 0 0 2px #fff,0 0 0 4px #0a3f88;background-color:#fafafa}._5Ym5W:disabled,._5Ym5W[aria-disabled=true]{color:#74777a;border-color:#e5e5e5;cursor:not-allowed}._5Ym5W._QVcbH{border-color:#b00}._5Ym5W._QVcbH:focus{box-shadow:0 0 0 2px #fff,0 0 0 4px #900000}._5Ym5W._vSoKd{min-width:120px;padding:0 4px 0 12px}._5Ym5W._csAvZ{margin-top:4px}._5Ym5W._zk3mq:not([aria-disabled=true]):not(:disabled){color:#32363a}._5Ym5W ._5mwEh{display:inline-flex;align-items:center;min-height:10px}._5Ym5W ._5mwEh._Oc-MT{line-height:20px;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}._5Ym5W ._Z0RPQ{height:24px;width:24px;border-radius:4px;fill:#515559;flex-shrink:0;cursor:pointer}._5Ym5W ._Z0RPQ._TEWRH{border-color:#e5e5e5;fill:#9d9fa1;opacity:.4;cursor:not-allowed}._5Ym5W ._Z0RPQ._rjvAN{transform:rotate(-180deg)}._5lMF-[aria-disabled=true]{cursor:not-allowed;color:rgba(81,85,89,.65);fill:#9d9fa1}._2YXi1{position:sticky;top:0;z-index:20;padding:4px 8px 8px!important;border-bottom:1px solid #e8e8e8;border-radius:4px 4px 0 0;background-color:#fff!important}._CTuRo{min-height:40px;padding:10px 12px;display:flex;flex-direction:row;align-items:center;background-color:#fff;font-size:14px;color:#32363a;word-break:break-word}._XzebP{fill:#515559}._tYCdy{margin:2px 12px 2px 0}._tYCdy._LxnoL>svg{border-color:#0b6ed0}._s3Uv4{width:100%}";
|
|
4
|
+
var styles = {"container":"_hiv2a","button":"_5Ym5W","invalid":"_QVcbH","hasText":"_vSoKd","labelled":"_csAvZ","selected":"_zk3mq","buttonLabel":"_5mwEh","isString":"_Oc-MT","icon":"_Z0RPQ","disabled":"_TEWRH","open":"_rjvAN","option":"_5lMF-","search":"_2YXi1","emptyOption":"_CTuRo","searchIcon":"_XzebP","checkbox":"_tYCdy","highlighted":"_LxnoL","searchInput":"_s3Uv4"};
|
|
5
|
+
var stylesheet="._hiv2a{max-width:100%;position:relative;display:inline-block}._5Ym5W{display:inline-flex;justify-content:space-between;align-items:center;background-color:#fafafa;border:1px solid #898989;border-radius:4px;height:36px;color:#515559;outline:none;cursor:pointer}._5Ym5W:hover:not([aria-disabled=true]){cursor:pointer;background-color:#f5f5f5}._5Ym5W:focus{box-shadow:0 0 0 2px #fff,0 0 0 4px #0a3f88;background-color:#fafafa}._5Ym5W:disabled,._5Ym5W[aria-disabled=true]{color:#74777a;border-color:#e5e5e5;cursor:not-allowed}._5Ym5W._QVcbH{border-color:#b00}._5Ym5W._QVcbH:focus{box-shadow:0 0 0 2px #fff,0 0 0 4px #900000}._5Ym5W._vSoKd{min-width:120px;padding:0 4px 0 12px}._5Ym5W._csAvZ{margin-top:4px}._5Ym5W._zk3mq:not([aria-disabled=true]):not(:disabled){color:#32363a}._5Ym5W ._5mwEh{display:inline-flex;align-items:center;min-height:10px}._5Ym5W ._5mwEh._Oc-MT{line-height:20px;font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}._5Ym5W ._Z0RPQ{height:24px;width:24px;border-radius:4px;fill:#515559;flex-shrink:0;cursor:pointer}._5Ym5W ._Z0RPQ._TEWRH{border-color:#e5e5e5;fill:#9d9fa1;opacity:.4;cursor:not-allowed}._5Ym5W ._Z0RPQ._rjvAN{transform:rotate(-180deg)}._5lMF-[aria-disabled=true]{cursor:not-allowed;color:rgba(81,85,89,.65);fill:#9d9fa1}._2YXi1{position:sticky;top:0;z-index:20;padding:4px 8px 8px!important;border-bottom:1px solid #e8e8e8;border-radius:4px 4px 0 0;background-color:#fff!important}._CTuRo{min-height:40px;padding:10px 12px;display:flex;flex-direction:row;align-items:center;background-color:#fff;font-size:14px;color:#32363a;word-break:break-word}._XzebP{fill:#515559}._tYCdy{margin:2px 12px 2px 0}._tYCdy._LxnoL>svg{border-color:#0b6ed0}._s3Uv4{width:100%}";
|
|
6
6
|
styleInject(css_248z);
|
|
7
7
|
|
|
8
8
|
export { styles as default, stylesheet };
|
|
@@ -15,8 +15,6 @@ import getSubDataTestId from '../../utils/getSubDataTestId/getSubDataTestId.js';
|
|
|
15
15
|
import ChevronDownIcon from '../../icons/components/ChevronDownIcon.js';
|
|
16
16
|
|
|
17
17
|
const DropdownButton = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
18
|
-
var _ref2, _children$props$aria, _children$props, _ref3, _children$props$aria2, _children$props2, _ref4, _children$props$aria3, _children$props3, _children$props$tabIn, _children$props4, _children$props7, _children$props8;
|
|
19
|
-
|
|
20
18
|
let {
|
|
21
19
|
children,
|
|
22
20
|
className,
|
|
@@ -54,7 +52,8 @@ const DropdownButton = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
54
52
|
ariaDescribedby: dropdownAriaDescribedby,
|
|
55
53
|
dataTestId: contextDataTestId
|
|
56
54
|
} = useDropdownContext();
|
|
57
|
-
const [label, setLabel] = useControllableState(defaultLabel,
|
|
55
|
+
const [label, setLabel] = useControllableState(defaultLabel,
|
|
56
|
+
// will get updated in effect
|
|
58
57
|
onLabelChange, externalLabel);
|
|
59
58
|
const [isOptionSelected, setIsOptionSelected] = useState(false);
|
|
60
59
|
const {
|
|
@@ -62,9 +61,9 @@ const DropdownButton = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
62
61
|
helperTextId: formFieldHelperTextId,
|
|
63
62
|
errorTextId: formFieldErrorTextId
|
|
64
63
|
} = useFormFieldControl();
|
|
65
|
-
const ariaLabelledBy =
|
|
66
|
-
const ariaLabel =
|
|
67
|
-
const ariaDescribedby = concatIds(
|
|
64
|
+
const ariaLabelledBy = children?.props?.['aria-labelledby'] ?? externalAriaLabelledBy ?? (dropdownAriaLabelledBy ? `${dropdownAriaLabelledBy} ${buttonId}` : undefined);
|
|
65
|
+
const ariaLabel = children?.props?.['aria-label'] ?? externalAriaLabel ?? (dropdownAriaLabel && typeof label === 'string' ? `${dropdownAriaLabel} ${label}` : dropdownAriaLabel);
|
|
66
|
+
const ariaDescribedby = concatIds(children?.props?.['aria-describedby'] ?? externalAriaDescribedBy ?? dropdownAriaDescribedby, formFieldHelperTextId, formFieldErrorTextId);
|
|
68
67
|
useEffect(() => {
|
|
69
68
|
const selectedLabels = [];
|
|
70
69
|
options.forEach(option => {
|
|
@@ -76,34 +75,29 @@ const DropdownButton = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
76
75
|
setLabel(selectedLabels.length > 0 ? selectedLabels.join(', ') : defaultLabel);
|
|
77
76
|
}, [setLabel, options, defaultLabel]);
|
|
78
77
|
useEffect(() => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
setMinWidth(buttonRef === null || buttonRef === void 0 ? void 0 : (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 ? void 0 : _buttonRef$current.offsetWidth);
|
|
78
|
+
setMinWidth(buttonRef?.current?.offsetWidth);
|
|
82
79
|
});
|
|
83
80
|
const isInvalid = isInvalidProp !== undefined ? isInvalidProp : dropdownIsInvalid;
|
|
84
|
-
|
|
85
81
|
const handleClick = e => {
|
|
86
|
-
if (disabled
|
|
87
|
-
onClick
|
|
88
|
-
|
|
82
|
+
if (disabled ?? dropdownAriaDisabled) return;
|
|
83
|
+
onClick?.(e);
|
|
84
|
+
// Needed because some browsers don't focus on click
|
|
89
85
|
e.currentTarget.focus();
|
|
90
86
|
setIsOpen(currentIsOpen => {
|
|
91
87
|
setHighlightedIndex(currentIsOpen ? -1 : selectedIndex);
|
|
92
88
|
return !currentIsOpen;
|
|
93
89
|
});
|
|
94
90
|
};
|
|
95
|
-
|
|
96
91
|
const handleKeyDown = e => {
|
|
97
|
-
if (disabled
|
|
98
|
-
onKeyDown
|
|
92
|
+
if (disabled ?? dropdownAriaDisabled) return;
|
|
93
|
+
onKeyDown?.(e);
|
|
99
94
|
onKeyDownButton(e);
|
|
100
95
|
};
|
|
101
|
-
|
|
102
96
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, children ? /*#__PURE__*/React__default.cloneElement(children, {
|
|
103
|
-
ref: mergeRefs(ref, children
|
|
97
|
+
ref: mergeRefs(ref, children?.ref, buttonRef, dropdownButtonRef),
|
|
104
98
|
disabled: disabled || dropdownAriaDisabled,
|
|
105
99
|
'aria-disabled': dropdownAriaDisabled,
|
|
106
|
-
tabIndex:
|
|
100
|
+
tabIndex: children.props?.tabIndex ?? 0,
|
|
107
101
|
role: 'button',
|
|
108
102
|
'aria-expanded': isOpen,
|
|
109
103
|
'aria-haspopup': 'listbox',
|
|
@@ -113,19 +107,15 @@ const DropdownButton = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
113
107
|
'aria-describedby': ariaDescribedby,
|
|
114
108
|
id: buttonId,
|
|
115
109
|
onFocus: e => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
(_children$props5 = children.props) === null || _children$props5 === void 0 ? void 0 : (_children$props5$onFo = _children$props5.onFocus) === null || _children$props5$onFo === void 0 ? void 0 : _children$props5$onFo.call(_children$props5, e);
|
|
119
|
-
onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
|
|
110
|
+
children.props?.onFocus?.(e);
|
|
111
|
+
onFocus?.(e);
|
|
120
112
|
},
|
|
121
113
|
onBlur: e => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
(_children$props6 = children.props) === null || _children$props6 === void 0 ? void 0 : (_children$props6$onBl = _children$props6.onBlur) === null || _children$props6$onBl === void 0 ? void 0 : _children$props6$onBl.call(_children$props6, e);
|
|
125
|
-
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
114
|
+
children.props?.onBlur?.(e);
|
|
115
|
+
onBlur?.(e);
|
|
126
116
|
},
|
|
127
|
-
onKeyDown: wrapEvent(
|
|
128
|
-
onClick: wrapEvent(
|
|
117
|
+
onKeyDown: wrapEvent(children.props?.onKeyDown, handleKeyDown),
|
|
118
|
+
onClick: wrapEvent(children.props?.onClick, handleClick)
|
|
129
119
|
}) : /*#__PURE__*/React__default.createElement("button", _extends({}, rest, {
|
|
130
120
|
ref: mergeRefs(ref, buttonRef, dropdownButtonRef),
|
|
131
121
|
type: "button",
|
|
@@ -142,14 +132,14 @@ const DropdownButton = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
142
132
|
[styles.hasText]: !!label,
|
|
143
133
|
[styles.invalid]: isInvalid,
|
|
144
134
|
[styles.labelled]: hasFormLabel,
|
|
145
|
-
[styles.selected]: externalLabel
|
|
146
|
-
|
|
135
|
+
[styles.selected]: externalLabel ?? isOptionSelected // defaultLabel has lighter text color
|
|
147
136
|
}),
|
|
137
|
+
|
|
148
138
|
onFocus: onFocus,
|
|
149
139
|
onBlur: onBlur,
|
|
150
140
|
onKeyDown: handleKeyDown,
|
|
151
141
|
onClick: handleClick,
|
|
152
|
-
"data-testid": dataTestId
|
|
142
|
+
"data-testid": dataTestId ?? getSubDataTestId(contextDataTestId, 'button')
|
|
153
143
|
}), /*#__PURE__*/React__default.createElement("span", {
|
|
154
144
|
className: classNames(styles.buttonLabel, {
|
|
155
145
|
[styles.isString]: typeof label === 'string'
|
|
@@ -158,7 +148,7 @@ const DropdownButton = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
|
158
148
|
size: "medium",
|
|
159
149
|
className: classNames(styles.icon, {
|
|
160
150
|
[styles.open]: isOpen,
|
|
161
|
-
[styles.disabled]: disabled
|
|
151
|
+
[styles.disabled]: disabled ?? dropdownAriaDisabled
|
|
162
152
|
}),
|
|
163
153
|
"aria-hidden": "true"
|
|
164
154
|
})));
|
|
@@ -47,10 +47,11 @@ const DropdownList = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
47
47
|
translate
|
|
48
48
|
} = useTranslation();
|
|
49
49
|
const noMatchesText = useMemo(() => isSearchable && translate('noMatchesFound'), [isSearchable, translate]);
|
|
50
|
-
const ariaLabelledby = externalAriaLabelledBy
|
|
51
|
-
const ariaLabel = externalAriaLabel
|
|
50
|
+
const ariaLabelledby = externalAriaLabelledBy ?? ariaLabelledByFromContext;
|
|
51
|
+
const ariaLabel = externalAriaLabel ?? ariaLabelFromContext;
|
|
52
52
|
const announceToScreenReader = useScreenReaderAnnouncement('assertive');
|
|
53
|
-
const showNoResults = useMemo(() => options.filter(option => option.isVisible).length === 1,
|
|
53
|
+
const showNoResults = useMemo(() => options.filter(option => option.isVisible).length === 1,
|
|
54
|
+
// 1 to include the search box entry
|
|
54
55
|
[options]);
|
|
55
56
|
useDidUpdate(() => {
|
|
56
57
|
if (showNoResults && isSearchable) {
|
|
@@ -78,14 +79,14 @@ const DropdownList = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
78
79
|
"aria-labelledby": ariaLabelledby,
|
|
79
80
|
hidden: !isOpen,
|
|
80
81
|
onKeyDown: e => {
|
|
81
|
-
onKeyDown
|
|
82
|
+
onKeyDown?.(e);
|
|
82
83
|
onKeyDownList(e);
|
|
83
84
|
},
|
|
84
85
|
style: {
|
|
85
86
|
minWidth,
|
|
86
87
|
...style
|
|
87
88
|
},
|
|
88
|
-
"data-testid": dataTestId
|
|
89
|
+
"data-testid": dataTestId ?? getSubDataTestId(contextDataTestId, 'flyout')
|
|
89
90
|
}), isSearchable && /*#__PURE__*/React__default.createElement(DropdownSearch, null), /*#__PURE__*/React__default.createElement("div", {
|
|
90
91
|
id: listboxId,
|
|
91
92
|
role: "listbox",
|
|
@@ -93,10 +94,10 @@ const DropdownList = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
93
94
|
"aria-label": ariaLabel,
|
|
94
95
|
"aria-labelledby": ariaLabelledby
|
|
95
96
|
}, children), isSearchable && showNoResults && /*#__PURE__*/React__default.createElement("div", {
|
|
96
|
-
className: styles.emptyOption
|
|
97
|
+
className: styles.emptyOption
|
|
98
|
+
// eslint-disable-next-line jsx-a11y/role-has-required-aria-props
|
|
97
99
|
,
|
|
98
100
|
role: "option" // `aria-selected` is omitted because this option is not selectable
|
|
99
|
-
|
|
100
101
|
}, noMatchesText))
|
|
101
102
|
});
|
|
102
103
|
});
|