@semcore/dropdown-menu 4.20.4 → 4.21.0-prerelease.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -1
- package/lib/cjs/DropdownMenu.js +311 -95
- package/lib/cjs/DropdownMenu.js.map +1 -1
- package/lib/cjs/index.d.js.map +1 -1
- package/lib/cjs/style/dropdown-menu.shadow.css +20 -1
- package/lib/cjs/styleScrollArea.js +6 -6
- package/lib/es6/DropdownMenu.js +316 -97
- package/lib/es6/DropdownMenu.js.map +1 -1
- package/lib/es6/index.d.js.map +1 -1
- package/lib/es6/style/dropdown-menu.shadow.css +20 -1
- package/lib/es6/styleScrollArea.js +6 -6
- package/lib/types/index.d.ts +9 -0
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
-
## [4.
|
|
5
|
+
## [4.21.0-prerelease.1] - 2024-02-15
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- Assistive technologies were not announcing the selected item if dropdown contained focusable elements.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- When dropdown menu item has focusable elements inside, pressing tab locks focus inside the item. Closing or navigating inside the dropdown menu unlocks the focus.
|
|
14
|
+
- If dropdown menu poppers placed to the left or right side of trigger, user needs to press `ArrowLeft` or `ArrowRight` to open the popper (`ArrowUp` or `ArrowDown` was opening popper with any placement before the change).
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- `DropdownMenu.Nesting` component to support accessible nested dropdowns.
|
|
19
|
+
|
|
20
|
+
## [4.20.4] - 2024-02-19
|
|
6
21
|
|
|
7
22
|
### Changed
|
|
8
23
|
|
package/lib/cjs/DropdownMenu.js
CHANGED
|
@@ -27,24 +27,27 @@ var _i18nEnhance = _interopRequireDefault(require("@semcore/utils/lib/enhances/i
|
|
|
27
27
|
var _intergalacticDynamicLocales = require("./translations/__intergalactic-dynamic-locales");
|
|
28
28
|
var _useFocusLock = require("@semcore/utils/lib/use/useFocusLock");
|
|
29
29
|
var _styleScrollArea = _interopRequireDefault(require("./styleScrollArea"));
|
|
30
|
-
var
|
|
31
|
-
|
|
30
|
+
var _setFocus = require("@semcore/utils/src/focus-lock/setFocus");
|
|
31
|
+
var _isFocusInside = require("@semcore/utils/src/focus-lock/isFocusInside");
|
|
32
|
+
var _getFocusableIn = require("@semcore/utils/src/focus-lock/getFocusableIn");
|
|
33
|
+
var _excluded = ["className"];
|
|
32
34
|
/*__reshadow-styles__:"./style/dropdown-menu.shadow.css"*/
|
|
33
|
-
var style = ( /*__reshadow_css_start__*/_core.sstyled.insert( /*__inner_css_start__*/".
|
|
34
|
-
"__SDropdownMenuList": "
|
|
35
|
-
"__SDropdownMenuItem": "
|
|
36
|
-
"_highlighted": "
|
|
37
|
-
"_disabled": "
|
|
38
|
-
"_size_l": "
|
|
39
|
-
"_size_m": "
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
35
|
+
var style = ( /*__reshadow_css_start__*/_core.sstyled.insert( /*__inner_css_start__*/".___SDropdownMenuItem_1578a_gg_,.___SDropdownMenuList_1578a_gg_{position:relative;color:var(--intergalactic-text-primary, #191b23)}.___SDropdownMenuList_1578a_gg_{max-height:240px;padding:var(--intergalactic-spacing-1x, 4px)0;min-height:26px;min-width:32px;box-sizing:content-box;z-index:0}.___SDropdownMenuItem_1578a_gg_{display:flex;align-items:center;-webkit-text-decoration:none;text-decoration:none;box-sizing:border-box;cursor:pointer;width:100%;text-align:left;line-height:normal}@media (hover:hover){.___SDropdownMenuItem_1578a_gg_:hover{background-color:var(--intergalactic-dropdown-menu-item-hover, #f4f5f9)}}.___SDropdownMenuItem_1578a_gg_:focus{outline:0}.___SDropdownMenuItem_1578a_gg_.__selected_1578a_gg_{background-color:var(--intergalactic-dropdown-menu-item-selected, rgba(196, 229, 254, 0.7));box-shadow:2px 0 0 0 var(--intergalactic-control-primary-info, #008ff8) inset}@media (hover:hover){.___SDropdownMenuItem_1578a_gg_.__selected_1578a_gg_:hover{background-color:var(--intergalactic-dropdown-menu-item-selected-hover, #c4e5fe)}}.___SDropdownMenuItem_1578a_gg_.__highlighted_1578a_gg_:not(:focus-within){z-index:1;box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5)) inset}.___SDropdownMenuItem_1578a_gg_.__disabled_1578a_gg_{opacity:var(--intergalactic-disabled-opacity, 0.3);cursor:default;pointer-events:none}.___SDropdownMenuItem_1578a_gg_._size_l_1578a_gg_{font-size:var(--intergalactic-fs-300, 16px);line-height:var(--intergalactic-lh-300, 150%);padding:var(--intergalactic-spacing-2x, 8px) var(--intergalactic-spacing-3x, 12px);min-height:40px}.___SDropdownMenuItem_1578a_gg_._size_m_1578a_gg_{font-size:var(--intergalactic-fs-200, 14px);line-height:var(--intergalactic-lh-200, 142%);padding:calc(var(--intergalactic-spacing-1x, 4px) + var(--intergalactic-spacing-05x, 2px)) var(--intergalactic-spacing-2x, 8px);min-height:32px}.___SDropdownMenuItem_1578a_gg_.__notInteractive_1578a_gg_{cursor:default}@media (hover:hover){.___SDropdownMenuItem_1578a_gg_.__notInteractive_1578a_gg_:hover{background:0 0}}.___SDropdownMenuItem_1578a_gg_._variant_hint_1578a_gg_{color:var(--intergalactic-text-secondary, #6c6e79);cursor:default}@media (hover:hover){.___SDropdownMenuItem_1578a_gg_._variant_hint_1578a_gg_:hover{background:0 0}}.___SDropdownMenuItem_1578a_gg_._variant_title_1578a_gg_{font-weight:var(--intergalactic-bold, 700);cursor:default}@media (hover:hover){.___SDropdownMenuItem_1578a_gg_._variant_title_1578a_gg_:hover{background:0 0}}.___SDropdownMenuItem_1578a_gg_.__visible_1578a_gg_{background-color:var(--intergalactic-dropdown-menu-item-hover, #f4f5f9)}.___SDropdownMenuItem_1578a_gg_.__nesting-trigger_1578a_gg_{justify-content:space-between}.___SDropdownMenuItemAddon_1578a_gg_{display:inline-flex;margin-left:var(--intergalactic-spacing-2x, 8px);margin-right:var(--intergalactic-spacing-2x, 8px)}.___SDropdownMenuItemAddon_1578a_gg_:first-child{margin-left:0}.___SDropdownMenuItemAddon_1578a_gg_:last-child{margin-right:0}.___SDropdownMenuNesting_1578a_gg_,.___SDropdownMenuNesting_1578a_gg_._size_l_1578a_gg_,.___SDropdownMenuNesting_1578a_gg_._size_m_1578a_gg_{padding:0}.___SDropdownMenuNesting_1578a_gg_.__highlighted_1578a_gg_{z-index:1;box-shadow:var(--intergalactic-keyboard-focus, 0px 0px 0px 3px rgba(0, 143, 248, 0.5)) inset}" /*__inner_css_end__*/, "1578a_gg_") /*__reshadow_css_end__*/, {
|
|
36
|
+
"__SDropdownMenuList": "___SDropdownMenuList_1578a_gg_",
|
|
37
|
+
"__SDropdownMenuItem": "___SDropdownMenuItem_1578a_gg_",
|
|
38
|
+
"_highlighted": "__highlighted_1578a_gg_",
|
|
39
|
+
"_disabled": "__disabled_1578a_gg_",
|
|
40
|
+
"_size_l": "_size_l_1578a_gg_",
|
|
41
|
+
"_size_m": "_size_m_1578a_gg_",
|
|
42
|
+
"_visible": "__visible_1578a_gg_",
|
|
43
|
+
"_nesting-trigger": "__nesting-trigger_1578a_gg_",
|
|
44
|
+
"__SDropdownMenuNesting": "___SDropdownMenuNesting_1578a_gg_",
|
|
45
|
+
"_selected": "__selected_1578a_gg_",
|
|
46
|
+
"_notInteractive": "__notInteractive_1578a_gg_",
|
|
47
|
+
"_variant_hint": "_variant_hint_1578a_gg_",
|
|
48
|
+
"_variant_title": "_variant_title_1578a_gg_",
|
|
49
|
+
"__SDropdownMenuItemAddon": "___SDropdownMenuItemAddon_1578a_gg_"
|
|
45
50
|
});
|
|
46
|
-
var KEYS = ['ArrowDown', 'ArrowUp', 'Enter', ' '];
|
|
47
|
-
var INTERACTION_TAGS = ['INPUT', 'TEXTAREA', 'BUTTON'];
|
|
48
51
|
var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
49
52
|
(0, _inherits2["default"])(DropdownMenuRoot, _Component);
|
|
50
53
|
var _super = (0, _createSuper2["default"])(DropdownMenuRoot);
|
|
@@ -55,55 +58,194 @@ var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
|
55
58
|
args[_key] = arguments[_key];
|
|
56
59
|
}
|
|
57
60
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
61
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
|
|
62
|
+
focusLockItemIndex: null
|
|
63
|
+
});
|
|
58
64
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "popperRef", /*#__PURE__*/_react["default"].createRef());
|
|
65
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "triggerRef", /*#__PURE__*/_react["default"].createRef());
|
|
59
66
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "itemProps", []);
|
|
67
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "itemRefs", []);
|
|
60
68
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "highlightedItemRef", /*#__PURE__*/_react["default"].createRef());
|
|
69
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "ignoreTriggerKeyboardFocusUntil", 0);
|
|
61
70
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "prevHighlightedIndex", null);
|
|
71
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "focusTrigger", function () {
|
|
72
|
+
var trigger = _this.triggerRef.current;
|
|
73
|
+
if (!trigger) return;
|
|
74
|
+
if ((0, _isFocusInside.isFocusInside)(trigger)) return;
|
|
75
|
+
(0, _setFocus.setFocus)(trigger);
|
|
76
|
+
});
|
|
62
77
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "bindHandlerKeyDown", function (place) {
|
|
63
78
|
return function (e) {
|
|
64
79
|
var amount = e.shiftKey ? 5 : 1;
|
|
65
80
|
var targetTagName = e.target.tagName;
|
|
66
|
-
|
|
81
|
+
var _this$asProps = _this.asProps,
|
|
82
|
+
visible = _this$asProps.visible,
|
|
83
|
+
highlightedIndex = _this$asProps.highlightedIndex,
|
|
84
|
+
placement = _this$asProps.placement;
|
|
85
|
+
if (e.key === ' ' && ['INPUT', 'TEXTAREA', 'BUTTON'].includes(targetTagName)) return;
|
|
67
86
|
if (e.key === 'Enter') {
|
|
68
87
|
if (targetTagName === 'TEXTAREA') return;
|
|
69
88
|
if (place === 'popper' && (targetTagName === 'BUTTON' || targetTagName === 'A')) return;
|
|
70
89
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
90
|
+
if (visible && e.key === 'Tab') {
|
|
91
|
+
var item = highlightedIndex !== null && _this.itemRefs[highlightedIndex];
|
|
92
|
+
if (item && (0, _getFocusableIn.getFocusableIn)(item).length !== 0) {
|
|
93
|
+
_this.setState({
|
|
94
|
+
focusLockItemIndex: highlightedIndex
|
|
95
|
+
});
|
|
96
|
+
} else {
|
|
97
|
+
_this.handlers.highlightedIndex(null);
|
|
98
|
+
}
|
|
75
99
|
return;
|
|
76
100
|
}
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
if (e.key === 'Escape' && _this.state.focusLockItemIndex !== null) {
|
|
102
|
+
_this.setState({
|
|
103
|
+
focusLockItemIndex: null
|
|
104
|
+
});
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
var verticalPlacement = !placement || placement.startsWith('top') || placement.startsWith('bottom');
|
|
108
|
+
if (['ArrowDown', 'ArrowUp'].includes(e.key) && verticalPlacement) {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
_this.handlers.visible(true);
|
|
111
|
+
}
|
|
112
|
+
if (['ArrowLeft', 'ArrowRight'].includes(e.key) && !verticalPlacement) {
|
|
113
|
+
var show = e.key === 'ArrowRight' && placement.startsWith('right') || e.key === 'ArrowLeft' && placement.startsWith('left');
|
|
114
|
+
var hide = e.key === 'ArrowLeft' && placement.startsWith('right') || e.key === 'ArrowRight' && placement.startsWith('left');
|
|
115
|
+
var visibleChanged = visible && hide || !visible && show;
|
|
116
|
+
if (show) {
|
|
117
|
+
_this.handlers.visible(true);
|
|
118
|
+
} else if (hide) {
|
|
119
|
+
_this.handlers.visible(false);
|
|
120
|
+
}
|
|
121
|
+
if (visibleChanged) {
|
|
122
|
+
e.preventDefault();
|
|
123
|
+
e.stopPropagation();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (['ArrowLeft', 'ArrowRight'].includes(e.key)) {
|
|
128
|
+
var _item = highlightedIndex !== null && _this.itemRefs[highlightedIndex];
|
|
129
|
+
var focusable = (0, _getFocusableIn.getFocusableIn)(_item);
|
|
130
|
+
if (focusable.length > 0 && _item) {
|
|
131
|
+
var focusedIndex = focusable.indexOf(document.activeElement);
|
|
132
|
+
if (e.key === 'ArrowRight') {
|
|
133
|
+
if (focusedIndex === -1) {
|
|
134
|
+
_this.setState({
|
|
135
|
+
focusLockItemIndex: highlightedIndex
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
var nextFocused = focusable[focusedIndex + 1];
|
|
139
|
+
if (nextFocused) {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
e.stopPropagation();
|
|
142
|
+
nextFocused.focus();
|
|
143
|
+
}
|
|
144
|
+
} else if (e.key === 'ArrowLeft') {
|
|
145
|
+
if (focusedIndex === 0) {
|
|
146
|
+
_this.setState({
|
|
147
|
+
focusLockItemIndex: null
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
var prevFocused = focusable[focusedIndex - 1];
|
|
151
|
+
if (prevFocused) {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
e.stopPropagation();
|
|
154
|
+
prevFocused.focus();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
81
159
|
switch (e.key) {
|
|
82
160
|
case 'ArrowDown':
|
|
83
161
|
{
|
|
84
|
-
|
|
85
|
-
|
|
162
|
+
if (visible) {
|
|
163
|
+
_this.moveHighlightedIndex(amount, e);
|
|
164
|
+
if ((0, _isFocusInside.isFocusInside)(_this.popperRef.current)) {
|
|
165
|
+
_this.focusTrigger();
|
|
166
|
+
}
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
e.stopPropagation();
|
|
169
|
+
}
|
|
86
170
|
break;
|
|
87
171
|
}
|
|
88
172
|
case 'ArrowUp':
|
|
89
173
|
{
|
|
90
|
-
|
|
91
|
-
|
|
174
|
+
if (visible) {
|
|
175
|
+
_this.moveHighlightedIndex(-amount, e);
|
|
176
|
+
if ((0, _isFocusInside.isFocusInside)(_this.popperRef.current)) {
|
|
177
|
+
_this.focusTrigger();
|
|
178
|
+
}
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
e.stopPropagation();
|
|
181
|
+
}
|
|
92
182
|
break;
|
|
93
183
|
}
|
|
94
184
|
case ' ':
|
|
95
185
|
case 'Enter':
|
|
96
186
|
if (_this.highlightedItemRef.current) {
|
|
187
|
+
e.stopPropagation();
|
|
188
|
+
e.preventDefault();
|
|
97
189
|
_this.highlightedItemRef.current.click();
|
|
98
190
|
} else {
|
|
99
|
-
if (place === 'trigger')
|
|
191
|
+
if (place === 'trigger') {
|
|
192
|
+
_this.handlers.visible(false);
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
}
|
|
100
195
|
}
|
|
101
196
|
break;
|
|
102
197
|
}
|
|
103
198
|
};
|
|
104
199
|
});
|
|
200
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleTriggerKeyboardFocus", function () {
|
|
201
|
+
if (_this.ignoreTriggerKeyboardFocusUntil > Date.now()) return false;
|
|
202
|
+
});
|
|
203
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleNestingClick", function (event) {
|
|
204
|
+
var _focusable$;
|
|
205
|
+
var itemIndex = _this.itemRefs.indexOf(event.currentTarget);
|
|
206
|
+
if (itemIndex === -1) return;
|
|
207
|
+
var focusable = (0, _getFocusableIn.getFocusableIn)(event.currentTarget);
|
|
208
|
+
(_focusable$ = focusable[0]) === null || _focusable$ === void 0 ? void 0 : _focusable$.focus();
|
|
209
|
+
if (focusable[0] && _this.state.focusLockItemIndex === null) {
|
|
210
|
+
_this.setState({
|
|
211
|
+
focusLockItemIndex: null
|
|
212
|
+
});
|
|
213
|
+
event.preventDefault();
|
|
214
|
+
event.stopPropagation();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleNestingKeyDown", function (event) {
|
|
218
|
+
if (event.key === ' ') {
|
|
219
|
+
_this.handleNestingClick(event);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getNestingProps", function () {
|
|
223
|
+
var size = _this.asProps.size;
|
|
224
|
+
return {
|
|
225
|
+
size: size,
|
|
226
|
+
onClick: _this.handleNestingClick,
|
|
227
|
+
onKeyDown: _this.handleNestingKeyDown
|
|
228
|
+
};
|
|
229
|
+
});
|
|
230
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleNestedVisibleChange", function (lastUserInteraction) {
|
|
231
|
+
if (_this.asProps.visible && _this.asProps.highlightedIndex === null && lastUserInteraction === 'keyboard') {
|
|
232
|
+
_this.handlers.highlightedIndex(0);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getNestingTriggerProps", function () {
|
|
236
|
+
var _this$asProps2 = _this.asProps,
|
|
237
|
+
size = _this$asProps2.size,
|
|
238
|
+
visible = _this$asProps2.visible;
|
|
239
|
+
return {
|
|
240
|
+
size: size,
|
|
241
|
+
visible: visible,
|
|
242
|
+
onNestedVisibleChange: _this.handleNestedVisibleChange
|
|
243
|
+
};
|
|
244
|
+
});
|
|
105
245
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "scrollToNode", function (node) {
|
|
106
|
-
|
|
246
|
+
if (node) {
|
|
247
|
+
_this.highlightedItemRef.current = node;
|
|
248
|
+
}
|
|
107
249
|
setTimeout(function () {
|
|
108
250
|
if (node !== null && node !== void 0 && node.scrollIntoView) {
|
|
109
251
|
if (_this.asProps.highlightedIndex !== _this.prevHighlightedIndex) {
|
|
@@ -121,21 +263,26 @@ var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
|
121
263
|
(0, _createClass2["default"])(DropdownMenuRoot, [{
|
|
122
264
|
key: "uncontrolledProps",
|
|
123
265
|
value: function uncontrolledProps() {
|
|
266
|
+
var _this2 = this;
|
|
124
267
|
return {
|
|
125
268
|
highlightedIndex: null,
|
|
126
|
-
visible: null
|
|
269
|
+
visible: [null, function (visible) {
|
|
270
|
+
if (!visible) {
|
|
271
|
+
_this2.ignoreTriggerKeyboardFocusUntil = Date.now() + 100;
|
|
272
|
+
}
|
|
273
|
+
}]
|
|
127
274
|
};
|
|
128
275
|
}
|
|
129
276
|
}, {
|
|
130
277
|
key: "getTriggerProps",
|
|
131
278
|
value: function getTriggerProps() {
|
|
132
|
-
var _this$
|
|
133
|
-
size = _this$
|
|
134
|
-
uid = _this$
|
|
135
|
-
disablePortal = _this$
|
|
136
|
-
visible = _this$
|
|
137
|
-
getI18nText = _this$
|
|
138
|
-
highlightedIndex = _this$
|
|
279
|
+
var _this$asProps3 = this.asProps,
|
|
280
|
+
size = _this$asProps3.size,
|
|
281
|
+
uid = _this$asProps3.uid,
|
|
282
|
+
disablePortal = _this$asProps3.disablePortal,
|
|
283
|
+
visible = _this$asProps3.visible,
|
|
284
|
+
getI18nText = _this$asProps3.getI18nText,
|
|
285
|
+
highlightedIndex = _this$asProps3.highlightedIndex;
|
|
139
286
|
return {
|
|
140
287
|
size: size,
|
|
141
288
|
id: "igc-".concat(uid, "-trigger"),
|
|
@@ -143,15 +290,17 @@ var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
|
143
290
|
focusHint: visible && !disablePortal ? getI18nText('triggerHint') : undefined,
|
|
144
291
|
'aria-expanded': visible ? 'true' : 'false',
|
|
145
292
|
'aria-activedescendant': visible && highlightedIndex !== null ? "igc-".concat(uid, "-option-").concat(highlightedIndex) : undefined,
|
|
146
|
-
onKeyDown: this.bindHandlerKeyDown('trigger')
|
|
293
|
+
onKeyDown: this.bindHandlerKeyDown('trigger'),
|
|
294
|
+
ref: this.triggerRef,
|
|
295
|
+
onKeyboardFocus: this.handleTriggerKeyboardFocus
|
|
147
296
|
};
|
|
148
297
|
}
|
|
149
298
|
}, {
|
|
150
299
|
key: "getListProps",
|
|
151
300
|
value: function getListProps() {
|
|
152
|
-
var _this$
|
|
153
|
-
size = _this$
|
|
154
|
-
uid = _this$
|
|
301
|
+
var _this$asProps4 = this.asProps,
|
|
302
|
+
size = _this$asProps4.size,
|
|
303
|
+
uid = _this$asProps4.uid;
|
|
155
304
|
return {
|
|
156
305
|
size: size,
|
|
157
306
|
uid: uid,
|
|
@@ -161,12 +310,12 @@ var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
|
161
310
|
}, {
|
|
162
311
|
key: "getPopperProps",
|
|
163
312
|
value: function getPopperProps() {
|
|
164
|
-
var _this$
|
|
165
|
-
uid = _this$
|
|
166
|
-
disablePortal = _this$
|
|
167
|
-
ignorePortalsStacking = _this$
|
|
168
|
-
interaction = _this$
|
|
169
|
-
highlightedIndex = _this$
|
|
313
|
+
var _this$asProps5 = this.asProps,
|
|
314
|
+
uid = _this$asProps5.uid,
|
|
315
|
+
disablePortal = _this$asProps5.disablePortal,
|
|
316
|
+
ignorePortalsStacking = _this$asProps5.ignorePortalsStacking,
|
|
317
|
+
interaction = _this$asProps5.interaction,
|
|
318
|
+
highlightedIndex = _this$asProps5.highlightedIndex;
|
|
170
319
|
return {
|
|
171
320
|
ref: this.popperRef,
|
|
172
321
|
tabIndex: 0,
|
|
@@ -181,21 +330,29 @@ var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
|
181
330
|
}, {
|
|
182
331
|
key: "getItemProps",
|
|
183
332
|
value: function getItemProps(props, index) {
|
|
184
|
-
var
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
333
|
+
var _this3 = this;
|
|
334
|
+
var _this$asProps6 = this.asProps,
|
|
335
|
+
size = _this$asProps6.size,
|
|
336
|
+
highlightedIndex = _this$asProps6.highlightedIndex,
|
|
337
|
+
uid = _this$asProps6.uid;
|
|
188
338
|
var highlighted = index === highlightedIndex;
|
|
189
|
-
var
|
|
339
|
+
var ref = this.itemRefs[index];
|
|
190
340
|
this.itemProps[index] = props;
|
|
191
341
|
if (highlighted) {
|
|
192
|
-
|
|
342
|
+
ref = function ref(node) {
|
|
343
|
+
_this3.itemRefs[index] = node;
|
|
344
|
+
_this3.scrollToNode(node);
|
|
345
|
+
};
|
|
193
346
|
}
|
|
194
|
-
return
|
|
347
|
+
return {
|
|
195
348
|
id: "igc-".concat(uid, "-option-").concat(index),
|
|
196
349
|
size: size,
|
|
197
|
-
highlighted: highlighted
|
|
198
|
-
|
|
350
|
+
highlighted: highlighted,
|
|
351
|
+
focusLock: this.state.focusLockItemIndex === index,
|
|
352
|
+
triggerRef: this.triggerRef,
|
|
353
|
+
ref: ref,
|
|
354
|
+
index: index
|
|
355
|
+
};
|
|
199
356
|
}
|
|
200
357
|
}, {
|
|
201
358
|
key: "getItemHintProps",
|
|
@@ -226,6 +383,8 @@ var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
|
226
383
|
if (highlightedIndex == null) {
|
|
227
384
|
if (selectedIndex !== -1) {
|
|
228
385
|
highlightedIndex = selectedIndex;
|
|
386
|
+
} else if (this.highlightedItemRef.current) {
|
|
387
|
+
highlightedIndex = this.prevHighlightedIndex;
|
|
229
388
|
} else {
|
|
230
389
|
highlightedIndex = amount < 0 ? 0 : itemsLastIndex;
|
|
231
390
|
}
|
|
@@ -245,22 +404,25 @@ var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
|
245
404
|
}, {
|
|
246
405
|
key: "componentDidUpdate",
|
|
247
406
|
value: function componentDidUpdate() {
|
|
248
|
-
var
|
|
249
|
-
if (!visible) {
|
|
407
|
+
var _this4 = this;
|
|
408
|
+
if (!this.asProps.visible) {
|
|
250
409
|
this.handlers.highlightedIndex(null);
|
|
251
410
|
}
|
|
411
|
+
if ((this.state.focusLockItemIndex !== this.asProps.highlightedIndex || !this.asProps.visible) && this.state.focusLockItemIndex !== null) {
|
|
412
|
+
setTimeout(function () {
|
|
413
|
+
_this4.setState({
|
|
414
|
+
focusLockItemIndex: null
|
|
415
|
+
});
|
|
416
|
+
}, 0);
|
|
417
|
+
}
|
|
252
418
|
}
|
|
253
419
|
}, {
|
|
254
420
|
key: "render",
|
|
255
421
|
value: function render() {
|
|
256
422
|
var _ref = this.asProps;
|
|
257
|
-
var
|
|
258
|
-
Children = _this$asProps5.Children,
|
|
259
|
-
interaction = _this$asProps5.interaction,
|
|
260
|
-
dataUiName = _this$asProps5['data-ui-name'];
|
|
261
|
-
var props = {};
|
|
423
|
+
var Children = this.asProps.Children;
|
|
262
424
|
this.itemProps = [];
|
|
263
|
-
return /*#__PURE__*/_react["default"].createElement(_dropdown["default"], (0, _core.assignProps)(
|
|
425
|
+
return /*#__PURE__*/_react["default"].createElement(_dropdown["default"], (0, _core.assignProps)({}, _ref), /*#__PURE__*/_react["default"].createElement(Children, null));
|
|
264
426
|
}
|
|
265
427
|
}]);
|
|
266
428
|
return DropdownMenuRoot;
|
|
@@ -278,10 +440,10 @@ var DropdownMenuRoot = /*#__PURE__*/function (_Component) {
|
|
|
278
440
|
});
|
|
279
441
|
function List(props) {
|
|
280
442
|
var _ref2 = arguments[0],
|
|
281
|
-
|
|
443
|
+
_ref10;
|
|
282
444
|
var SDropdownMenuList = _scrollArea["default"];
|
|
283
445
|
var uid = props.uid;
|
|
284
|
-
return
|
|
446
|
+
return _ref10 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SDropdownMenuList, _ref10.cn("SDropdownMenuList", (0, _objectSpread2["default"])({}, (0, _core.assignProps)({
|
|
285
447
|
"tabIndex": null,
|
|
286
448
|
"role": 'menu',
|
|
287
449
|
"aria-labelledby": "igc-".concat(uid, "-trigger"),
|
|
@@ -309,22 +471,72 @@ function Menu(props) {
|
|
|
309
471
|
};
|
|
310
472
|
return /*#__PURE__*/_react["default"].createElement(DropdownMenu.Popper, popperProps, /*#__PURE__*/_react["default"].createElement(DropdownMenu.List, (0, _core.assignProps)({}, _ref3)));
|
|
311
473
|
}
|
|
312
|
-
function Item(
|
|
313
|
-
var
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
474
|
+
function Item(_ref16) {
|
|
475
|
+
var _ref4 = arguments[0],
|
|
476
|
+
_ref11;
|
|
477
|
+
var styles = _ref16.styles,
|
|
478
|
+
label = _ref16.label,
|
|
479
|
+
triggerRef = _ref16.triggerRef,
|
|
480
|
+
focusLock = _ref16.focusLock,
|
|
481
|
+
disabled = _ref16.disabled,
|
|
482
|
+
highlighted = _ref16.highlighted;
|
|
483
|
+
var SDropdownMenuItem = _flexBox.Flex;
|
|
484
|
+
var ref = _react["default"].useRef();
|
|
485
|
+
(0, _useFocusLock.useFocusLock)(ref, false, triggerRef, !focusLock || disabled, true);
|
|
486
|
+
return _ref11 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SDropdownMenuItem, _ref11.cn("SDropdownMenuItem", (0, _objectSpread2["default"])({}, (0, _core.assignProps)({
|
|
487
|
+
"ref": ref,
|
|
488
|
+
"role": 'menuitem',
|
|
489
|
+
"tabIndex": -1,
|
|
490
|
+
"id": label,
|
|
491
|
+
"use:highlighted": !disabled && highlighted
|
|
492
|
+
}, _ref4))));
|
|
493
|
+
}
|
|
494
|
+
function Nesting(_ref17) {
|
|
495
|
+
var _ref5 = arguments[0],
|
|
496
|
+
_ref12;
|
|
497
|
+
var styles = _ref17.styles;
|
|
498
|
+
var SDropdownMenuNesting = DropdownMenu.Item;
|
|
499
|
+
return _ref12 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SDropdownMenuNesting, _ref12.cn("SDropdownMenuNesting", (0, _objectSpread2["default"])({}, (0, _core.assignProps)({
|
|
500
|
+
"aria-haspopup": 'true'
|
|
501
|
+
}, _ref5))));
|
|
502
|
+
}
|
|
503
|
+
function NestingTrigger(_ref18) {
|
|
504
|
+
var _ref6 = arguments[0],
|
|
505
|
+
_ref13;
|
|
506
|
+
var styles = _ref18.styles,
|
|
507
|
+
visible = _ref18.visible,
|
|
508
|
+
onNestedVisibleChange = _ref18.onNestedVisibleChange;
|
|
509
|
+
var SDropdownMenuItem = _flexBox.Flex;
|
|
510
|
+
var lastUserInteractionRef = _react["default"].useRef(undefined);
|
|
511
|
+
_react["default"].useEffect(function () {
|
|
512
|
+
onNestedVisibleChange(lastUserInteractionRef.current);
|
|
513
|
+
}, [visible]);
|
|
514
|
+
var handleMouseEvent = _react["default"].useCallback(function () {
|
|
515
|
+
lastUserInteractionRef.current = 'mouse';
|
|
516
|
+
}, []);
|
|
517
|
+
var handleKeyboardEvent = _react["default"].useCallback(function () {
|
|
518
|
+
lastUserInteractionRef.current = 'keyboard';
|
|
519
|
+
}, []);
|
|
520
|
+
_react["default"].useEffect(function () {
|
|
521
|
+
document.addEventListener('mouseover', handleMouseEvent, {
|
|
522
|
+
capture: true
|
|
523
|
+
});
|
|
524
|
+
document.addEventListener('keydown', handleKeyboardEvent, {
|
|
525
|
+
capture: true
|
|
526
|
+
});
|
|
527
|
+
return function () {
|
|
528
|
+
document.removeEventListener('mouseover', handleMouseEvent, {
|
|
529
|
+
capture: true
|
|
530
|
+
});
|
|
531
|
+
document.removeEventListener('keydown', handleKeyboardEvent, {
|
|
532
|
+
capture: true
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
}, []);
|
|
536
|
+
return _ref13 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SDropdownMenuItem, _ref13.cn("SDropdownMenuItem", (0, _objectSpread2["default"])({}, (0, _core.assignProps)({
|
|
537
|
+
"nesting-trigger": true,
|
|
538
|
+
"tabIndex": 0
|
|
539
|
+
}, _ref6))));
|
|
328
540
|
}
|
|
329
541
|
function Addon(props) {
|
|
330
542
|
var _useBox = (0, _flexBox.useBox)(props, props.forwardRef),
|
|
@@ -332,33 +544,33 @@ function Addon(props) {
|
|
|
332
544
|
SDropdownMenuItemAddon = _useBox2[0],
|
|
333
545
|
_useBox2$ = _useBox2[1],
|
|
334
546
|
className = _useBox2$.className,
|
|
335
|
-
other = (0, _objectWithoutProperties2["default"])(_useBox2$,
|
|
547
|
+
other = (0, _objectWithoutProperties2["default"])(_useBox2$, _excluded);
|
|
336
548
|
var styles = (0, _core.sstyled)(props.styles);
|
|
337
549
|
return /*#__PURE__*/_react["default"].createElement(SDropdownMenuItemAddon, (0, _extends2["default"])({
|
|
338
550
|
className: (0, _classnames["default"])(styles.cn('SDropdownMenuItemAddon', props).className, className) || undefined
|
|
339
551
|
}, other));
|
|
340
552
|
}
|
|
341
553
|
function Hint(props) {
|
|
342
|
-
var
|
|
343
|
-
|
|
554
|
+
var _ref7 = arguments[0],
|
|
555
|
+
_ref14;
|
|
344
556
|
var SDropdownMenuItem = _flexBox.Flex;
|
|
345
|
-
return
|
|
557
|
+
return _ref14 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SDropdownMenuItem, _ref14.cn("SDropdownMenuItem", (0, _objectSpread2["default"])({}, (0, _core.assignProps)({
|
|
346
558
|
"variant": 'hint'
|
|
347
|
-
},
|
|
559
|
+
}, _ref7))));
|
|
348
560
|
}
|
|
349
561
|
function Title(props) {
|
|
350
|
-
var
|
|
351
|
-
|
|
562
|
+
var _ref8 = arguments[0],
|
|
563
|
+
_ref15;
|
|
352
564
|
var SDropdownMenuItem = _flexBox.Flex;
|
|
353
|
-
return
|
|
565
|
+
return _ref15 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SDropdownMenuItem, _ref15.cn("SDropdownMenuItem", (0, _objectSpread2["default"])({}, (0, _core.assignProps)({
|
|
354
566
|
"variant": 'title'
|
|
355
|
-
},
|
|
567
|
+
}, _ref8))));
|
|
356
568
|
}
|
|
357
569
|
function Trigger() {
|
|
358
|
-
var
|
|
570
|
+
var _ref9 = arguments[0];
|
|
359
571
|
return /*#__PURE__*/_react["default"].createElement(_dropdown["default"].Trigger, (0, _core.assignProps)({
|
|
360
572
|
"aria-haspopup": 'true'
|
|
361
|
-
},
|
|
573
|
+
}, _ref9));
|
|
362
574
|
}
|
|
363
575
|
var DropdownMenu = (0, _core["default"])(DropdownMenuRoot, {
|
|
364
576
|
Trigger: Trigger,
|
|
@@ -368,6 +580,10 @@ var DropdownMenu = (0, _core["default"])(DropdownMenuRoot, {
|
|
|
368
580
|
Item: [Item, {
|
|
369
581
|
Addon: Addon
|
|
370
582
|
}],
|
|
583
|
+
Nesting: [Nesting, {
|
|
584
|
+
Trigger: NestingTrigger,
|
|
585
|
+
Addon: Addon
|
|
586
|
+
}],
|
|
371
587
|
ItemTitle: Title,
|
|
372
588
|
ItemHint: Hint
|
|
373
589
|
}, {
|