@qualtrics/ui-react 2.24.2 → 2.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/__shared/cjs/{index-8f52588d.js → index-ae6df097.js} +3 -3
- package/dist/__shared/cjs/{index-b7a35c2e.js → index-dc6f69ac.js} +262 -256
- package/dist/components/Accordion/Accordion2.js +3 -3
- package/dist/components/Button/Button.js +3 -3
- package/dist/components/Button/Button2.js +1 -1
- package/dist/components/ButtonGroup/ButtonGroup2.js +3 -3
- package/dist/components/Checkbox/Checkbox2.js +3 -3
- package/dist/components/Checkbox/VisualCheckbox2.js +3 -3
- package/dist/components/ColorPicker/Alpha.js +1 -1
- package/dist/components/ColorPicker/ColorPicker2.js +3 -3
- package/dist/components/ColorPicker/Hue.js +1 -1
- package/dist/components/ColorPicker/Palette.js +1 -1
- package/dist/components/ColorPicker/Saturation.js +1 -1
- package/dist/components/Combobox/Combobox.js +3 -3
- package/dist/components/Combobox/Combobox2.js +3 -3
- package/dist/components/Combobox/ComboboxIcon.js +1 -1
- package/dist/components/Combobox/ComboboxInput.js +1 -1
- package/dist/components/ConfigPane/ConfigPane2.js +3 -3
- package/dist/components/Divider/Divider2.js +3 -3
- package/dist/components/Dropdown/Dropdown.js +4 -4
- package/dist/components/Dropdown/Dropdown2.js +3 -3
- package/dist/components/Dropdown/DropdownButton.js +6 -6
- package/dist/components/Dropdown/DropdownList.js +1 -1
- package/dist/components/Dropdown/DropdownOption.js +2 -2
- package/dist/components/Dropdown/DropdownSearch.js +2 -2
- package/dist/components/FilePicker/FilePicker.js +2 -2
- package/dist/components/FilePicker/FilePicker2.js +3 -3
- package/dist/components/FormField/Caption.js +3 -3
- package/dist/components/FormField/FormField2.js +3 -3
- package/dist/components/FormField/FormFieldContext.js +3 -3
- package/dist/components/FullScreenTakeover/FullScreenTakeover.js +2 -2
- package/dist/components/FullScreenTakeover/FullScreenTakeover2.js +3 -3
- package/dist/components/IconButton/IconButton2.js +3 -3
- package/dist/components/InlineInput/InlineInput.js +7 -7
- package/dist/components/InlineInput/InlineInput2.js +3 -3
- package/dist/components/Input/Input2.js +3 -3
- package/dist/components/Input/InputField.js +2 -2
- package/dist/components/InputGroup/InputGroup2.js +3 -3
- package/dist/components/Label/Label2.js +3 -3
- package/dist/components/Link/Link2.js +3 -3
- package/dist/components/LoadingSpinner/LoadingSpinner2.js +3 -3
- package/dist/components/LogicEditor/LogicEditor.js +1 -1
- package/dist/components/LogicEditor/LogicEditor2.js +3 -3
- package/dist/components/Modal/Modal.js +6 -6
- package/dist/components/Modal/Modal2.js +3 -3
- package/dist/components/NewMenu/BaseMenu.js +3 -3
- package/dist/components/NewMenu/NewMenu.js +3 -3
- package/dist/components/NewMenu/SelectMenu/SelectMenu.js +2 -2
- package/dist/components/NewMenu/parts/ArrowNav/ArrowNav.js +3 -3
- package/dist/components/NumberStepper/NumberStepper.js +2 -2
- package/dist/components/NumberStepper/NumberStepper2.js +3 -3
- package/dist/components/NumberStepper/NumberStepperDecrement.js +1 -1
- package/dist/components/NumberStepper/NumberStepperIncrement.js +1 -1
- package/dist/components/NumberStepper/NumberStepperInput.js +3 -3
- package/dist/components/PageLayout/PageLayout.js +3 -3
- package/dist/components/Pagination/Pagination.js +1 -1
- package/dist/components/Pagination/Pagination2.js +3 -3
- package/dist/components/Pagination/PaginationNextButton.js +3 -3
- package/dist/components/Pagination/PaginationPageInput.js +8 -8
- package/dist/components/Pagination/PaginationPreviousButton.js +3 -3
- package/dist/components/Popover/Popover.js +5 -5
- package/dist/components/Popover/Popover2.js +3 -3
- package/dist/components/QuickSearch/QuickSearch2.js +3 -3
- package/dist/components/QuickSearch/QuickSearchInput.js +4 -4
- package/dist/components/Radio/Radio2.js +3 -3
- package/dist/components/SearchInput/SearchInput.js +2 -2
- package/dist/components/SearchInput/SearchInput2.js +3 -3
- package/dist/components/SidebarNav/SidebarNav.js +1 -1
- package/dist/components/SidebarNav/SidebarNav2.js +3 -3
- package/dist/components/Slider/Slider2.js +3 -3
- package/dist/components/Switch/Switch2.js +3 -3
- package/dist/components/Table/Table2.js +3 -3
- package/dist/components/Tabs/Tabs2.js +3 -3
- package/dist/components/Tooltip/Tooltip2.js +3 -3
- package/dist/components/deprecated_ColorPicker/Alpha.js +2 -2
- package/dist/components/deprecated_ColorPicker/ColorPicker.js +1 -1
- package/dist/components/deprecated_ColorPicker/ColorPicker2.js +3 -3
- package/dist/components/deprecated_ColorPicker/HexInput.js +1 -1
- package/dist/components/deprecated_ColorPicker/Hue.js +2 -2
- package/dist/components/deprecated_ColorPicker/Saturation.js +2 -2
- package/dist/components/deprecated_ColorPicker/Swatch.js +1 -1
- package/dist/components/deprecated_NumberStepper/NumberStepper2.js +3 -3
- package/dist/components/deprecated_NumberStepper/NumberStepperDecrement.js +1 -1
- package/dist/components/deprecated_NumberStepper/NumberStepperIncrement.js +1 -1
- package/dist/components/deprecated_NumberStepper/NumberStepperInput.js +3 -3
- package/dist/components/deprecated_Tabs/Tabs.js +3 -3
- package/dist/components/deprecated_Tabs/Tabs2.js +3 -3
- package/dist/components/deprecated_Toolbar/Toolbar2.js +3 -3
- package/dist/components/deprecated_Toolbar/ToolbarPanels.js +1 -1
- package/dist/components/deprecated_Toolbar/ToolbarTab.js +5 -5
- package/dist/components/deprecated_Toolbar/ToolbarTabs.js +3 -3
- package/dist/hooks/useControllableState/useControllableState.js +1 -1
- package/dist/hooks/useOverlay/useOverlay.js +3 -3
- package/dist/hooks/useOverlay/useOverlay2.js +3 -3
- package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement.js +1 -1
- package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement2.js +3 -3
- package/dist/icons/Icon.js +3 -3
- package/dist/icons/index.js +1 -1
- package/dist/index.d.ts +15 -7
- package/dist/index.es.js +2 -1
- package/dist/index.js +4 -3
- package/dist/next/AdvancedTable/AdvancedTable.js +8 -6
- package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
- package/dist/next/AdvancedTable/AdvancedTableCell.js +4 -4
- package/dist/next/AdvancedTable/AdvancedTableCheckbox.js +6 -3
- package/dist/next/AdvancedTable/AdvancedTableColumnHeader.js +3 -3
- package/dist/next/AdvancedTable/AdvancedTableColumnHeaderMenu.js +2 -2
- package/dist/next/AdvancedTable/AdvancedTablePagination.js +1 -1
- package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput.js +3 -3
- package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput2.js +3 -3
- package/dist/next/Combobox/Combobox.js +2 -0
- package/dist/next/Combobox/Combobox2.js +3 -3
- package/dist/next/Combobox/ComboboxInput.js +2 -0
- package/dist/next/Combobox/ComboboxOption.js +2 -0
- package/dist/next/Combobox/hooks/useComboboxFocusSequence/useComboboxFocusSequence.js +1 -1
- package/dist/next/Drawer/Drawer.js +2 -2
- package/dist/next/Drawer/Drawer2.js +3 -3
- package/dist/next/FilterAnchor/FilterAnchor.js +2 -2
- package/dist/next/FilterAnchor/FilterAnchor2.js +3 -3
- package/dist/next/Input/Input2.js +3 -3
- package/dist/next/Menu/{useCSSVariable.js → Hooks/useCSSVariable.js} +1 -1
- package/dist/next/Menu/Hooks/useFocusVirtualBoundary.js +41 -0
- package/dist/next/Menu/Hooks/useIsVirtualized.js +8 -0
- package/dist/next/Menu/Hooks/useMaskDimensions.js +59 -0
- package/dist/next/Menu/{useMutationObserver.js → Hooks/useMutationObserver.js} +1 -1
- package/dist/next/Menu/{usePaneSearch.js → Hooks/usePaneSearch.js} +76 -34
- package/dist/next/Menu/Menu.js +22 -24
- package/dist/next/Menu/Menu2.js +3 -3
- package/dist/next/Menu/MenuButton.js +5 -2
- package/dist/next/Menu/MenuContext.js +5 -1
- package/dist/next/Menu/MenuItem.js +38 -16
- package/dist/next/Menu/MenuPane.js +90 -55
- package/dist/next/Menu/PaneChildren.js +47 -0
- package/dist/next/Menu/SubMenu.js +95 -49
- package/dist/next/PhoneNumberInput/PhoneNumberInput.js +1 -1
- package/dist/next/PhoneNumberInput/PhoneNumberInput2.js +3 -3
- package/dist/next/Select/Select.js +118 -0
- package/dist/next/Select/Select2.js +8 -0
- package/dist/next/Select/SelectButton.js +46 -0
- package/dist/next/Select/SelectContext.js +16 -0
- package/dist/next/Select/SelectItem.js +46 -0
- package/dist/next/Select/SelectPane.js +43 -0
- package/dist/next/Select/SelectedItems.js +45 -0
- package/dist/next/Select/SubSelect.js +90 -0
- package/dist/next/Select/constants.js +13 -0
- package/dist/next/Select/index.js +5 -0
- package/dist/next/SplitButton/SplitButton2.js +3 -3
- package/dist/next/TimePicker/TimePicker2.js +3 -3
- package/dist/next/TimePicker/TimePickerIcon.js +1 -1
- package/dist/next/ToggleButton/styles.js +3 -3
- package/dist/next/index.d.ts +68 -6
- package/dist/next/index.es.js +6 -0
- package/dist/next/index.js +1009 -372
- package/dist/translations-en.js +7 -1
- package/dist/utils/Flyout/Flyout2.js +3 -3
- package/dist/utils/Popper/Popper.js +2 -2
- package/dist/utils/mediaQueryManager/mediaQueryManager.js +1 -1
- package/dist/utils/wrapEvent/wrapEvent.js +1 -1
- package/icons/package.json +2 -0
- package/next/package.json +3 -1
- package/package.json +6 -3
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React__default, { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
const useIsVirtualized = function (children) {
|
|
4
|
+
let isVirtualizationDisabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
|
|
5
|
+
return useMemo(() => !isVirtualizationDisabled && React__default.Children.count(children) >= 25, [children, isVirtualizationDisabled]);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { useIsVirtualized as default };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import useResizeObserver from '@react-hook/resize-observer';
|
|
3
|
+
import '../../../hooks/index.js';
|
|
4
|
+
import { useMenuContext } from '../MenuContext.js';
|
|
5
|
+
import { useDidUpdate } from '../../../hooks/useDidUpdate/useDidUpdate.js';
|
|
6
|
+
|
|
7
|
+
const useMaskDimensions = (target, animatedLeft, paneDepth, children) => {
|
|
8
|
+
var _process$env;
|
|
9
|
+
const {
|
|
10
|
+
setMaskHeight,
|
|
11
|
+
maskHeight,
|
|
12
|
+
setMaskWidth,
|
|
13
|
+
openPaneDepth,
|
|
14
|
+
open
|
|
15
|
+
} = useMenuContext();
|
|
16
|
+
const updateMaskDimensions = () => {
|
|
17
|
+
if (target) {
|
|
18
|
+
setMaskHeight(target.clientHeight);
|
|
19
|
+
setMaskWidth(target.clientWidth);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const auto = 'auto';
|
|
23
|
+
|
|
24
|
+
// resets dimensions on menu close, so that the top-level pane reopens immediately, rather than animating
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!open) {
|
|
27
|
+
setMaskHeight(auto);
|
|
28
|
+
setMaskWidth(auto);
|
|
29
|
+
}
|
|
30
|
+
}, [open, setMaskHeight, setMaskWidth]);
|
|
31
|
+
|
|
32
|
+
// handles async children adjustments by consumer
|
|
33
|
+
useDidUpdate(() => {
|
|
34
|
+
if (paneDepth === openPaneDepth) {
|
|
35
|
+
updateMaskDimensions();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
// ignoring other dependencies because this should only run when the children change
|
|
39
|
+
[children]);
|
|
40
|
+
|
|
41
|
+
// handles returning to this pane by traversing backwards
|
|
42
|
+
useDidUpdate(() => {
|
|
43
|
+
if (!animatedLeft) {
|
|
44
|
+
updateMaskDimensions();
|
|
45
|
+
}
|
|
46
|
+
}, [animatedLeft]);
|
|
47
|
+
|
|
48
|
+
// handles dynamic resizing by both radix and virtuoso
|
|
49
|
+
useResizeObserver(target, () => {
|
|
50
|
+
if (openPaneDepth === paneDepth) {
|
|
51
|
+
updateMaskDimensions();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// determines if the mask is ready
|
|
56
|
+
return maskHeight !== auto || typeof process !== 'undefined' && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === 'test';
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { useMaskDimensions as default };
|
|
@@ -8,7 +8,7 @@ const useMutationObserver = (target, options, onMutate) => useEffect(() => {
|
|
|
8
8
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
9
|
args[_key] = arguments[_key];
|
|
10
10
|
}
|
|
11
|
-
onMutate === null || onMutate === void 0
|
|
11
|
+
onMutate === null || onMutate === void 0 || onMutate(...args);
|
|
12
12
|
});
|
|
13
13
|
observer.observe(target, options);
|
|
14
14
|
return () => observer.disconnect();
|
|
@@ -1,21 +1,39 @@
|
|
|
1
|
-
import React__default, { useState, useEffect, useRef, useCallback } from 'react';
|
|
1
|
+
import React__default, { useState, useMemo, useEffect, useRef, useCallback } from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
import { useMenuContext } from '
|
|
6
|
-
import { KEYS, DATA_TESTID_SUFFIXES } from '
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
3
|
+
import '../../../hooks/index.js';
|
|
4
|
+
import '../../../utils/index.js';
|
|
5
|
+
import { useMenuContext } from '../MenuContext.js';
|
|
6
|
+
import { KEYS, DATA_TESTID_SUFFIXES as DATA_TESTID_SUFFIXES$1 } from '../constants.js';
|
|
7
|
+
import { DATA_TESTID_SUFFIXES } from '../../Select/constants.js';
|
|
8
|
+
import styles from '../Menu2.js';
|
|
9
|
+
import useSelectContext from '../../Select/SelectContext.js';
|
|
10
|
+
import useFocusVirtualBoundary from './useFocusVirtualBoundary.js';
|
|
11
|
+
import useControllableState from '../../../hooks/useControllableState/useControllableState.js';
|
|
12
|
+
import useTranslation from '../../../utils/Translation/useTranslation.js';
|
|
13
|
+
import useEventListener from '../../../hooks/useEventListener/useEventListener.js';
|
|
11
14
|
|
|
12
15
|
// abstracts the logic required for searching by both `MenuPane` and `SubMenu`
|
|
13
16
|
// creates a searchBarConfig, which maps to an instance of `MenuSearch`
|
|
14
17
|
// returns values that are necessary for use within pane
|
|
15
|
-
function usePaneSearch(
|
|
18
|
+
function usePaneSearch(_ref) {
|
|
16
19
|
var _searchRef$current$qu, _searchRef$current;
|
|
17
|
-
let
|
|
18
|
-
|
|
20
|
+
let {
|
|
21
|
+
isSearchable,
|
|
22
|
+
externalSearchValue,
|
|
23
|
+
onSearchValueChange,
|
|
24
|
+
items,
|
|
25
|
+
animatedLeft,
|
|
26
|
+
animatedRight,
|
|
27
|
+
menuParentDataTestId,
|
|
28
|
+
id,
|
|
29
|
+
flyoutRef,
|
|
30
|
+
children,
|
|
31
|
+
isSearchFilteringDisabled,
|
|
32
|
+
backButtonRef,
|
|
33
|
+
closeSubmenu,
|
|
34
|
+
isVirtualized
|
|
35
|
+
} = _ref;
|
|
36
|
+
const withinSelect = useSelectContext(true) !== null;
|
|
19
37
|
const [internalSearchValue, setSearchValue] = useControllableState(externalSearchValue, onSearchValueChange, externalSearchValue);
|
|
20
38
|
const [zeroSearchResults, setZeroSearchResults] = useState();
|
|
21
39
|
const {
|
|
@@ -23,22 +41,34 @@ function usePaneSearch(isSearchable, externalSearchValue, onSearchValueChange, i
|
|
|
23
41
|
} = useTranslation();
|
|
24
42
|
const noMatchesText = translate('menu.noItemsToDisplay');
|
|
25
43
|
const searchPlaceholder = translate('searchText');
|
|
44
|
+
const filteredChildren = useMemo(() => (Array.isArray(children) ? children : [children]).filter(_ref2 => {
|
|
45
|
+
var _props$label, _searchMatcher$toLowe;
|
|
46
|
+
let {
|
|
47
|
+
props
|
|
48
|
+
} = _ref2;
|
|
49
|
+
if (!props || !internalSearchValue || isSearchFilteringDisabled) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const searchMatcher = (_props$label = props.label) !== null && _props$label !== void 0 ? _props$label : typeof props.children === 'string' ? props.children : undefined;
|
|
53
|
+
return searchMatcher === null || searchMatcher === void 0 || (_searchMatcher$toLowe = searchMatcher.toLowerCase) === null || _searchMatcher$toLowe === void 0 ? void 0 : _searchMatcher$toLowe.call(searchMatcher).includes(internalSearchValue.toLowerCase());
|
|
54
|
+
}), [internalSearchValue, children, isSearchFilteringDisabled]);
|
|
55
|
+
const focusVirtualBoundary = useFocusVirtualBoundary(items, backButtonRef);
|
|
26
56
|
useEffect(() => setZeroSearchResults((items === null || items === void 0 ? void 0 : items.filter(item => item.element.current).length) === 0), [items, internalSearchValue]);
|
|
27
57
|
const searchRef = useRef(null);
|
|
28
58
|
const searchInput = (_searchRef$current$qu = (_searchRef$current = searchRef.current) === null || _searchRef$current === void 0 ? void 0 : _searchRef$current.querySelector('input')) !== null && _searchRef$current$qu !== void 0 ? _searchRef$current$qu : null;
|
|
29
|
-
const
|
|
59
|
+
const getFirstVisibleItem = () => {
|
|
30
60
|
var _backButtonRef$curren, _items$find;
|
|
31
61
|
return (_backButtonRef$curren = backButtonRef === null || backButtonRef === void 0 ? void 0 : backButtonRef.current) !== null && _backButtonRef$curren !== void 0 ? _backButtonRef$curren : (_items$find = items.find(item => item.element.current)) === null || _items$find === void 0 ? void 0 : _items$find.element.current;
|
|
32
62
|
};
|
|
33
|
-
const
|
|
63
|
+
const getLastVisibleItem = () => {
|
|
34
64
|
var _findLast$element$cur, _findLast;
|
|
35
65
|
return (// our tsconfig does not target a recent enough version to use `Array.prototype.findLast`
|
|
36
66
|
(_findLast$element$cur = (_findLast = items.findLast(item => item.element.current)) === null || _findLast === void 0 ? void 0 : _findLast.element.current) !== null && _findLast$element$cur !== void 0 ? _findLast$element$cur : backButtonRef === null || backButtonRef === void 0 ? void 0 : backButtonRef.current
|
|
37
67
|
);
|
|
38
68
|
};
|
|
39
69
|
useEventListener(flyoutRef, 'keydown', e => {
|
|
40
|
-
if (KEYS.NAVIGATE_UP.includes(e.key) && e.target ===
|
|
41
|
-
searchInput === null || searchInput === void 0
|
|
70
|
+
if (KEYS.NAVIGATE_UP.includes(e.key) && e.target === getFirstVisibleItem() || KEYS.NAVIGATE_DOWN.includes(e.key) && e.target === getLastVisibleItem()) {
|
|
71
|
+
searchInput === null || searchInput === void 0 || searchInput.focus();
|
|
42
72
|
}
|
|
43
73
|
}, {
|
|
44
74
|
additionalDependencies: [flyoutRef.current],
|
|
@@ -49,17 +79,25 @@ function usePaneSearch(isSearchable, externalSearchValue, onSearchValueChange, i
|
|
|
49
79
|
var _e$target;
|
|
50
80
|
lastestKeyPressedInSearchInput.current = e.key;
|
|
51
81
|
if ([...KEYS.NAVIGATE_DOWN, ...KEYS.NAVIGATE_TOP].includes(e.key)) {
|
|
52
|
-
var _getFirstNonNullItem;
|
|
53
82
|
// prevent scrolling
|
|
54
83
|
e.preventDefault();
|
|
55
|
-
|
|
84
|
+
if (isVirtualized) {
|
|
85
|
+
focusVirtualBoundary('top');
|
|
86
|
+
} else {
|
|
87
|
+
var _getFirstVisibleItem;
|
|
88
|
+
(_getFirstVisibleItem = getFirstVisibleItem()) === null || _getFirstVisibleItem === void 0 || _getFirstVisibleItem.focus();
|
|
89
|
+
}
|
|
56
90
|
} else if ([...KEYS.NAVIGATE_UP, ...KEYS.NAVIIGATE_BOTTOM].includes(e.key)) {
|
|
57
|
-
var _getLastNonNullItem;
|
|
58
91
|
// prevent scrolling
|
|
59
92
|
e.preventDefault();
|
|
60
|
-
|
|
93
|
+
if (isVirtualized) {
|
|
94
|
+
focusVirtualBoundary('bottom');
|
|
95
|
+
} else {
|
|
96
|
+
var _getLastVisibleItem;
|
|
97
|
+
(_getLastVisibleItem = getLastVisibleItem()) === null || _getLastVisibleItem === void 0 || _getLastVisibleItem.focus();
|
|
98
|
+
}
|
|
61
99
|
} else if (KEYS.CLOSE_SUBMENU.includes(e.key) && ((_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.selectionStart) === 0) {
|
|
62
|
-
closeSubmenu === null || closeSubmenu === void 0
|
|
100
|
+
closeSubmenu === null || closeSubmenu === void 0 || closeSubmenu(e);
|
|
63
101
|
} else if (KEYS.IGNORED_BY_SEARCH_INPUT.includes(e.key)) {
|
|
64
102
|
e.preventDefault();
|
|
65
103
|
}
|
|
@@ -81,7 +119,7 @@ function usePaneSearch(isSearchable, externalSearchValue, onSearchValueChange, i
|
|
|
81
119
|
}) && e.preventDefault(), [searchBarConfigs]);
|
|
82
120
|
useEffect(() => {
|
|
83
121
|
if (!isSearchable) {
|
|
84
|
-
return
|
|
122
|
+
return;
|
|
85
123
|
}
|
|
86
124
|
setSearchBarConfigs(configs => {
|
|
87
125
|
const configsClone = [...configs];
|
|
@@ -90,7 +128,7 @@ function usePaneSearch(isSearchable, externalSearchValue, onSearchValueChange, i
|
|
|
90
128
|
isInteractive: !animatedLeft && !animatedRight,
|
|
91
129
|
animatedLeft,
|
|
92
130
|
animatedRight,
|
|
93
|
-
dataTestId: menuParentDataTestId === null || menuParentDataTestId === void 0 ? void 0 : menuParentDataTestId.replace(DATA_TESTID_SUFFIXES.MENU_PANE, DATA_TESTID_SUFFIXES.MENU_SEARCH),
|
|
131
|
+
dataTestId: menuParentDataTestId === null || menuParentDataTestId === void 0 ? void 0 : menuParentDataTestId.replace(withinSelect ? DATA_TESTID_SUFFIXES.SELECT_PANE : DATA_TESTID_SUFFIXES$1.MENU_PANE, withinSelect ? DATA_TESTID_SUFFIXES.SELECT_SEARCH : DATA_TESTID_SUFFIXES$1.MENU_SEARCH),
|
|
94
132
|
setSearchValue,
|
|
95
133
|
ref: searchRef,
|
|
96
134
|
id,
|
|
@@ -104,16 +142,19 @@ function usePaneSearch(isSearchable, externalSearchValue, onSearchValueChange, i
|
|
|
104
142
|
}
|
|
105
143
|
return configsClone;
|
|
106
144
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
},
|
|
145
|
+
}, [isSearchable, searchPlaceholder, setSearchBarConfigs, internalSearchValue, animatedLeft, animatedRight, menuParentDataTestId, setSearchValue, searchRef, id, withinSelect]);
|
|
146
|
+
useEffect(() => () => setSearchBarConfigs(configs => {
|
|
147
|
+
const configIndex = configs.findIndex(config => config.id === id);
|
|
148
|
+
if (configIndex === -1) {
|
|
149
|
+
return configs;
|
|
150
|
+
}
|
|
151
|
+
const configsClone = [...configs];
|
|
152
|
+
configsClone.splice(configIndex, 1);
|
|
153
|
+
return configsClone;
|
|
154
|
+
}),
|
|
155
|
+
// Omitted dependencies because we only want this to run on unmount
|
|
156
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
157
|
+
[]);
|
|
117
158
|
const noSearchResultsNode = zeroSearchResults && /*#__PURE__*/React__default.createElement("div", {
|
|
118
159
|
className: classNames(styles.menuItem, styles.noItems),
|
|
119
160
|
"aria-live": "assertive"
|
|
@@ -121,7 +162,8 @@ function usePaneSearch(isSearchable, externalSearchValue, onSearchValueChange, i
|
|
|
121
162
|
return {
|
|
122
163
|
internalSearchValue,
|
|
123
164
|
noSearchResultsNode,
|
|
124
|
-
onInteractOutside
|
|
165
|
+
onInteractOutside,
|
|
166
|
+
filteredChildren
|
|
125
167
|
};
|
|
126
168
|
}
|
|
127
169
|
|
package/dist/next/Menu/Menu.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import React__default, {
|
|
1
|
+
import React__default, { useRef, useState, useMemo } from 'react';
|
|
2
2
|
import { Root } from '@radix-ui/react-dropdown-menu';
|
|
3
|
+
import { ResizeObserver } from '@juggle/resize-observer';
|
|
3
4
|
import { MenuContextProvider } from './MenuContext.js';
|
|
4
5
|
import '../../hooks/index.js';
|
|
5
6
|
import useControllableState from '../../hooks/useControllableState/useControllableState.js';
|
|
7
|
+
import useEventListener from '../../hooks/useEventListener/useEventListener.js';
|
|
6
8
|
|
|
7
9
|
/* eslint-disable max-classes-per-file */
|
|
8
10
|
const Menu = _ref => {
|
|
@@ -12,7 +14,8 @@ const Menu = _ref => {
|
|
|
12
14
|
isOpen,
|
|
13
15
|
onIsOpenChange,
|
|
14
16
|
isDisabled,
|
|
15
|
-
children
|
|
17
|
+
children,
|
|
18
|
+
isVirtualizationDisabled
|
|
16
19
|
} = _ref;
|
|
17
20
|
if (typeof process !== 'undefined' && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === 'test' && window) {
|
|
18
21
|
var _window$ResizeObserve, _window$PointerEvent;
|
|
@@ -20,7 +23,9 @@ const Menu = _ref => {
|
|
|
20
23
|
window.PointerEvent = (_window$PointerEvent = window.PointerEvent) !== null && _window$PointerEvent !== void 0 ? _window$PointerEvent : PointerEvent;
|
|
21
24
|
}
|
|
22
25
|
const [open, setOpen] = useControllableState(isOpen, onIsOpenChange, isOpen);
|
|
26
|
+
const virtuoso = useRef(null);
|
|
23
27
|
const [maskHeight, setMaskHeight] = useState(null);
|
|
28
|
+
const [maskWidth, setMaskWidth] = useState(null);
|
|
24
29
|
const [submenus, setSubmenus] = useState(new Set());
|
|
25
30
|
const triggerRef = useRef(null);
|
|
26
31
|
const registerSubmenu = (submenuId, submenuIsOpen) => {
|
|
@@ -34,6 +39,16 @@ const Menu = _ref => {
|
|
|
34
39
|
return clone;
|
|
35
40
|
});
|
|
36
41
|
};
|
|
42
|
+
|
|
43
|
+
// Virtuoso and Radix-Dropdown have conflicting ResizeObserver behavior
|
|
44
|
+
// according to the author of the error, this is not a problem https://stackoverflow.com/a/50387233/9487902
|
|
45
|
+
// the virtuoso library author recommends this approach for conflicting libraries https://virtuoso.dev/react-beautiful-dnd/
|
|
46
|
+
useEventListener(window, 'error', e => {
|
|
47
|
+
if (e.message === 'ResizeObserver loop completed with undelivered notifications.' || e.message === 'ResizeObserver loop limit exceeded') {
|
|
48
|
+
e.stopImmediatePropagation();
|
|
49
|
+
e.preventDefault();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
37
52
|
const openPaneDepth = useMemo(() => open ? submenus.size + 1 : 0, [submenus, open]);
|
|
38
53
|
const [searchBarConfigs, setSearchBarConfigs] = useState([]);
|
|
39
54
|
return /*#__PURE__*/React__default.createElement(MenuContextProvider, {
|
|
@@ -47,7 +62,11 @@ const Menu = _ref => {
|
|
|
47
62
|
open,
|
|
48
63
|
triggerRef,
|
|
49
64
|
searchBarConfigs,
|
|
50
|
-
setSearchBarConfigs
|
|
65
|
+
setSearchBarConfigs,
|
|
66
|
+
maskWidth,
|
|
67
|
+
setMaskWidth,
|
|
68
|
+
virtuoso,
|
|
69
|
+
isVirtualizationDisabled
|
|
51
70
|
}
|
|
52
71
|
}, /*#__PURE__*/React__default.createElement(Root, {
|
|
53
72
|
open: open,
|
|
@@ -56,27 +75,6 @@ const Menu = _ref => {
|
|
|
56
75
|
}, children));
|
|
57
76
|
};
|
|
58
77
|
|
|
59
|
-
// https://github.com/radix-ui/primitives/issues/420#issuecomment-771615182
|
|
60
|
-
class ResizeObserver {
|
|
61
|
-
constructor(cb) {
|
|
62
|
-
this.cb = cb;
|
|
63
|
-
}
|
|
64
|
-
observe() {
|
|
65
|
-
this.cb([{
|
|
66
|
-
borderBoxSize: {
|
|
67
|
-
inlineSize: 0,
|
|
68
|
-
blockSize: 0
|
|
69
|
-
}
|
|
70
|
-
}]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// eslint-disable-next-line class-methods-use-this
|
|
74
|
-
unobserve() {}
|
|
75
|
-
|
|
76
|
-
// eslint-disable-next-line class-methods-use-this
|
|
77
|
-
disconnect() {}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
78
|
// https://github.com/radix-ui/primitives/issues/1220#issuecomment-1087465026
|
|
81
79
|
class PointerEvent extends Event {
|
|
82
80
|
constructor(type, props) {
|
package/dist/next/Menu/Menu2.js
CHANGED
|
@@ -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 = {"buttonContainer":"
|
|
5
|
-
var stylesheet=".
|
|
3
|
+
var css_248z = "._P-1qk{position:relative;display:inline-flex;height:36px;min-width:60px;cursor:pointer}._P-1qk>._avlWI{cursor:unset;width:100%;height:100%;padding:0 28px 0 12px;border-radius:4px;white-space:nowrap;line-height:20px;font-size:14px;text-align:left;outline:none;border:none;box-shadow:inset 0 0 0 1px #898989;color:#515559;background-color:#fafafa;overflow:hidden;text-overflow:ellipsis}._P-1qk>._avlWI:hover:not([aria-disabled=true]){background-color:#f5f5f5}._P-1qk>._avlWI.focus-visible,._P-1qk>._avlWI:focus-visible{background-color:#fafafa;box-shadow:0 0 0 2px #fff,0 0 0 4px #0a3f88}._P-1qk>._avlWI+._08qYC{fill:#515559;position:absolute;pointer-events:none;right:4px;top:50%;transform:translateY(-50%)}._P-1qk>._avlWI[data-state=open]+._08qYC{transform:rotate(-180deg) translateY(50%)}._P-1qk>._avlWI[aria-disabled=true]{box-shadow:inset 0 0 0 1px #e5e5e5;color:#74777a;cursor:not-allowed}._P-1qk>._avlWI[aria-disabled=true]+._08qYC{fill:#515559;opacity:.4}._gZOPA>[data-radix-popper-content-wrapper]{overflow:hidden;background-color:#fff;max-width:350px;min-width:200px!important;box-shadow:0 8px 20px rgba(0,0,0,.1),0 4px 6px rgba(0,0,0,.05);border-radius:4px;z-index:var(--mask-z-index)!important;width:var(--mask-width);height:var(--mask-height);transition:height .35s,width .35s}._gZOPA>[data-radix-popper-content-wrapper] [data-radix-popper-content-wrapper]{transform:translateZ(0)!important}._-nrnj{margin:0;padding-bottom:var(--flyout-bottom-padding);background:#fff;transition:margin-left .35s,opacity .35s,height .35s,width .35s;opacity:1;max-width:350px;width:-webkit-max-content;width:-moz-max-content;width:max-content;min-width:200px;max-height:var(--flyout-max-height)}._-nrnj ._sDfyk{height:100%;overflow-y:scroll}._-nrnj._zgTUU{margin-left:30px;opacity:0}._-nrnj._lOy6Z{margin-left:-30px}._TTaMv{position:relative;padding:10px 12px;display:flex;flex-direction:row;min-height:40px;align-items:center;cursor:pointer;outline:none;word-break:break-word;font-size:14px;color:#32363a;width:100%}._TTaMv._cWSdL{cursor:unset}._TTaMv ._5244S{fill:#32363a;margin-right:4px}._TTaMv:focus,._TTaMv:hover:not(._TTaMv._cWSdL){background-color:#efefef;box-shadow:inset 0 0 0 2px #0a3f88,inset 0 0 0 4px #fff;border-radius:6px}._TTaMv[aria-disabled=true]{cursor:not-allowed;opacity:.65}._TTaMv._al2zZ{padding-right:32px}._TTaMv._al2zZ ._08qYC{position:absolute;height:100%;right:3px;fill:#515559}._TTaMv._GIP-N{pointer-events:none}._5WkZQ{position:-webkit-sticky;position:sticky;top:0;background-color:#fff;border-bottom:1px solid #e8e8e8}._5WkZQ._eQooQ{padding-top:52px}._uUO-O{pointer-events:none;position:fixed;left:0;top:0;transition:width .35s;min-width:200px;width:var(--mask-width);max-width:350px}._wQQjr{position:absolute;padding:8px;border-radius:4px 4px 0 0;pointer-events:auto;opacity:1;width:100%;transition:opacity .35s,margin-left .35s}._wQQjr._lOy6Z{opacity:0}._wQQjr._lOy6Z>._9og9E{margin-left:-30px}._wQQjr._zgTUU{opacity:0}._wQQjr._zgTUU>._9og9E{margin-left:30px}._wQQjr>._9og9E{transition:margin-left .35s;width:100%}._wQQjr._GIP-N{pointer-events:none}body.keyboard-user ._TTaMv:hover:not(:focus){background-color:#fff;box-shadow:none}";
|
|
4
|
+
var styles = {"buttonContainer":"_P-1qk","button":"_avlWI","rightIcon":"_08qYC","maskContainer":"_gZOPA","flyout":"_-nrnj","scrollContainer":"_sDfyk","animatedRight":"_zgTUU","animatedLeft":"_lOy6Z","menuItem":"_TTaMv","noItems":"_cWSdL","backIcon":"_5244S","subMenu":"_al2zZ","unresponsive":"_GIP-N","stickyBox":"_5WkZQ","isSearchable":"_eQooQ","searchBoxesContainer":"_uUO-O","searchBox":"_wQQjr","searchInput":"_9og9E"};
|
|
5
|
+
var stylesheet="._P-1qk{position:relative;display:inline-flex;height:36px;min-width:60px;cursor:pointer}._P-1qk>._avlWI{cursor:unset;width:100%;height:100%;padding:0 28px 0 12px;border-radius:4px;white-space:nowrap;line-height:20px;font-size:14px;text-align:left;outline:none;border:none;box-shadow:inset 0 0 0 1px #898989;color:#515559;background-color:#fafafa;overflow:hidden;text-overflow:ellipsis}._P-1qk>._avlWI:hover:not([aria-disabled=true]){background-color:#f5f5f5}._P-1qk>._avlWI.focus-visible,._P-1qk>._avlWI:focus-visible{background-color:#fafafa;box-shadow:0 0 0 2px #fff,0 0 0 4px #0a3f88}._P-1qk>._avlWI+._08qYC{fill:#515559;position:absolute;pointer-events:none;right:4px;top:50%;transform:translateY(-50%)}._P-1qk>._avlWI[data-state=open]+._08qYC{transform:rotate(-180deg) translateY(50%)}._P-1qk>._avlWI[aria-disabled=true]{box-shadow:inset 0 0 0 1px #e5e5e5;color:#74777a;cursor:not-allowed}._P-1qk>._avlWI[aria-disabled=true]+._08qYC{fill:#515559;opacity:.4}._gZOPA>[data-radix-popper-content-wrapper]{overflow:hidden;background-color:#fff;max-width:350px;min-width:200px!important;box-shadow:0 8px 20px rgba(0,0,0,.1),0 4px 6px rgba(0,0,0,.05);border-radius:4px;z-index:var(--mask-z-index)!important;width:var(--mask-width);height:var(--mask-height);transition:height .35s,width .35s}._gZOPA>[data-radix-popper-content-wrapper] [data-radix-popper-content-wrapper]{transform:translateZ(0)!important}._-nrnj{margin:0;padding-bottom:var(--flyout-bottom-padding);background:#fff;transition:margin-left .35s,opacity .35s,height .35s,width .35s;opacity:1;max-width:350px;width:-webkit-max-content;width:-moz-max-content;width:max-content;min-width:200px;max-height:var(--flyout-max-height)}._-nrnj ._sDfyk{height:100%;overflow-y:scroll}._-nrnj._zgTUU{margin-left:30px;opacity:0}._-nrnj._lOy6Z{margin-left:-30px}._TTaMv{position:relative;padding:10px 12px;display:flex;flex-direction:row;min-height:40px;align-items:center;cursor:pointer;outline:none;word-break:break-word;font-size:14px;color:#32363a;width:100%}._TTaMv._cWSdL{cursor:unset}._TTaMv ._5244S{fill:#32363a;margin-right:4px}._TTaMv:focus,._TTaMv:hover:not(._TTaMv._cWSdL){background-color:#efefef;box-shadow:inset 0 0 0 2px #0a3f88,inset 0 0 0 4px #fff;border-radius:6px}._TTaMv[aria-disabled=true]{cursor:not-allowed;opacity:.65}._TTaMv._al2zZ{padding-right:32px}._TTaMv._al2zZ ._08qYC{position:absolute;height:100%;right:3px;fill:#515559}._TTaMv._GIP-N{pointer-events:none}._5WkZQ{position:-webkit-sticky;position:sticky;top:0;background-color:#fff;border-bottom:1px solid #e8e8e8}._5WkZQ._eQooQ{padding-top:52px}._uUO-O{pointer-events:none;position:fixed;left:0;top:0;transition:width .35s;min-width:200px;width:var(--mask-width);max-width:350px}._wQQjr{position:absolute;padding:8px;border-radius:4px 4px 0 0;pointer-events:auto;opacity:1;width:100%;transition:opacity .35s,margin-left .35s}._wQQjr._lOy6Z{opacity:0}._wQQjr._lOy6Z>._9og9E{margin-left:-30px}._wQQjr._zgTUU{opacity:0}._wQQjr._zgTUU>._9og9E{margin-left:30px}._wQQjr>._9og9E{transition:margin-left .35s;width:100%}._wQQjr._GIP-N{pointer-events:none}body.keyboard-user ._TTaMv:hover:not(:focus){background-color:#fff;box-shadow:none}";
|
|
6
6
|
if(typeof process !== 'object' || !process.hasOwnProperty('env') || process.env.NODE_ENV !== 'test'){styleInject(css_248z);}
|
|
7
7
|
|
|
8
8
|
export { styles as default, stylesheet };
|
|
@@ -6,9 +6,11 @@ import '../../icons/index.es.js';
|
|
|
6
6
|
import styles from './Menu2.js';
|
|
7
7
|
import '../../utils/index.js';
|
|
8
8
|
import { useMenuContext } from './MenuContext.js';
|
|
9
|
-
import { DATA_TESTID_SUFFIXES } from './constants.js';
|
|
9
|
+
import { DATA_TESTID_SUFFIXES as DATA_TESTID_SUFFIXES$1 } from './constants.js';
|
|
10
10
|
import '../../hooks/index.js';
|
|
11
11
|
import '../../components/index.js';
|
|
12
|
+
import { DATA_TESTID_SUFFIXES } from '../Select/constants.js';
|
|
13
|
+
import useSelectContext from '../Select/SelectContext.js';
|
|
12
14
|
import Tooltip from '../../components/Tooltip/Tooltip.js';
|
|
13
15
|
import useIsTruncated from '../../hooks/useIsTruncated/useIsTruncated.js';
|
|
14
16
|
import mergeRefs from '../../utils/mergeRefs/mergeRefs.js';
|
|
@@ -43,6 +45,7 @@ const MenuButton = /*#__PURE__*/React__default.forwardRef((_ref2, ref) => {
|
|
|
43
45
|
triggerRef
|
|
44
46
|
} = useMenuContext();
|
|
45
47
|
const isTruncated = useIsTruncated(triggerRef);
|
|
48
|
+
const withinSelect = useSelectContext(true) !== null;
|
|
46
49
|
return /*#__PURE__*/React__default.createElement(AsChildWrapper, {
|
|
47
50
|
asChild: asChild,
|
|
48
51
|
tooltipContent: children,
|
|
@@ -54,7 +57,7 @@ const MenuButton = /*#__PURE__*/React__default.forwardRef((_ref2, ref) => {
|
|
|
54
57
|
}),
|
|
55
58
|
asChild: asChild,
|
|
56
59
|
ref: mergeRefs(triggerRef, ref),
|
|
57
|
-
"data-testid": getSubDataTestId(rootDataTestId, DATA_TESTID_SUFFIXES.MENU_BUTTON)
|
|
60
|
+
"data-testid": getSubDataTestId(rootDataTestId, withinSelect ? DATA_TESTID_SUFFIXES.SELECT_BUTTON : DATA_TESTID_SUFFIXES$1.MENU_BUTTON)
|
|
58
61
|
}), children), !asChild && /*#__PURE__*/React__default.createElement(ChevronDownIcon, {
|
|
59
62
|
className: styles.rightIcon,
|
|
60
63
|
"aria-hidden": "true"
|
|
@@ -7,6 +7,10 @@ const {
|
|
|
7
7
|
useContext: useMenuContext,
|
|
8
8
|
Provider: MenuContextProvider
|
|
9
9
|
} = createContextUtilities();
|
|
10
|
+
const {
|
|
11
|
+
useContext: useItemContext,
|
|
12
|
+
Provider: ItemContextProvider
|
|
13
|
+
} = createContextUtilities({});
|
|
10
14
|
const {
|
|
11
15
|
useContext: intermediaryUseMenuContext,
|
|
12
16
|
Provider: IntermediaryMenuContextProvider
|
|
@@ -36,4 +40,4 @@ const usePaneContext = childItemRef => {
|
|
|
36
40
|
};
|
|
37
41
|
};
|
|
38
42
|
|
|
39
|
-
export { MenuContextProvider, PaneContextProvider, useMenuContext, usePaneContext };
|
|
43
|
+
export { ItemContextProvider, MenuContextProvider, PaneContextProvider, useItemContext, useMenuContext, usePaneContext };
|
|
@@ -4,9 +4,11 @@ import { Item } from '@radix-ui/react-dropdown-menu';
|
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import { useFocusVisible } from '@react-aria/interactions';
|
|
6
6
|
import styles from './Menu2.js';
|
|
7
|
-
import { usePaneContext } from './MenuContext.js';
|
|
7
|
+
import { usePaneContext, useItemContext } from './MenuContext.js';
|
|
8
8
|
import '../../utils/index.js';
|
|
9
|
-
import { DATA_TESTID_SUFFIXES
|
|
9
|
+
import { DATA_TESTID_SUFFIXES } from '../Select/constants.js';
|
|
10
|
+
import { DATA_TESTID_SUFFIXES as DATA_TESTID_SUFFIXES$1, KEYS } from './constants.js';
|
|
11
|
+
import useSelectContext from '../Select/SelectContext.js';
|
|
10
12
|
import getSubDataTestId from '../../utils/getSubDataTestId/getSubDataTestId.js';
|
|
11
13
|
import mergeRefs from '../../utils/mergeRefs/mergeRefs.js';
|
|
12
14
|
|
|
@@ -20,27 +22,31 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
20
22
|
label,
|
|
21
23
|
...rest
|
|
22
24
|
} = _ref;
|
|
25
|
+
const selectContext = useSelectContext(true);
|
|
26
|
+
const withinSelect = selectContext !== null;
|
|
27
|
+
const multiselect = selectContext === null || selectContext === void 0 ? void 0 : selectContext.multiselect;
|
|
23
28
|
const itemRef = useRef(null);
|
|
24
29
|
const {
|
|
25
30
|
dataTestId: menuParentDataTestId,
|
|
26
|
-
childIndex
|
|
27
|
-
searchValue,
|
|
28
|
-
isSearchFilteringDisabled,
|
|
31
|
+
childIndex,
|
|
29
32
|
isInteractive,
|
|
30
33
|
closeSubmenu,
|
|
31
34
|
flyoutRef,
|
|
32
|
-
stickyBoxRef
|
|
35
|
+
stickyBoxRef,
|
|
36
|
+
focusVirtualBoundary,
|
|
37
|
+
isVirtualized: paneIsVirtualized,
|
|
38
|
+
maskIsReady
|
|
33
39
|
} = usePaneContext(itemRef);
|
|
40
|
+
const {
|
|
41
|
+
virtualIndex
|
|
42
|
+
} = useItemContext();
|
|
43
|
+
const index = useMemo(() => virtualIndex !== null && virtualIndex !== void 0 ? virtualIndex : childIndex, [childIndex, virtualIndex]);
|
|
34
44
|
const {
|
|
35
45
|
isFocusVisible
|
|
36
46
|
} = useFocusVisible({
|
|
37
47
|
isTextInput: true
|
|
38
48
|
});
|
|
39
|
-
const dataTestId = getSubDataTestId(menuParentDataTestId === null || menuParentDataTestId === void 0 ? void 0 : menuParentDataTestId.replace(DATA_TESTID_SUFFIXES.MENU_PANE, DATA_TESTID_SUFFIXES.MENU_ITEM), String(index));
|
|
40
|
-
const isVisible = useMemo(() => {
|
|
41
|
-
const searchMatcher = label !== null && label !== void 0 ? label : typeof children === 'string' ? children : undefined;
|
|
42
|
-
return isSearchFilteringDisabled || !searchValue || (searchMatcher === null || searchMatcher === void 0 ? void 0 : searchMatcher.toLowerCase().includes(searchValue.toLowerCase()));
|
|
43
|
-
}, [children, searchValue, label, isSearchFilteringDisabled]);
|
|
49
|
+
const dataTestId = getSubDataTestId(menuParentDataTestId === null || menuParentDataTestId === void 0 ? void 0 : menuParentDataTestId.replace(withinSelect ? DATA_TESTID_SUFFIXES.SELECT_PANE : DATA_TESTID_SUFFIXES$1.MENU_PANE, withinSelect ? DATA_TESTID_SUFFIXES.SELECT_ITEM : DATA_TESTID_SUFFIXES$1.MENU_ITEM), String(index));
|
|
44
50
|
const handleFocus = () => {
|
|
45
51
|
if (itemRef.current && flyoutRef.current && isFocusVisible) {
|
|
46
52
|
var _stickyBoxRef$current, _stickyBoxRef$current2;
|
|
@@ -53,7 +59,7 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
53
59
|
}
|
|
54
60
|
}
|
|
55
61
|
};
|
|
56
|
-
return
|
|
62
|
+
return /*#__PURE__*/React__default.createElement(Item, _extends({}, rest, {
|
|
57
63
|
asChild: asChild,
|
|
58
64
|
"aria-disabled": isDisabled,
|
|
59
65
|
className: classNames(className, styles.menuItem, {
|
|
@@ -67,15 +73,31 @@ const MenuItem = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
67
73
|
return;
|
|
68
74
|
}
|
|
69
75
|
if (KEYS.CLOSE_SUBMENU.includes(e.key)) {
|
|
70
|
-
closeSubmenu === null || closeSubmenu === void 0
|
|
76
|
+
closeSubmenu === null || closeSubmenu === void 0 || closeSubmenu(e);
|
|
77
|
+
} else if (paneIsVirtualized && KEYS.NAVIGATE_TOP.includes(e.key)) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
focusVirtualBoundary('top');
|
|
80
|
+
} else if (paneIsVirtualized && KEYS.NAVIIGATE_BOTTOM.includes(e.key)) {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
focusVirtualBoundary('bottom');
|
|
71
83
|
}
|
|
72
84
|
},
|
|
73
85
|
onFocus: handleFocus
|
|
74
86
|
// stop radix from closing the menu on selection of disabled item
|
|
75
87
|
// other pointer and keyboard events still work, even when disabled
|
|
76
88
|
,
|
|
77
|
-
onSelect: e =>
|
|
78
|
-
|
|
89
|
+
onSelect: e => {
|
|
90
|
+
if (isDisabled || maskIsReady === false) {
|
|
91
|
+
e.preventDefault();
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (multiselect) {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
}
|
|
97
|
+
onSelect === null || onSelect === void 0 || onSelect();
|
|
98
|
+
}
|
|
99
|
+
}), (!children || typeof children === 'string') && label ? label : children);
|
|
79
100
|
});
|
|
101
|
+
var MenuItem$1 = MenuItem;
|
|
80
102
|
|
|
81
|
-
export { MenuItem as default };
|
|
103
|
+
export { MenuItem$1 as default };
|