@itwin/itwinui-react 3.17.2 → 3.17.4

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/DEV-cjs/core/ComboBox/ComboBox.js +17 -21
  3. package/DEV-cjs/core/ComboBox/ComboBoxMenu.js +6 -2
  4. package/DEV-cjs/core/DropdownMenu/DropdownMenu.js +55 -27
  5. package/DEV-cjs/core/Menu/Menu.js +64 -45
  6. package/DEV-cjs/core/Menu/MenuItem.js +6 -0
  7. package/DEV-cjs/core/Tabs/Tabs.js +7 -2
  8. package/DEV-cjs/core/Tile/Tile.js +25 -27
  9. package/DEV-cjs/core/Tree/Tree.js +25 -17
  10. package/DEV-cjs/styles.js +1 -1
  11. package/DEV-esm/core/ComboBox/ComboBox.js +17 -21
  12. package/DEV-esm/core/ComboBox/ComboBoxMenu.js +6 -2
  13. package/DEV-esm/core/DropdownMenu/DropdownMenu.js +40 -24
  14. package/DEV-esm/core/Menu/Menu.js +57 -42
  15. package/DEV-esm/core/Menu/MenuItem.js +9 -0
  16. package/DEV-esm/core/Tabs/Tabs.js +5 -2
  17. package/DEV-esm/core/Tile/Tile.js +29 -28
  18. package/DEV-esm/core/Tree/Tree.js +25 -17
  19. package/DEV-esm/styles.js +1 -1
  20. package/cjs/core/ComboBox/ComboBox.js +17 -21
  21. package/cjs/core/ComboBox/ComboBoxMenu.js +6 -2
  22. package/cjs/core/DropdownMenu/DropdownMenu.d.ts +10 -0
  23. package/cjs/core/DropdownMenu/DropdownMenu.js +55 -27
  24. package/cjs/core/Menu/Menu.d.ts +9 -1
  25. package/cjs/core/Menu/Menu.js +64 -45
  26. package/cjs/core/Menu/MenuItem.js +6 -0
  27. package/cjs/core/Tabs/Tabs.js +7 -2
  28. package/cjs/core/Tile/Tile.js +25 -27
  29. package/cjs/core/Tree/Tree.js +25 -17
  30. package/cjs/styles.js +1 -1
  31. package/esm/core/ComboBox/ComboBox.js +17 -21
  32. package/esm/core/ComboBox/ComboBoxMenu.js +6 -2
  33. package/esm/core/DropdownMenu/DropdownMenu.d.ts +10 -0
  34. package/esm/core/DropdownMenu/DropdownMenu.js +40 -24
  35. package/esm/core/Menu/Menu.d.ts +9 -1
  36. package/esm/core/Menu/Menu.js +57 -42
  37. package/esm/core/Menu/MenuItem.js +9 -0
  38. package/esm/core/Tabs/Tabs.js +5 -2
  39. package/esm/core/Tile/Tile.js +29 -28
  40. package/esm/core/Tree/Tree.js +25 -17
  41. package/esm/styles.js +1 -1
  42. package/package.json +2 -2
  43. package/styles.css +10 -10
