@itwin/itwinui-react 3.17.1 → 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 +17 -0
- package/DEV-cjs/core/Dialog/DialogMain.js +1 -1
- 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-cjs/utils/components/FocusTrap.js +23 -18
- package/DEV-esm/core/Dialog/DialogMain.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/DEV-esm/utils/components/FocusTrap.js +23 -18
- package/cjs/core/Dialog/DialogMain.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/cjs/utils/components/FocusTrap.js +23 -18
- package/esm/core/Dialog/DialogMain.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/esm/utils/components/FocusTrap.js +23 -18
- package/package.json +1 -1
- package/styles.css +11 -11
|
@@ -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
|
);
|
package/DEV-esm/styles.js
CHANGED
|
@@ -1,36 +1,41 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { getTabbableElements } from '../functions/focusable.js';
|
|
3
|
-
import { cloneElementWithRef } from '../functions/react.js';
|
|
4
3
|
export const FocusTrap = (props) => {
|
|
5
4
|
let { children } = props;
|
|
6
|
-
let
|
|
7
|
-
let getFirstLastFocusables = () => {
|
|
8
|
-
let
|
|
5
|
+
let firstFocusTrapRef = React.useRef(null);
|
|
6
|
+
let getFirstLastFocusables = React.useCallback(() => {
|
|
7
|
+
let childrenElement = firstFocusTrapRef.current?.nextElementSibling;
|
|
8
|
+
let elements = getTabbableElements(childrenElement);
|
|
9
9
|
let firstElement = elements[0];
|
|
10
10
|
let lastElement = elements[(elements.length || 1) - 1];
|
|
11
11
|
return [firstElement, lastElement];
|
|
12
|
-
};
|
|
13
|
-
let onFirstFocus = (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
}, []);
|
|
13
|
+
let onFirstFocus = React.useCallback(
|
|
14
|
+
(event) => {
|
|
15
|
+
let [firstElement, lastElement] = getFirstLastFocusables();
|
|
16
|
+
if (event.relatedTarget === firstElement) lastElement?.focus();
|
|
17
|
+
else firstElement?.focus();
|
|
18
|
+
},
|
|
19
|
+
[getFirstLastFocusables],
|
|
20
|
+
);
|
|
21
|
+
let onLastFocus = React.useCallback(
|
|
22
|
+
(event) => {
|
|
23
|
+
let [firstElement, lastElement] = getFirstLastFocusables();
|
|
24
|
+
if (event.relatedTarget === lastElement) firstElement?.focus();
|
|
25
|
+
else lastElement?.focus();
|
|
26
|
+
},
|
|
27
|
+
[getFirstLastFocusables],
|
|
28
|
+
);
|
|
23
29
|
return React.createElement(
|
|
24
30
|
React.Fragment,
|
|
25
31
|
null,
|
|
26
32
|
React.createElement('div', {
|
|
33
|
+
ref: firstFocusTrapRef,
|
|
27
34
|
tabIndex: 0,
|
|
28
35
|
onFocus: onFirstFocus,
|
|
29
36
|
'aria-hidden': true,
|
|
30
37
|
}),
|
|
31
|
-
|
|
32
|
-
ref: childRef,
|
|
33
|
-
})),
|
|
38
|
+
children,
|
|
34
39
|
React.createElement('div', {
|
|
35
40
|
tabIndex: 0,
|
|
36
41
|
onFocus: onLastFocus,
|
|
@@ -107,7 +107,7 @@ const DialogMain = _react.forwardRef((props, ref) => {
|
|
|
107
107
|
dialogRef.current?.focus({
|
|
108
108
|
preventScroll: true,
|
|
109
109
|
});
|
|
110
|
-
}, [
|
|
110
|
+
}, [setFocus]);
|
|
111
111
|
let beforeClose = _react.useCallback(() => {
|
|
112
112
|
if (
|
|
113
113
|
dialogRef.current?.contains(
|
|
@@ -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
|
-
|
|
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'));
|
|
@@ -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
|
-
}, [
|
|
62
|
+
}, [close, menuItems]);
|
|
63
|
+
let dropdownMenuContextValue = _react.useMemo(
|
|
64
|
+
() => ({
|
|
65
|
+
close,
|
|
66
|
+
}),
|
|
67
|
+
[close],
|
|
68
|
+
);
|
|
49
69
|
return _react.createElement(
|
|
50
|
-
|
|
70
|
+
DropdownMenuContext.Provider,
|
|
51
71
|
{
|
|
52
|
-
|
|
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
|
-
|
|
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);
|
package/cjs/core/Menu/Menu.d.ts
CHANGED
|
@@ -28,7 +28,12 @@ type MenuProps = {
|
|
|
28
28
|
listNavigation?: Partial<UseListNavigationProps>;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
|
|
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 {};
|
package/cjs/core/Menu/Menu.js
CHANGED
|
@@ -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,
|
|
@@ -37,6 +38,10 @@ const MenuItem = _react.forwardRef((props, forwardedRef) => {
|
|
|
37
38
|
} = props;
|
|
38
39
|
let logWarning = (0, _index.useWarningLogger)();
|
|
39
40
|
let parentMenu = _react.useContext(_Menu.MenuContext);
|
|
41
|
+
let dropdownMenu = _react.useContext(_DropdownMenu.DropdownMenuContext);
|
|
42
|
+
let shouldCloseMenuOnClick = _react.useContext(
|
|
43
|
+
_DropdownMenu.DropdownMenuCloseOnClickContext,
|
|
44
|
+
);
|
|
40
45
|
let menuItemRef = _react.useRef(null);
|
|
41
46
|
let submenuId = (0, _index.useId)();
|
|
42
47
|
let popoverProps = _react.useMemo(
|
|
@@ -55,6 +60,7 @@ const MenuItem = _react.forwardRef((props, forwardedRef) => {
|
|
|
55
60
|
);
|
|
56
61
|
let onClick = () => {
|
|
57
62
|
if (disabled) return;
|
|
63
|
+
if (shouldCloseMenuOnClick) dropdownMenu?.close();
|
|
58
64
|
onClickProp?.(value);
|
|
59
65
|
};
|
|
60
66
|
let handlers = {
|
package/cjs/core/Tile/Tile.js
CHANGED
|
@@ -196,41 +196,39 @@ const TileMoreOptions = _react.forwardRef((props, forwardedRef) => {
|
|
|
196
196
|
let { className, children = [], buttonProps, ...rest } = props;
|
|
197
197
|
let [isMenuVisible, setIsMenuVisible] = _react.useState(false);
|
|
198
198
|
return _react.createElement(
|
|
199
|
-
|
|
199
|
+
_DropdownMenu.DropdownMenuCloseOnClickContext.Provider,
|
|
200
200
|
{
|
|
201
|
-
|
|
202
|
-
'iui-tile-more-options',
|
|
203
|
-
{
|
|
204
|
-
'iui-visible': isMenuVisible,
|
|
205
|
-
},
|
|
206
|
-
className,
|
|
207
|
-
),
|
|
208
|
-
ref: forwardedRef,
|
|
209
|
-
...rest,
|
|
201
|
+
value: true,
|
|
210
202
|
},
|
|
211
203
|
_react.createElement(
|
|
212
|
-
|
|
204
|
+
_index.Box,
|
|
213
205
|
{
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
),
|
|
206
|
+
className: (0, _classnames.default)(
|
|
207
|
+
'iui-tile-more-options',
|
|
208
|
+
{
|
|
209
|
+
'iui-visible': isMenuVisible,
|
|
210
|
+
},
|
|
211
|
+
className,
|
|
212
|
+
),
|
|
213
|
+
ref: forwardedRef,
|
|
214
|
+
...rest,
|
|
224
215
|
},
|
|
225
216
|
_react.createElement(
|
|
226
|
-
|
|
217
|
+
_DropdownMenu.DropdownMenu,
|
|
227
218
|
{
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
'aria-label': 'More options',
|
|
231
|
-
...buttonProps,
|
|
219
|
+
onVisibleChange: setIsMenuVisible,
|
|
220
|
+
menuItems: children,
|
|
232
221
|
},
|
|
233
|
-
_react.createElement(
|
|
222
|
+
_react.createElement(
|
|
223
|
+
_IconButton.IconButton,
|
|
224
|
+
{
|
|
225
|
+
styleType: 'borderless',
|
|
226
|
+
size: 'small',
|
|
227
|
+
'aria-label': 'More options',
|
|
228
|
+
...buttonProps,
|
|
229
|
+
},
|
|
230
|
+
_react.createElement(_index.SvgMore, null),
|
|
231
|
+
),
|
|
234
232
|
),
|
|
235
233
|
),
|
|
236
234
|
);
|
package/cjs/styles.js
CHANGED
|
@@ -11,37 +11,42 @@ Object.defineProperty(exports, 'FocusTrap', {
|
|
|
11
11
|
const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
|
|
12
12
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require('react'));
|
|
13
13
|
const _focusable = require('../functions/focusable.js');
|
|
14
|
-
const _react1 = require('../functions/react.js');
|
|
15
14
|
const FocusTrap = (props) => {
|
|
16
15
|
let { children } = props;
|
|
17
|
-
let
|
|
18
|
-
let getFirstLastFocusables = () => {
|
|
19
|
-
let
|
|
16
|
+
let firstFocusTrapRef = _react.useRef(null);
|
|
17
|
+
let getFirstLastFocusables = _react.useCallback(() => {
|
|
18
|
+
let childrenElement = firstFocusTrapRef.current?.nextElementSibling;
|
|
19
|
+
let elements = (0, _focusable.getTabbableElements)(childrenElement);
|
|
20
20
|
let firstElement = elements[0];
|
|
21
21
|
let lastElement = elements[(elements.length || 1) - 1];
|
|
22
22
|
return [firstElement, lastElement];
|
|
23
|
-
};
|
|
24
|
-
let onFirstFocus = (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
}, []);
|
|
24
|
+
let onFirstFocus = _react.useCallback(
|
|
25
|
+
(event) => {
|
|
26
|
+
let [firstElement, lastElement] = getFirstLastFocusables();
|
|
27
|
+
if (event.relatedTarget === firstElement) lastElement?.focus();
|
|
28
|
+
else firstElement?.focus();
|
|
29
|
+
},
|
|
30
|
+
[getFirstLastFocusables],
|
|
31
|
+
);
|
|
32
|
+
let onLastFocus = _react.useCallback(
|
|
33
|
+
(event) => {
|
|
34
|
+
let [firstElement, lastElement] = getFirstLastFocusables();
|
|
35
|
+
if (event.relatedTarget === lastElement) firstElement?.focus();
|
|
36
|
+
else lastElement?.focus();
|
|
37
|
+
},
|
|
38
|
+
[getFirstLastFocusables],
|
|
39
|
+
);
|
|
34
40
|
return _react.createElement(
|
|
35
41
|
_react.Fragment,
|
|
36
42
|
null,
|
|
37
43
|
_react.createElement('div', {
|
|
44
|
+
ref: firstFocusTrapRef,
|
|
38
45
|
tabIndex: 0,
|
|
39
46
|
onFocus: onFirstFocus,
|
|
40
47
|
'aria-hidden': true,
|
|
41
48
|
}),
|
|
42
|
-
|
|
43
|
-
ref: childRef,
|
|
44
|
-
})),
|
|
49
|
+
children,
|
|
45
50
|
_react.createElement('div', {
|
|
46
51
|
tabIndex: 0,
|
|
47
52
|
onFocus: onLastFocus,
|
|
@@ -101,7 +101,7 @@ export const DialogMain = React.forwardRef((props, ref) => {
|
|
|
101
101
|
dialogRef.current?.focus({
|
|
102
102
|
preventScroll: true,
|
|
103
103
|
});
|
|
104
|
-
}, [
|
|
104
|
+
}, [setFocus]);
|
|
105
105
|
let beforeClose = React.useCallback(() => {
|
|
106
106
|
if (
|
|
107
107
|
dialogRef.current?.contains(
|
|
@@ -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>;
|