@itwin/itwinui-react 3.17.2 → 3.17.3
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 +8 -0
- package/DEV-cjs/core/DropdownMenu/DropdownMenu.js +55 -27
- package/DEV-cjs/core/Menu/Menu.js +64 -45
- package/DEV-cjs/core/Menu/MenuItem.js +6 -0
- package/DEV-cjs/core/Tile/Tile.js +25 -27
- package/DEV-cjs/styles.js +1 -1
- package/DEV-esm/core/DropdownMenu/DropdownMenu.js +40 -24
- package/DEV-esm/core/Menu/Menu.js +57 -42
- package/DEV-esm/core/Menu/MenuItem.js +9 -0
- package/DEV-esm/core/Tile/Tile.js +29 -28
- package/DEV-esm/styles.js +1 -1
- package/cjs/core/DropdownMenu/DropdownMenu.d.ts +10 -0
- package/cjs/core/DropdownMenu/DropdownMenu.js +55 -27
- package/cjs/core/Menu/Menu.d.ts +9 -1
- package/cjs/core/Menu/Menu.js +64 -45
- package/cjs/core/Menu/MenuItem.js +6 -0
- package/cjs/core/Tile/Tile.js +25 -27
- package/cjs/styles.js +1 -1
- package/esm/core/DropdownMenu/DropdownMenu.d.ts +10 -0
- package/esm/core/DropdownMenu/DropdownMenu.js +40 -24
- package/esm/core/Menu/Menu.d.ts +9 -1
- package/esm/core/Menu/Menu.js +57 -42
- package/esm/core/Menu/MenuItem.js +9 -0
- package/esm/core/Tile/Tile.js +29 -28
- package/esm/styles.js +1 -1
- package/package.json +1 -1
- package/styles.css +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.17.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#2452](https://github.com/iTwin/iTwinUI/pull/2452): Fixed bug where nested `MenuItem`s in `Tile.MoreOptions` were not closing when clicked.
|
|
8
|
+
- [#2455](https://github.com/iTwin/iTwinUI/pull/2455): Submenus will now correctly portal to the same place as their parent menu (E.g. `DropdownMenu`, `SplitButton`)
|
|
9
|
+
- [#2457](https://github.com/iTwin/iTwinUI/pull/2457): Fixed bug in `ExpandableBlock` where cursor was `pointer` even when it was disabled.
|
|
10
|
+
|
|
3
11
|
## 3.17.2
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -2,11 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, '__esModule', {
|
|
3
3
|
value: true,
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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'));
|
|
@@ -42,34 +54,50 @@ const DropdownMenuContent = _react.forwardRef((props, forwardedRef) => {
|
|
|
42
54
|
visibleProp,
|
|
43
55
|
onVisibleChange,
|
|
44
56
|
);
|
|
57
|
+
let close = _react.useCallback(() => {
|
|
58
|
+
setVisible(false);
|
|
59
|
+
}, [setVisible]);
|
|
45
60
|
let menuContent = _react.useMemo(() => {
|
|
46
|
-
if ('function' == typeof menuItems)
|
|
47
|
-
return menuItems(() => setVisible(false));
|
|
61
|
+
if ('function' == typeof menuItems) return menuItems(close);
|
|
48
62
|
return menuItems;
|
|
49
|
-
}, [
|
|
63
|
+
}, [close, menuItems]);
|
|
64
|
+
let dropdownMenuContextValue = _react.useMemo(
|
|
65
|
+
() => ({
|
|
66
|
+
close,
|
|
67
|
+
}),
|
|
68
|
+
[close],
|
|
69
|
+
);
|
|
50
70
|
return _react.createElement(
|
|
51
|
-
|
|
71
|
+
DropdownMenuContext.Provider,
|
|
52
72
|
{
|
|
53
|
-
|
|
54
|
-
onKeyDown: (0, _index.mergeEventHandlers)(props.onKeyDown, (e) => {
|
|
55
|
-
if (e.defaultPrevented) return;
|
|
56
|
-
if ('Tab' === e.key) setVisible(false);
|
|
57
|
-
}),
|
|
58
|
-
role: role,
|
|
59
|
-
ref: forwardedRef,
|
|
60
|
-
portal: portal,
|
|
61
|
-
popoverProps: _react.useMemo(
|
|
62
|
-
() => ({
|
|
63
|
-
placement,
|
|
64
|
-
matchWidth,
|
|
65
|
-
visible,
|
|
66
|
-
onVisibleChange: setVisible,
|
|
67
|
-
middleware,
|
|
68
|
-
}),
|
|
69
|
-
[matchWidth, middleware, placement, setVisible, visible],
|
|
70
|
-
),
|
|
71
|
-
...rest,
|
|
73
|
+
value: dropdownMenuContextValue,
|
|
72
74
|
},
|
|
73
|
-
|
|
75
|
+
_react.createElement(
|
|
76
|
+
_Menu.Menu,
|
|
77
|
+
{
|
|
78
|
+
trigger: children,
|
|
79
|
+
onKeyDown: (0, _index.mergeEventHandlers)(props.onKeyDown, (e) => {
|
|
80
|
+
if (e.defaultPrevented) return;
|
|
81
|
+
if ('Tab' === e.key) setVisible(false);
|
|
82
|
+
}),
|
|
83
|
+
role: role,
|
|
84
|
+
ref: forwardedRef,
|
|
85
|
+
portal: portal,
|
|
86
|
+
popoverProps: _react.useMemo(
|
|
87
|
+
() => ({
|
|
88
|
+
placement,
|
|
89
|
+
matchWidth,
|
|
90
|
+
visible,
|
|
91
|
+
onVisibleChange: setVisible,
|
|
92
|
+
middleware,
|
|
93
|
+
}),
|
|
94
|
+
[matchWidth, middleware, placement, setVisible, visible],
|
|
95
|
+
),
|
|
96
|
+
...rest,
|
|
97
|
+
},
|
|
98
|
+
menuContent,
|
|
99
|
+
),
|
|
74
100
|
);
|
|
75
101
|
});
|
|
102
|
+
const DropdownMenuContext = _react.createContext(void 0);
|
|
103
|
+
const DropdownMenuCloseOnClickContext = _react.createContext(void 0);
|
|
@@ -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
|
|
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 = (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
158
|
-
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
213
|
+
value: _react.useMemo(
|
|
214
|
+
() => ({
|
|
215
|
+
popoverGetItemProps,
|
|
216
|
+
focusableElements,
|
|
217
|
+
}),
|
|
218
|
+
[focusableElements, popoverGetItemProps],
|
|
219
|
+
),
|
|
208
220
|
},
|
|
209
221
|
_react.createElement(
|
|
210
|
-
|
|
222
|
+
MenuPortalContext.Provider,
|
|
211
223
|
{
|
|
212
|
-
value:
|
|
224
|
+
value: portal,
|
|
213
225
|
},
|
|
214
|
-
|
|
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);
|
|
@@ -17,6 +17,7 @@ const _ListItem = require('../List/ListItem.js');
|
|
|
17
17
|
const _classnames = /*#__PURE__*/ _interop_require_default._(
|
|
18
18
|
require('classnames'),
|
|
19
19
|
);
|
|
20
|
+
const _DropdownMenu = require('../DropdownMenu/DropdownMenu.js');
|
|
20
21
|
const MenuItem = _react.forwardRef((props, forwardedRef) => {
|
|
21
22
|
let {
|
|
22
23
|
className,
|
|
@@ -41,6 +42,10 @@ const MenuItem = _react.forwardRef((props, forwardedRef) => {
|
|
|
41
42
|
'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.',
|
|
42
43
|
);
|
|
43
44
|
let parentMenu = _react.useContext(_Menu.MenuContext);
|
|
45
|
+
let dropdownMenu = _react.useContext(_DropdownMenu.DropdownMenuContext);
|
|
46
|
+
let shouldCloseMenuOnClick = _react.useContext(
|
|
47
|
+
_DropdownMenu.DropdownMenuCloseOnClickContext,
|
|
48
|
+
);
|
|
44
49
|
let menuItemRef = _react.useRef(null);
|
|
45
50
|
let submenuId = (0, _index.useId)();
|
|
46
51
|
let popoverProps = _react.useMemo(
|
|
@@ -59,6 +64,7 @@ const MenuItem = _react.forwardRef((props, forwardedRef) => {
|
|
|
59
64
|
);
|
|
60
65
|
let onClick = () => {
|
|
61
66
|
if (disabled) return;
|
|
67
|
+
if (shouldCloseMenuOnClick) dropdownMenu?.close();
|
|
62
68
|
onClickProp?.(value);
|
|
63
69
|
};
|
|
64
70
|
let handlers = {
|
|
@@ -211,41 +211,39 @@ const TileMoreOptions = _react.forwardRef((props, forwardedRef) => {
|
|
|
211
211
|
let { className, children = [], buttonProps, ...rest } = props;
|
|
212
212
|
let [isMenuVisible, setIsMenuVisible] = _react.useState(false);
|
|
213
213
|
return _react.createElement(
|
|
214
|
-
|
|
214
|
+
_DropdownMenu.DropdownMenuCloseOnClickContext.Provider,
|
|
215
215
|
{
|
|
216
|
-
|
|
217
|
-
'iui-tile-more-options',
|
|
218
|
-
{
|
|
219
|
-
'iui-visible': isMenuVisible,
|
|
220
|
-
},
|
|
221
|
-
className,
|
|
222
|
-
),
|
|
223
|
-
ref: forwardedRef,
|
|
224
|
-
...rest,
|
|
216
|
+
value: true,
|
|
225
217
|
},
|
|
226
218
|
_react.createElement(
|
|
227
|
-
|
|
219
|
+
_index.Box,
|
|
228
220
|
{
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
),
|
|
221
|
+
className: (0, _classnames.default)(
|
|
222
|
+
'iui-tile-more-options',
|
|
223
|
+
{
|
|
224
|
+
'iui-visible': isMenuVisible,
|
|
225
|
+
},
|
|
226
|
+
className,
|
|
227
|
+
),
|
|
228
|
+
ref: forwardedRef,
|
|
229
|
+
...rest,
|
|
239
230
|
},
|
|
240
231
|
_react.createElement(
|
|
241
|
-
|
|
232
|
+
_DropdownMenu.DropdownMenu,
|
|
242
233
|
{
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
'aria-label': 'More options',
|
|
246
|
-
...buttonProps,
|
|
234
|
+
onVisibleChange: setIsMenuVisible,
|
|
235
|
+
menuItems: children,
|
|
247
236
|
},
|
|
248
|
-
_react.createElement(
|
|
237
|
+
_react.createElement(
|
|
238
|
+
_IconButton.IconButton,
|
|
239
|
+
{
|
|
240
|
+
styleType: 'borderless',
|
|
241
|
+
size: 'small',
|
|
242
|
+
'aria-label': 'More options',
|
|
243
|
+
...buttonProps,
|
|
244
|
+
},
|
|
245
|
+
_react.createElement(_index.SvgMore, null),
|
|
246
|
+
),
|
|
249
247
|
),
|
|
250
248
|
),
|
|
251
249
|
);
|
package/DEV-cjs/styles.js
CHANGED
|
@@ -31,34 +31,50 @@ let DropdownMenuContent = React.forwardRef((props, forwardedRef) => {
|
|
|
31
31
|
visibleProp,
|
|
32
32
|
onVisibleChange,
|
|
33
33
|
);
|
|
34
|
+
let close = React.useCallback(() => {
|
|
35
|
+
setVisible(false);
|
|
36
|
+
}, [setVisible]);
|
|
34
37
|
let menuContent = React.useMemo(() => {
|
|
35
|
-
if ('function' == typeof menuItems)
|
|
36
|
-
return menuItems(() => setVisible(false));
|
|
38
|
+
if ('function' == typeof menuItems) return menuItems(close);
|
|
37
39
|
return menuItems;
|
|
38
|
-
}, [
|
|
40
|
+
}, [close, menuItems]);
|
|
41
|
+
let dropdownMenuContextValue = React.useMemo(
|
|
42
|
+
() => ({
|
|
43
|
+
close,
|
|
44
|
+
}),
|
|
45
|
+
[close],
|
|
46
|
+
);
|
|
39
47
|
return React.createElement(
|
|
40
|
-
|
|
48
|
+
DropdownMenuContext.Provider,
|
|
41
49
|
{
|
|
42
|
-
|
|
43
|
-
onKeyDown: mergeEventHandlers(props.onKeyDown, (e) => {
|
|
44
|
-
if (e.defaultPrevented) return;
|
|
45
|
-
if ('Tab' === e.key) setVisible(false);
|
|
46
|
-
}),
|
|
47
|
-
role: role,
|
|
48
|
-
ref: forwardedRef,
|
|
49
|
-
portal: portal,
|
|
50
|
-
popoverProps: React.useMemo(
|
|
51
|
-
() => ({
|
|
52
|
-
placement,
|
|
53
|
-
matchWidth,
|
|
54
|
-
visible,
|
|
55
|
-
onVisibleChange: setVisible,
|
|
56
|
-
middleware,
|
|
57
|
-
}),
|
|
58
|
-
[matchWidth, middleware, placement, setVisible, visible],
|
|
59
|
-
),
|
|
60
|
-
...rest,
|
|
50
|
+
value: dropdownMenuContextValue,
|
|
61
51
|
},
|
|
62
|
-
|
|
52
|
+
React.createElement(
|
|
53
|
+
Menu,
|
|
54
|
+
{
|
|
55
|
+
trigger: children,
|
|
56
|
+
onKeyDown: mergeEventHandlers(props.onKeyDown, (e) => {
|
|
57
|
+
if (e.defaultPrevented) return;
|
|
58
|
+
if ('Tab' === e.key) setVisible(false);
|
|
59
|
+
}),
|
|
60
|
+
role: role,
|
|
61
|
+
ref: forwardedRef,
|
|
62
|
+
portal: portal,
|
|
63
|
+
popoverProps: React.useMemo(
|
|
64
|
+
() => ({
|
|
65
|
+
placement,
|
|
66
|
+
matchWidth,
|
|
67
|
+
visible,
|
|
68
|
+
onVisibleChange: setVisible,
|
|
69
|
+
middleware,
|
|
70
|
+
}),
|
|
71
|
+
[matchWidth, middleware, placement, setVisible, visible],
|
|
72
|
+
),
|
|
73
|
+
...rest,
|
|
74
|
+
},
|
|
75
|
+
menuContent,
|
|
76
|
+
),
|
|
63
77
|
);
|
|
64
78
|
});
|
|
79
|
+
export const DropdownMenuContext = React.createContext(void 0);
|
|
80
|
+
export const DropdownMenuCloseOnClickContext = React.createContext(void 0);
|
|
@@ -25,11 +25,13 @@ export const Menu = React.forwardRef((props, ref) => {
|
|
|
25
25
|
className,
|
|
26
26
|
trigger,
|
|
27
27
|
positionReference,
|
|
28
|
-
portal
|
|
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 = (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
149
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
197
|
+
value: React.useMemo(
|
|
198
|
+
() => ({
|
|
199
|
+
popoverGetItemProps,
|
|
200
|
+
focusableElements,
|
|
201
|
+
}),
|
|
202
|
+
[focusableElements, popoverGetItemProps],
|
|
203
|
+
),
|
|
196
204
|
},
|
|
197
205
|
React.createElement(
|
|
198
|
-
|
|
206
|
+
MenuPortalContext.Provider,
|
|
199
207
|
{
|
|
200
|
-
value:
|
|
208
|
+
value: portal,
|
|
201
209
|
},
|
|
202
|
-
|
|
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 = {
|
|
@@ -10,7 +10,10 @@ import {
|
|
|
10
10
|
polymorphic,
|
|
11
11
|
Box,
|
|
12
12
|
} from '../../utils/index.js';
|
|
13
|
-
import {
|
|
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
|
-
|
|
195
|
+
DropdownMenuCloseOnClickContext.Provider,
|
|
193
196
|
{
|
|
194
|
-
|
|
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
|
-
|
|
200
|
+
Box,
|
|
206
201
|
{
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
213
|
+
DropdownMenu,
|
|
220
214
|
{
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
'aria-label': 'More options',
|
|
224
|
-
...buttonProps,
|
|
215
|
+
onVisibleChange: setIsMenuVisible,
|
|
216
|
+
menuItems: children,
|
|
225
217
|
},
|
|
226
|
-
React.createElement(
|
|
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
|
);
|