@@ -25,11 +25,13 @@ export const Menu = React.forwardRef((props, ref) => {
25
25
  className,
26
26
  trigger,
27
27
  positionReference,
28
- portal = true,
28
+ portal: portalProp,
29
29
  popoverProps: popoverPropsProp,
30
30
  children,
31
31
  ...rest
32
32
  } = props;
33
+ let menuPortalContext = React.useContext(MenuPortalContext);
34
+ let portal = portalProp ?? menuPortalContext;
33
35
  let tree = useFloatingTree();
34
36
  let nodeId = useFloatingNodeId();
35
37
  let parentId = useFloatingParentNodeId();
@@ -125,32 +127,35 @@ export const Menu = React.forwardRef((props, ref) => {
125
127
  () => void 0,
126
128
  () => void 0,
127
129
  );
128
- let popoverGetItemProps = ({ focusableItemIndex, userProps }) =>
129
- getItemProps({
130
- ...userProps,
131
- tabIndex:
132
- null != activeIndex &&
133
- activeIndex >= 0 &&
134
- null != focusableItemIndex &&
135
- focusableItemIndex >= 0 &&
136
- activeIndex === focusableItemIndex
137
- ? 0
138
- : -1,
139
- onFocus: mergeEventHandlers(userProps?.onFocus, () => {
140
- queueMicrotask(() => {
141
- setHasFocusedNodeInSubmenu(true);
142
- });
143
- tree?.events.emit('onNodeFocused', {
144
- nodeId: nodeId,
145
- parentId: parentId,
146
- });
130
+ let popoverGetItemProps = React.useCallback(
131
+ ({ focusableItemIndex, userProps }) =>
132
+ getItemProps({
133
+ ...userProps,
134
+ tabIndex:
135
+ null != activeIndex &&
136
+ activeIndex >= 0 &&
137
+ null != focusableItemIndex &&
138
+ focusableItemIndex >= 0 &&
139
+ activeIndex === focusableItemIndex
140
+ ? 0
141
+ : -1,
142
+ onFocus: mergeEventHandlers(userProps?.onFocus, () => {
143
+ queueMicrotask(() => {
144
+ setHasFocusedNodeInSubmenu(true);
145
+ });
146
+ tree?.events.emit('onNodeFocused', {
147
+ nodeId: nodeId,
148
+ parentId: parentId,
149
+ });
150
+ }),
151
+ onMouseEnter: mergeEventHandlers(userProps?.onMouseEnter, (event) => {
152
+ if (null != focusableItemIndex && focusableItemIndex >= 0)
153
+ setActiveIndex(focusableItemIndex);
154
+ if (event.target === event.currentTarget) event.currentTarget.focus();
155
+ }),
147
156
  }),
148
- onMouseEnter: mergeEventHandlers(userProps?.onMouseEnter, (event) => {
149
- if (null != focusableItemIndex && focusableItemIndex >= 0)
150
- setActiveIndex(focusableItemIndex);
151
- if (event.target === event.currentTarget) event.currentTarget.focus();
152
- }),
153
- });
157
+ [activeIndex, getItemProps, nodeId, parentId, tree?.events],
158
+ );
154
159
  let reference = cloneElementWithRef(trigger, (triggerChild) =>
155
160
  getReferenceProps(
156
161
  popover.getReferenceProps({
@@ -189,28 +194,38 @@ export const Menu = React.forwardRef((props, ref) => {
189
194
  React.createElement(
190
195
  MenuContext.Provider,
191
196
  {
192
- value: {
193
- popoverGetItemProps,
194
- focusableElements,
195
- },
197
+ value: React.useMemo(
198
+ () => ({
199
+ popoverGetItemProps,
200
+ focusableElements,
201
+ }),
202
+ [focusableElements, popoverGetItemProps],
203
+ ),
196
204
  },
197
205
  React.createElement(
198
- PopoverOpenContext.Provider,
206
+ MenuPortalContext.Provider,
199
207
  {
200
- value: popover.open,
208
+ value: portal,
201
209
  },
202
- reference,
210
+ React.createElement(
211
+ PopoverOpenContext.Provider,
212
+ {
213
+ value: popover.open,
214
+ },
215
+ reference,
216
+ ),
217
+ null != tree
218
+ ? React.createElement(
219
+ FloatingNode,
220
+ {
221
+ id: nodeId,
222
+ },
223
+ floating,
224
+ )
225
+ : floating,
203
226
  ),
204
- null != tree
205
- ? React.createElement(
206
- FloatingNode,
207
- {
208
- id: nodeId,
209
- },
210
- floating,
211
- )
212
- : floating,
213
227
  ),
214
228
  );
215
229
  });
216
230
  export const MenuContext = React.createContext(void 0);
231
+ export const MenuPortalContext = React.createContext(void 0);
@@ -8,6 +8,10 @@ import {
8
8
  import { Menu, MenuContext } from './Menu.js';
9
9
  import { ListItem } from '../List/ListItem.js';
10
10
  import cx from 'classnames';
11
+ import {
12
+ DropdownMenuCloseOnClickContext,
13
+ DropdownMenuContext,
14
+ } from '../DropdownMenu/DropdownMenu.js';
11
15
  export const MenuItem = React.forwardRef((props, forwardedRef) => {
12
16
  let {
13
17
  className,
@@ -32,6 +36,10 @@ export const MenuItem = React.forwardRef((props, forwardedRef) => {
32
36
  'Passing a non-empty submenuItems array and onClick to MenuItem at the same time is not supported. This is because when a non empty submenuItems array is passed, clicking the MenuItem toggles the submenu visibility.',
33
37
  );
34
38
  let parentMenu = React.useContext(MenuContext);
39
+ let dropdownMenu = React.useContext(DropdownMenuContext);
40
+ let shouldCloseMenuOnClick = React.useContext(
41
+ DropdownMenuCloseOnClickContext,
42
+ );
35
43
  let menuItemRef = React.useRef(null);
36
44
  let submenuId = useId();
37
45
  let popoverProps = React.useMemo(
@@ -50,6 +58,7 @@ export const MenuItem = React.forwardRef((props, forwardedRef) => {
50
58
  );
51
59
  let onClick = () => {
52
60
  if (disabled) return;
61
+ if (shouldCloseMenuOnClick) dropdownMenu?.close();
53
62
  onClickProp?.(value);
54
63
  };
55
64
  let handlers = {
@@ -70,7 +70,7 @@ let TabsWrapper = React.forwardRef((props, ref) => {
70
70
  TabsWrapper.displayName = 'Tabs.Wrapper';
71
71
  let TabList = React.forwardRef((props, ref) => {
72
72
  let { className, children, ...rest } = props;
73
- let { type, hasSublabel, color } = useSafeContext(TabsContext);
73
+ let { type, hasSublabel, color, orientation } = useSafeContext(TabsContext);
74
74
  let isClient = useIsClient();
75
75
  let tablistRef = React.useRef(null);
76
76
  let [tablistSizeRef, tabsWidth] = useContainerWidth('default' !== type);
@@ -94,6 +94,7 @@ let TabList = React.forwardRef((props, ref) => {
94
94
  },
95
95
  className,
96
96
  ),
97
+ 'data-iui-orientation': orientation,
97
98
  role: 'tablist',
98
99
  ref: refs,
99
100
  ...rest,
@@ -140,10 +141,12 @@ let Tab = React.forwardRef((props, forwardedRef) => {
140
141
  let updateStripe = () => {
141
142
  let currentTabRect = tabRef.current?.getBoundingClientRect();
142
143
  let tabslistRect = tablistRef.current?.getBoundingClientRect();
144
+ let currentTabLeftIncludingScroll =
145
+ (currentTabRect?.x ?? 0) + (tablistRef.current?.scrollLeft ?? 0);
143
146
  let tabsStripePosition =
144
147
  null != currentTabRect && null != tabslistRect
145
148
  ? {
146
- horizontal: currentTabRect.x - tabslistRect.x,
149
+ horizontal: currentTabLeftIncludingScroll - tabslistRect.x,
147
150
  vertical: currentTabRect.y - tabslistRect.y,
148
151
  }
149
152
  : {
@@ -10,7 +10,10 @@ import {
10
10
  polymorphic,
11
11
  Box,
12
12
  } from '../../utils/index.js';
13
- import { DropdownMenu } from '../DropdownMenu/DropdownMenu.js';
13
+ import {
14
+ DropdownMenu,
15
+ DropdownMenuCloseOnClickContext,
16
+ } from '../DropdownMenu/DropdownMenu.js';
14
17
  import { IconButton } from '../Buttons/IconButton.js';
15
18
  import { ProgressRadial } from '../ProgressIndicators/ProgressRadial.js';
16
19
  import { LinkAction } from '../LinkAction/LinkAction.js';
@@ -189,41 +192,39 @@ let TileMoreOptions = React.forwardRef((props, forwardedRef) => {
189
192
  let { className, children = [], buttonProps, ...rest } = props;
190
193
  let [isMenuVisible, setIsMenuVisible] = React.useState(false);
191
194
  return React.createElement(
192
- Box,
195
+ DropdownMenuCloseOnClickContext.Provider,
193
196
  {
194
- className: cx(
195
- 'iui-tile-more-options',
196
- {
197
- 'iui-visible': isMenuVisible,
198
- },
199
- className,
200
- ),
201
- ref: forwardedRef,
202
- ...rest,
197
+ value: true,
203
198
  },
204
199
  React.createElement(
205
- DropdownMenu,
200
+ Box,
206
201
  {
207
- onVisibleChange: setIsMenuVisible,
208
- menuItems: (close) =>
209
- children?.map((option) =>
210
- React.cloneElement(option, {
211
- onClick: (value) => {
212
- close();
213
- option.props.onClick?.(value);
214
- },
215
- }),
216
- ),
202
+ className: cx(
203
+ 'iui-tile-more-options',
204
+ {
205
+ 'iui-visible': isMenuVisible,
206
+ },
207
+ className,
208
+ ),
209
+ ref: forwardedRef,
210
+ ...rest,
217
211
  },
218
212
  React.createElement(
219
- IconButton,
213
+ DropdownMenu,
220
214
  {
221
- styleType: 'borderless',
222
- size: 'small',
223
- 'aria-label': 'More options',
224
- ...buttonProps,
215
+ onVisibleChange: setIsMenuVisible,
216
+ menuItems: children,
225
217
  },
226
- React.createElement(SvgMore, null),
218
+ React.createElement(
219
+ IconButton,
220
+ {
221
+ styleType: 'borderless',
222
+ size: 'small',
223
+ 'aria-label': 'More options',
224
+ ...buttonProps,
225
+ },
226
+ React.createElement(SvgMore, null),
227
+ ),
227
228
  ),
228
229
  ),
229
230
  );
@@ -211,29 +211,37 @@ let VirtualizedTree = React.forwardRef(
211
211
  ref: useMergedRefs(ref, parentRef),
212
212
  },
213
213
  React.createElement(
214
- ShadowRoot,
214
+ 'div',
215
215
  {
216
- css: virtualizerCss,
216
+ style: {
217
+ display: 'contents',
218
+ },
217
219
  },
218
220
  React.createElement(
219
- 'div',
221
+ ShadowRoot,
220
222
  {
221
- 'data-iui-virtualizer': 'root',
222
- style: {
223
- minBlockSize: virtualizer.getTotalSize(),
224
- },
223
+ css: virtualizerCss,
225
224
  },
226
- React.createElement('slot', null),
227
- ),
228
- ),
229
- React.createElement(
230
- React.Fragment,
231
- null,
232
- virtualizer
233
- .getVirtualItems()
234
- .map((virtualItem) =>
235
- itemRenderer(virtualItem.index, virtualItem, virtualizer),
225
+ React.createElement(
226
+ 'div',
227
+ {
228
+ 'data-iui-virtualizer': 'root',
229
+ style: {
230
+ minBlockSize: virtualizer.getTotalSize(),
231
+ },
232
+ },
233
+ React.createElement('slot', null),
236
234
  ),
235
+ ),
236
+ React.createElement(
237
+ React.Fragment,
238
+ null,
239
+ virtualizer
240
+ .getVirtualItems()
241
+ .map((virtualItem) =>
242
+ itemRenderer(virtualItem.index, virtualItem, virtualizer),
243
+ ),
244
+ ),
237
245
  ),
238
246
  );
239
247
  },
package/DEV-esm/styles.js CHANGED
@@ -1,4 +1,4 @@
1
- const t = '3.17.2';
1
+ const t = '3.17.4';
2
2
  const u = new Proxy(
3
3
  {},
4
4
  {
@@ -371,27 +371,23 @@ const ComboBox = _react.forwardRef((props, forwardedRef) => {
371
371
  disabled: inputProps?.disabled,
372
372
  ...rest,
373
373
  },
374
- _react.createElement(
375
- _react.Fragment,
376
- null,
377
- _react.createElement(_ComboBoxInput.ComboBoxInput, {
378
- value: inputValue,
379
- disabled: inputProps?.disabled,
380
- ...inputProps,
381
- onChange: handleOnInput,
382
- selectTags: isMultipleEnabled(selectedIndexes, multiple)
383
- ? selectedIndexes
384
- ?.map((index) => {
385
- let item = options[index];
386
- return _react.createElement(_SelectTag.SelectTag, {
387
- key: item.label,
388
- label: item.label,
389
- });
390
- })
391
- .filter(Boolean)
392
- : void 0,
393
- }),
394
- ),
374
+ _react.createElement(_ComboBoxInput.ComboBoxInput, {
375
+ value: inputValue,
376
+ disabled: inputProps?.disabled,
377
+ ...inputProps,
378
+ onChange: handleOnInput,
379
+ selectTags: isMultipleEnabled(selectedIndexes, multiple)
380
+ ? selectedIndexes
381
+ ?.map((index) => {
382
+ let item = options[index];
383
+ return _react.createElement(_SelectTag.SelectTag, {
384
+ key: item.label,
385
+ label: item.label,
386
+ });
387
+ })
388
+ .filter(Boolean)
389
+ : void 0,
390
+ }),
395
391
  _react.createElement(_ComboBoxEndIcon.ComboBoxEndIcon, {
396
392
  ...endIconProps,
397
393
  disabled: inputProps?.disabled,
@@ -65,8 +65,12 @@ const VirtualizedComboBoxMenu = (props) => {
65
65
  [filteredOptions, getMenuItem, children, virtualizer.measureElement],
66
66
  );
67
67
  return _react.createElement(
68
- _react.Fragment,
69
- null,
68
+ 'div',
69
+ {
70
+ style: {
71
+ display: 'contents',
72
+ },
73
+ },
70
74
  _react.createElement(
71
75
  _index.ShadowRoot,
72
76
  {
@@ -48,3 +48,13 @@ export type DropdownMenuProps = {
48
48
  * </DropdownMenu>
49
49
  */
50
50
  export declare const DropdownMenu: PolymorphicForwardRefComponent<"div", DropdownMenuProps>;
51
+ export declare const DropdownMenuContext: React.Context<{
52
+ close: () => void;
53
+ } | undefined>;
54
+ /**
55
+ * @private
56
+ * Wraps around a `DropdownMenu`.
57
+ *
58
+ * If `true`, closes the `DropdownMenu` when any descendant `MenuItem` is clicked.
59
+ */
60
+ export declare const DropdownMenuCloseOnClickContext: React.Context<boolean | undefined>;
@@ -2,11 +2,23 @@
2
2
  Object.defineProperty(exports, '__esModule', {
3
3
  value: true,
4
4
  });
5
- Object.defineProperty(exports, 'DropdownMenu', {
6
- enumerable: true,
7
- get: function () {
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name],
10
+ });
11
+ }
12
+ _export(exports, {
13
+ DropdownMenu: function () {
8
14
  return DropdownMenu;
9
15
  },
16
+ DropdownMenuCloseOnClickContext: function () {
17
+ return DropdownMenuCloseOnClickContext;
18
+ },
19
+ DropdownMenuContext: function () {
20
+ return DropdownMenuContext;
21
+ },
10
22
  });
11
23
  const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
12
24
  const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react'));
@@ -41,34 +53,50 @@ const DropdownMenuContent = _react.forwardRef((props, forwardedRef) => {
41
53
  visibleProp,
42
54
  onVisibleChange,
43
55
  );
56
+ let close = _react.useCallback(() => {
57
+ setVisible(false);
58
+ }, [setVisible]);
44
59
  let menuContent = _react.useMemo(() => {
45
- if ('function' == typeof menuItems)
46
- return menuItems(() => setVisible(false));
60
+ if ('function' == typeof menuItems) return menuItems(close);
47
61
  return menuItems;
48
- }, [menuItems, setVisible]);
62
+ }, [close, menuItems]);
63
+ let dropdownMenuContextValue = _react.useMemo(
64
+ () => ({
65
+ close,
66
+ }),
67
+ [close],
68
+ );
49
69
  return _react.createElement(
50
- _Menu.Menu,
70
+ DropdownMenuContext.Provider,
51
71
  {
52
- trigger: children,
53
- onKeyDown: (0, _index.mergeEventHandlers)(props.onKeyDown, (e) => {
54
- if (e.defaultPrevented) return;
55
- if ('Tab' === e.key) setVisible(false);
56
- }),
57
- role: role,
58
- ref: forwardedRef,
59
- portal: portal,
60
- popoverProps: _react.useMemo(
61
- () => ({
62
- placement,
63
- matchWidth,
64
- visible,
65
- onVisibleChange: setVisible,
66
- middleware,
67
- }),
68
- [matchWidth, middleware, placement, setVisible, visible],
69
- ),
70
- ...rest,
72
+ value: dropdownMenuContextValue,
71
73
  },
72
- menuContent,
74
+ _react.createElement(
75
+ _Menu.Menu,
76
+ {
77
+ trigger: children,
78
+ onKeyDown: (0, _index.mergeEventHandlers)(props.onKeyDown, (e) => {
79
+ if (e.defaultPrevented) return;
80
+ if ('Tab' === e.key) setVisible(false);
81
+ }),
82
+ role: role,
83
+ ref: forwardedRef,
84
+ portal: portal,
85
+ popoverProps: _react.useMemo(
86
+ () => ({
87
+ placement,
88
+ matchWidth,
89
+ visible,
90
+ onVisibleChange: setVisible,
91
+ middleware,
92
+ }),
93
+ [matchWidth, middleware, placement, setVisible, visible],
94
+ ),
95
+ ...rest,
96
+ },
97
+ menuContent,
98
+ ),
73
99
  );
74
100
  });
101
+ const DropdownMenuContext = _react.createContext(void 0);
102
+ const DropdownMenuCloseOnClickContext = _react.createContext(void 0);
@@ -28,7 +28,12 @@ type MenuProps = {
28
28
  listNavigation?: Partial<UseListNavigationProps>;
29
29
  };
30
30
  };
31
- } & Pick<PortalProps, 'portal'>;
31
+ /**
32
+ * If not passed, uses the `portal` from its parent `Menu`.
33
+ * @see {@link PortalProps.portal} for docs on the prop.
34
+ */
35
+ portal?: PortalProps['portal'];
36
+ };
32
37
  /**
33
38
  * @private
34
39
  *
@@ -92,4 +97,7 @@ export declare const MenuContext: React.Context<{
92
97
  popoverGetItemProps: PopoverGetItemProps;
93
98
  focusableElements: HTMLElement[];
94
99
  } | undefined>;
100
+ export declare const MenuPortalContext: React.Context<boolean | {
101
+ to: HTMLElement | null | undefined | (() => HTMLElement | null | undefined);
102
+ } | undefined>;
95
103
  export {};
@@ -16,6 +16,9 @@ _export(exports, {
16
16
  MenuContext: function () {
17
17
  return MenuContext;
18
18
  },
19
+ MenuPortalContext: function () {
20
+ return MenuPortalContext;
21
+ },
19
22
  });
20
23
  const _interop_require_default = require('@swc/helpers/_/_interop_require_default');
21
24
  const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
@@ -31,11 +34,13 @@ const Menu = _react.forwardRef((props, ref) => {
31
34
  className,
32
35
  trigger,
33
36
  positionReference,
34
- portal = true,
37
+ portal: portalProp,
35
38
  popoverProps: popoverPropsProp,
36
39
  children,
37
40
  ...rest
38
41
  } = props;
42
+ let menuPortalContext = _react.useContext(MenuPortalContext);
43
+ let portal = portalProp ?? menuPortalContext;
39
44
  let tree = (0, _react1.useFloatingTree)();
40
45
  let nodeId = (0, _react1.useFloatingNodeId)();
41
46
  let parentId = (0, _react1.useFloatingParentNodeId)();
@@ -134,35 +139,39 @@ const Menu = _react.forwardRef((props, ref) => {
134
139
  () => void 0,
135
140
  () => void 0,
136
141
  );
137
- let popoverGetItemProps = ({ focusableItemIndex, userProps }) =>
138
- getItemProps({
139
- ...userProps,
140
- tabIndex:
141
- null != activeIndex &&
142
- activeIndex >= 0 &&
143
- null != focusableItemIndex &&
144
- focusableItemIndex >= 0 &&
145
- activeIndex === focusableItemIndex
146
- ? 0
147
- : -1,
148
- onFocus: (0, _index.mergeEventHandlers)(userProps?.onFocus, () => {
149
- queueMicrotask(() => {
150
- setHasFocusedNodeInSubmenu(true);
151
- });
152
- tree?.events.emit('onNodeFocused', {
153
- nodeId: nodeId,
154
- parentId: parentId,
155
- });
142
+ let popoverGetItemProps = _react.useCallback(
143
+ ({ focusableItemIndex, userProps }) =>
144
+ getItemProps({
145
+ ...userProps,
146
+ tabIndex:
147
+ null != activeIndex &&
148
+ activeIndex >= 0 &&
149
+ null != focusableItemIndex &&
150
+ focusableItemIndex >= 0 &&
151
+ activeIndex === focusableItemIndex
152
+ ? 0
153
+ : -1,
154
+ onFocus: (0, _index.mergeEventHandlers)(userProps?.onFocus, () => {
155
+ queueMicrotask(() => {
156
+ setHasFocusedNodeInSubmenu(true);
157
+ });
158
+ tree?.events.emit('onNodeFocused', {
159
+ nodeId: nodeId,
160
+ parentId: parentId,
161
+ });
162
+ }),
163
+ onMouseEnter: (0, _index.mergeEventHandlers)(
164
+ userProps?.onMouseEnter,
165
+ (event) => {
166
+ if (null != focusableItemIndex && focusableItemIndex >= 0)
167
+ setActiveIndex(focusableItemIndex);
168
+ if (event.target === event.currentTarget)
169
+ event.currentTarget.focus();
170
+ },
171
+ ),
156
172
  }),
157
- onMouseEnter: (0, _index.mergeEventHandlers)(
158
- userProps?.onMouseEnter,
159
- (event) => {
160
- if (null != focusableItemIndex && focusableItemIndex >= 0)
161
- setActiveIndex(focusableItemIndex);
162
- if (event.target === event.currentTarget) event.currentTarget.focus();
163
- },
164
- ),
165
- });
173
+ [activeIndex, getItemProps, nodeId, parentId, tree?.events],
174
+ );
166
175
  let reference = (0, _index.cloneElementWithRef)(trigger, (triggerChild) =>
167
176
  getReferenceProps(
168
177
  popover.getReferenceProps({
@@ -201,28 +210,38 @@ const Menu = _react.forwardRef((props, ref) => {
201
210
  _react.createElement(
202
211
  MenuContext.Provider,
203
212
  {
204
- value: {
205
- popoverGetItemProps,
206
- focusableElements,
207
- },
213
+ value: _react.useMemo(
214
+ () => ({
215
+ popoverGetItemProps,
216
+ focusableElements,
217
+ }),
218
+ [focusableElements, popoverGetItemProps],
219
+ ),
208
220
  },
209
221
  _react.createElement(
210
- _Popover.PopoverOpenContext.Provider,
222
+ MenuPortalContext.Provider,
211
223
  {
212
- value: popover.open,
224
+ value: portal,
213
225
  },
214
- reference,
226
+ _react.createElement(
227
+ _Popover.PopoverOpenContext.Provider,
228
+ {
229
+ value: popover.open,
230
+ },
231
+ reference,
232
+ ),
233
+ null != tree
234
+ ? _react.createElement(
235
+ _react1.FloatingNode,
236
+ {
237
+ id: nodeId,
238
+ },
239
+ floating,
240
+ )
241
+ : floating,
215
242
  ),
216
- null != tree
217
- ? _react.createElement(
218
- _react1.FloatingNode,
219
- {
220
- id: nodeId,
221
- },
222
- floating,
223
- )
224
- : floating,
225
243
  ),
226
244
  );
227
245
  });
228
246
  const MenuContext = _react.createContext(void 0);
247
+ const MenuPortalContext = _react.createContext(void 0);