@instructure/ui-menu 8.33.1 → 8.33.2
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 +4 -0
- package/es/Menu/MenuItem/MenuItemLocator.js +2 -1
- package/es/Menu/MenuItem/index.js +12 -53
- package/es/Menu/MenuItem/locator.js +1 -0
- package/es/Menu/MenuItem/props.js +1 -0
- package/es/Menu/MenuItem/styles.js +1 -2
- package/es/Menu/MenuItem/theme.js +5 -5
- package/es/Menu/MenuItemGroup/MenuItemGroupLocator.js +2 -1
- package/es/Menu/MenuItemGroup/index.js +6 -29
- package/es/Menu/MenuItemGroup/props.js +1 -0
- package/es/Menu/MenuItemGroup/styles.js +0 -1
- package/es/Menu/MenuItemGroup/theme.js +5 -5
- package/es/Menu/MenuItemSeparator/index.js +0 -10
- package/es/Menu/MenuItemSeparator/props.js +2 -0
- package/es/Menu/MenuItemSeparator/styles.js +0 -1
- package/es/Menu/MenuItemSeparator/theme.js +4 -4
- package/es/Menu/MenuLocator.js +12 -9
- package/es/Menu/index.js +26 -85
- package/es/Menu/locator.js +1 -0
- package/es/Menu/props.js +1 -0
- package/es/Menu/styles.js +0 -1
- package/es/Menu/theme.js +4 -4
- package/es/MenuContext.js +1 -1
- package/lib/Menu/MenuItem/MenuItemLocator.js +1 -3
- package/lib/Menu/MenuItem/index.js +12 -70
- package/lib/Menu/MenuItem/locator.js +0 -2
- package/lib/Menu/MenuItem/props.js +1 -4
- package/lib/Menu/MenuItem/styles.js +1 -3
- package/lib/Menu/MenuItem/theme.js +5 -6
- package/lib/Menu/MenuItemGroup/MenuItemGroupLocator.js +1 -4
- package/lib/Menu/MenuItemGroup/index.js +6 -45
- package/lib/Menu/MenuItemGroup/locator.js +0 -2
- package/lib/Menu/MenuItemGroup/props.js +1 -7
- package/lib/Menu/MenuItemGroup/styles.js +0 -2
- package/lib/Menu/MenuItemGroup/theme.js +5 -6
- package/lib/Menu/MenuItemSeparator/index.js +0 -18
- package/lib/Menu/MenuItemSeparator/props.js +2 -1
- package/lib/Menu/MenuItemSeparator/styles.js +0 -2
- package/lib/Menu/MenuItemSeparator/theme.js +4 -5
- package/lib/Menu/MenuLocator.js +11 -14
- package/lib/Menu/index.js +26 -103
- package/lib/Menu/locator.js +0 -2
- package/lib/Menu/props.js +1 -6
- package/lib/Menu/styles.js +0 -2
- package/lib/Menu/theme.js +4 -5
- package/lib/MenuContext.js +0 -2
- package/lib/index.js +0 -1
- package/package.json +19 -19
- package/tsconfig.build.tsbuildinfo +1 -1
package/es/Menu/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var _dec, _dec2, _dec3, _class, _class2;
|
|
2
|
-
|
|
3
2
|
/*
|
|
4
3
|
* The MIT License (MIT)
|
|
5
4
|
*
|
|
@@ -23,7 +22,6 @@ var _dec, _dec2, _dec3, _class, _class2;
|
|
|
23
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
23
|
* SOFTWARE.
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
25
|
/** @jsx jsx */
|
|
28
26
|
import React, { Children, Component } from 'react';
|
|
29
27
|
import keycode from 'keycode';
|
|
@@ -40,7 +38,6 @@ import { withStyle, jsx } from '@instructure/emotion';
|
|
|
40
38
|
import generateStyle from './styles';
|
|
41
39
|
import generateComponentTheme from './theme';
|
|
42
40
|
import { propTypes, allowedProps } from './props';
|
|
43
|
-
|
|
44
41
|
/**
|
|
45
42
|
---
|
|
46
43
|
category: components
|
|
@@ -62,67 +59,55 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
62
59
|
this._activeSubMenu = void 0;
|
|
63
60
|
this._id = void 0;
|
|
64
61
|
this.ref = null;
|
|
65
|
-
|
|
66
62
|
this.handleRef = el => {
|
|
67
63
|
const menuRef = this.props.menuRef;
|
|
68
64
|
this._menu = el;
|
|
69
|
-
|
|
70
65
|
if (typeof menuRef === 'function') {
|
|
71
66
|
menuRef(el);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
}
|
|
68
|
+
// If there is no trigger `<ul>` is the ref, otherwise the trigger
|
|
75
69
|
if (!this.props.trigger) {
|
|
76
70
|
this.ref = el;
|
|
77
71
|
}
|
|
78
72
|
};
|
|
79
|
-
|
|
80
73
|
this.registerMenuItem = item => {
|
|
81
74
|
this._menuItems.push(item);
|
|
82
75
|
};
|
|
83
|
-
|
|
84
76
|
this.removeMenuItem = item => {
|
|
85
77
|
const index = this.getMenuItemIndex(item);
|
|
86
78
|
error(index >= 0, '[Menu] Could not find registered menu item.');
|
|
87
|
-
|
|
88
79
|
if (index >= 0) {
|
|
89
80
|
this._menuItems.splice(index, 1);
|
|
90
81
|
}
|
|
91
82
|
};
|
|
92
|
-
|
|
93
83
|
this.getMenuItemIndex = item => {
|
|
94
84
|
return this._menuItems.findIndex(i => i === item);
|
|
95
85
|
};
|
|
96
|
-
|
|
97
86
|
this.handleTriggerKeyDown = event => {
|
|
98
87
|
if (this.props.type === 'flyout' && event.keyCode === keycode.codes.right) {
|
|
99
88
|
event.persist();
|
|
100
89
|
this.show(event);
|
|
101
90
|
}
|
|
102
91
|
};
|
|
103
|
-
|
|
104
92
|
this.handleTriggerMouseOver = event => {
|
|
105
93
|
if (this.props.type === 'flyout') {
|
|
106
94
|
this.show(event);
|
|
107
95
|
}
|
|
108
96
|
};
|
|
109
|
-
|
|
110
97
|
this.handleToggle = shown => {
|
|
111
98
|
if (typeof this.props.onToggle === 'function') {
|
|
112
99
|
this.props.onToggle(shown, this);
|
|
113
100
|
}
|
|
114
101
|
};
|
|
115
|
-
|
|
116
102
|
this.handleMenuKeyDown = event => {
|
|
117
103
|
const key = event && event.keyCode;
|
|
118
104
|
const _keycode$codes = keycode.codes,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
105
|
+
down = _keycode$codes.down,
|
|
106
|
+
up = _keycode$codes.up,
|
|
107
|
+
tab = _keycode$codes.tab,
|
|
108
|
+
left = _keycode$codes.left;
|
|
123
109
|
const pgdn = keycode.codes['page down'];
|
|
124
110
|
const pgup = keycode.codes['page up'];
|
|
125
|
-
|
|
126
111
|
if (key === down || key === pgdn) {
|
|
127
112
|
event.preventDefault();
|
|
128
113
|
event.stopPropagation();
|
|
@@ -137,107 +122,83 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
137
122
|
event.persist();
|
|
138
123
|
this.hide(event);
|
|
139
124
|
}
|
|
140
|
-
|
|
141
125
|
if (typeof this.props.onKeyDown === 'function') {
|
|
142
126
|
this.props.onKeyDown(event);
|
|
143
127
|
}
|
|
144
128
|
};
|
|
145
|
-
|
|
146
129
|
this.handleMenuItemSelect = (event, value, selected, item) => {
|
|
147
130
|
if (this.props.shouldHideOnSelect) {
|
|
148
131
|
this.hide(event);
|
|
149
132
|
}
|
|
150
|
-
|
|
151
133
|
if (typeof this.props.onSelect === 'function') {
|
|
152
134
|
this.props.onSelect(event, value, selected, item);
|
|
153
135
|
}
|
|
154
136
|
};
|
|
155
|
-
|
|
156
137
|
this.handleMenuItemFocus = () => {
|
|
157
138
|
this.setState({
|
|
158
139
|
hasFocus: true
|
|
159
140
|
});
|
|
160
141
|
};
|
|
161
|
-
|
|
162
142
|
this.handleMenuItemBlur = () => {
|
|
163
143
|
this.setState({
|
|
164
144
|
hasFocus: this.focusedIndex >= 0
|
|
165
145
|
});
|
|
166
146
|
};
|
|
167
|
-
|
|
168
147
|
this.handleMenuItemMouseOver = (event, menuItem) => {
|
|
169
148
|
if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
|
|
170
149
|
this.hideActiveSubMenu(event);
|
|
171
150
|
}
|
|
172
151
|
};
|
|
173
|
-
|
|
174
152
|
this.hideActiveSubMenu = event => {
|
|
175
153
|
if (this._activeSubMenu) {
|
|
176
154
|
this._activeSubMenu.hide(event);
|
|
177
|
-
|
|
178
155
|
this._activeSubMenu = null;
|
|
179
156
|
}
|
|
180
157
|
};
|
|
181
|
-
|
|
182
158
|
this.handleSubMenuToggle = (shown, subMenu) => {
|
|
183
159
|
if (shown) {
|
|
184
160
|
this._activeSubMenu = subMenu;
|
|
185
161
|
}
|
|
186
162
|
};
|
|
187
|
-
|
|
188
163
|
this.handleSubMenuDismiss = (event, documentClick) => {
|
|
189
164
|
if (event && event.keyCode === keycode.codes.tab || documentClick) {
|
|
190
165
|
this.hide(event);
|
|
191
166
|
}
|
|
192
167
|
};
|
|
193
|
-
|
|
194
168
|
this.hide = event => {
|
|
195
169
|
if (this._popover) {
|
|
196
170
|
this._popover.hide(event);
|
|
197
171
|
}
|
|
198
172
|
};
|
|
199
|
-
|
|
200
173
|
this.show = event => {
|
|
201
174
|
if (this._popover) {
|
|
202
175
|
this._popover.show(event);
|
|
203
176
|
}
|
|
204
177
|
};
|
|
205
|
-
|
|
206
178
|
this._id = this.props.id || props.deterministicId();
|
|
207
179
|
}
|
|
208
|
-
|
|
209
180
|
componentDidMount() {
|
|
210
181
|
var _this$props$makeStyle, _this$props;
|
|
211
|
-
|
|
212
182
|
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
213
183
|
}
|
|
214
|
-
|
|
215
184
|
componentDidUpdate() {
|
|
216
185
|
var _this$props$makeStyle2, _this$props2;
|
|
217
|
-
|
|
218
186
|
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
219
187
|
}
|
|
220
|
-
|
|
221
188
|
get menuItems() {
|
|
222
189
|
return this._menuItems;
|
|
223
190
|
}
|
|
224
|
-
|
|
225
191
|
focus() {
|
|
226
192
|
if (this.shown) {
|
|
227
193
|
var _this$_menu;
|
|
228
|
-
|
|
229
194
|
error(!!((_this$_menu = this._menu) !== null && _this$_menu !== void 0 && _this$_menu.focus), '[Menu] Could not focus the menu.');
|
|
230
|
-
|
|
231
195
|
this._menu.focus();
|
|
232
196
|
} else {
|
|
233
197
|
var _this$_trigger;
|
|
234
|
-
|
|
235
198
|
error(!!((_this$_trigger = this._trigger) !== null && _this$_trigger !== void 0 && _this$_trigger.focus), '[Menu] Could not focus the trigger.');
|
|
236
|
-
|
|
237
199
|
this._trigger.focus();
|
|
238
200
|
}
|
|
239
201
|
}
|
|
240
|
-
|
|
241
202
|
focused() {
|
|
242
203
|
if (this.shown) {
|
|
243
204
|
return containsActiveElement(this._menu) || this.state.hasFocus;
|
|
@@ -245,52 +206,42 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
245
206
|
return containsActiveElement(this._trigger);
|
|
246
207
|
}
|
|
247
208
|
}
|
|
248
|
-
|
|
249
209
|
get focusedIndex() {
|
|
250
210
|
return this.menuItems.findIndex(item => {
|
|
251
211
|
return item && item.focused === true;
|
|
252
212
|
});
|
|
253
213
|
}
|
|
254
|
-
|
|
255
214
|
moveFocus(step) {
|
|
256
215
|
const count = this.menuItems ? this.menuItems.length : 0;
|
|
257
|
-
|
|
258
216
|
if (count <= 0) {
|
|
259
217
|
return;
|
|
260
218
|
}
|
|
261
|
-
|
|
262
219
|
const current = this.focusedIndex < 0 && step < 0 ? 0 : this.focusedIndex;
|
|
263
220
|
const nextItem = this.menuItems[(current + count + step) % count];
|
|
264
221
|
error(typeof nextItem !== 'undefined' && typeof nextItem.focus !== 'undefined', '[Menu] Could not focus next menu item.');
|
|
265
222
|
nextItem.focus();
|
|
266
223
|
}
|
|
267
|
-
|
|
268
224
|
get shown() {
|
|
269
225
|
return this._popover ? this._popover.shown : true;
|
|
270
226
|
}
|
|
271
|
-
|
|
272
227
|
renderChildren() {
|
|
273
228
|
const _this$props3 = this.props,
|
|
274
|
-
|
|
275
|
-
|
|
229
|
+
children = _this$props3.children,
|
|
230
|
+
disabled = _this$props3.disabled;
|
|
276
231
|
let count = 0;
|
|
277
232
|
return Children.map(children, child => {
|
|
278
233
|
if (!matchComponentTypes(child, ['MenuItemSeparator', 'MenuItem', 'MenuItemGroup', 'Menu'])) {
|
|
279
234
|
return;
|
|
280
235
|
}
|
|
281
|
-
|
|
282
236
|
count += 1;
|
|
283
237
|
const isTabbable = !this.state.hasFocus && count === 1;
|
|
284
|
-
|
|
285
238
|
if (matchComponentTypes(child, ['MenuItemSeparator'])) {
|
|
286
239
|
return jsx("li", {
|
|
287
240
|
role: "none"
|
|
288
241
|
}, child);
|
|
289
242
|
}
|
|
290
|
-
|
|
291
243
|
const menuItemChild = child;
|
|
292
244
|
const controls = menuItemChild.props['aria-controls'] || menuItemChild.props.controls || this.props['aria-controls'] || this.props.controls;
|
|
293
|
-
|
|
294
245
|
if (matchComponentTypes(child, ['MenuItem'])) {
|
|
295
246
|
return jsx("li", {
|
|
296
247
|
role: "none"
|
|
@@ -305,7 +256,6 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
305
256
|
tabIndex: isTabbable ? 0 : -1
|
|
306
257
|
}));
|
|
307
258
|
}
|
|
308
|
-
|
|
309
259
|
if (matchComponentTypes(child, ['MenuItemGroup'])) {
|
|
310
260
|
return jsx("li", {
|
|
311
261
|
role: "none"
|
|
@@ -320,7 +270,6 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
320
270
|
isTabbable
|
|
321
271
|
}));
|
|
322
272
|
}
|
|
323
|
-
|
|
324
273
|
if (matchComponentTypes(child, ['Menu'])) {
|
|
325
274
|
const submenuDisabled = disabled || child.props.disabled;
|
|
326
275
|
return jsx("li", {
|
|
@@ -346,19 +295,16 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
346
295
|
}, child.props.title || child.props.label)
|
|
347
296
|
}));
|
|
348
297
|
}
|
|
349
|
-
|
|
350
298
|
return;
|
|
351
299
|
});
|
|
352
300
|
}
|
|
353
|
-
|
|
354
301
|
renderMenu() {
|
|
355
302
|
var _this$props$styles;
|
|
356
|
-
|
|
357
303
|
const _this$props4 = this.props,
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
304
|
+
disabled = _this$props4.disabled,
|
|
305
|
+
label = _this$props4.label,
|
|
306
|
+
trigger = _this$props4.trigger,
|
|
307
|
+
onKeyUp = _this$props4.onKeyUp;
|
|
362
308
|
const labelledBy = this.props['aria-labelledby'];
|
|
363
309
|
const controls = this.props['aria-controls'];
|
|
364
310
|
return jsx(MenuContext.Provider, {
|
|
@@ -379,33 +325,30 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
379
325
|
ref: this.handleRef
|
|
380
326
|
}, this.renderChildren()));
|
|
381
327
|
}
|
|
382
|
-
|
|
383
328
|
render() {
|
|
384
329
|
const _this$props5 = this.props,
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
330
|
+
show = _this$props5.show,
|
|
331
|
+
defaultShow = _this$props5.defaultShow,
|
|
332
|
+
placement = _this$props5.placement,
|
|
333
|
+
withArrow = _this$props5.withArrow,
|
|
334
|
+
trigger = _this$props5.trigger,
|
|
335
|
+
mountNode = _this$props5.mountNode,
|
|
336
|
+
popoverRef = _this$props5.popoverRef,
|
|
337
|
+
disabled = _this$props5.disabled,
|
|
338
|
+
onDismiss = _this$props5.onDismiss,
|
|
339
|
+
onFocus = _this$props5.onFocus,
|
|
340
|
+
onMouseOver = _this$props5.onMouseOver,
|
|
341
|
+
positionContainerDisplay = _this$props5.positionContainerDisplay,
|
|
342
|
+
offsetX = _this$props5.offsetX,
|
|
343
|
+
offsetY = _this$props5.offsetY;
|
|
399
344
|
return trigger ? jsx(Popover, {
|
|
400
345
|
isShowingContent: show,
|
|
401
346
|
defaultIsShowingContent: defaultShow,
|
|
402
347
|
onHideContent: (event, _ref) => {
|
|
403
348
|
let documentClick = _ref.documentClick;
|
|
404
|
-
|
|
405
349
|
if (typeof onDismiss === 'function') {
|
|
406
350
|
onDismiss(event, documentClick);
|
|
407
351
|
}
|
|
408
|
-
|
|
409
352
|
this.handleToggle(false);
|
|
410
353
|
},
|
|
411
354
|
onShowContent: () => this.handleToggle(true),
|
|
@@ -426,7 +369,6 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
426
369
|
},
|
|
427
370
|
ref: el => {
|
|
428
371
|
this._popover = el;
|
|
429
|
-
|
|
430
372
|
if (typeof popoverRef === 'function') {
|
|
431
373
|
popoverRef(el);
|
|
432
374
|
}
|
|
@@ -443,7 +385,6 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, gener
|
|
|
443
385
|
})
|
|
444
386
|
}, this.renderMenu()) : this.renderMenu();
|
|
445
387
|
}
|
|
446
|
-
|
|
447
388
|
}, _class2.displayName = "Menu", _class2.componentId = 'Menu', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
|
|
448
389
|
label: null,
|
|
449
390
|
disabled: false,
|
package/es/Menu/locator.js
CHANGED
package/es/Menu/props.js
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import PropTypes from 'prop-types';
|
|
25
26
|
import { PositionPropTypes } from '@instructure/ui-position';
|
|
26
27
|
import { controllable, Children as ChildrenPropTypes } from '@instructure/ui-prop-types';
|
package/es/Menu/styles.js
CHANGED
package/es/Menu/theme.js
CHANGED
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
*/
|
|
30
30
|
const generateComponentTheme = theme => {
|
|
31
31
|
const colors = theme.colors,
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
breakpoints = theme.breakpoints,
|
|
33
|
+
borders = theme.borders;
|
|
34
34
|
const componentVariables = {
|
|
35
35
|
minWidth: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.xxSmall,
|
|
36
36
|
maxWidth: breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.xSmall,
|
|
@@ -40,8 +40,8 @@ const generateComponentTheme = theme => {
|
|
|
40
40
|
focusBorderColor: colors === null || colors === void 0 ? void 0 : colors.borderBrand,
|
|
41
41
|
focusBorderRadius: borders === null || borders === void 0 ? void 0 : borders.radiusMedium
|
|
42
42
|
};
|
|
43
|
-
return {
|
|
43
|
+
return {
|
|
44
|
+
...componentVariables
|
|
44
45
|
};
|
|
45
46
|
};
|
|
46
|
-
|
|
47
47
|
export default generateComponentTheme;
|
package/es/MenuContext.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.MenuItemLocator = void 0;
|
|
7
|
-
|
|
8
7
|
var _locator = require("@instructure/ui-test-locator/lib/utils/locator.js");
|
|
9
|
-
|
|
10
8
|
var _index = require("./index");
|
|
11
|
-
|
|
12
9
|
/*
|
|
13
10
|
* The MIT License (MIT)
|
|
14
11
|
*
|
|
@@ -32,6 +29,7 @@ var _index = require("./index");
|
|
|
32
29
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
33
30
|
* SOFTWARE.
|
|
34
31
|
*/
|
|
32
|
+
|
|
35
33
|
// @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
|
|
36
34
|
const MenuItemLocator = (0, _locator.locator)(_index.MenuItem.selector);
|
|
37
35
|
exports.MenuItemLocator = MenuItemLocator;
|
|
@@ -1,48 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
exports.default = exports.MenuItem = void 0;
|
|
11
|
-
|
|
12
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
|
|
14
10
|
var _keycode = _interopRequireDefault(require("keycode"));
|
|
15
|
-
|
|
16
11
|
var _IconCheckSolid2 = require("@instructure/ui-icons/lib/IconCheckSolid.js");
|
|
17
|
-
|
|
18
12
|
var _IconArrowOpenEndSolid = require("@instructure/ui-icons/lib/IconArrowOpenEndSolid.js");
|
|
19
|
-
|
|
20
13
|
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
21
|
-
|
|
22
14
|
var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
|
|
23
|
-
|
|
24
15
|
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
25
|
-
|
|
26
16
|
var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
|
|
27
|
-
|
|
28
17
|
var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
|
|
29
|
-
|
|
30
18
|
var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
|
|
31
|
-
|
|
32
19
|
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
33
|
-
|
|
34
20
|
var _emotion = require("@instructure/emotion");
|
|
35
|
-
|
|
36
21
|
var _MenuContext = require("../../MenuContext");
|
|
37
|
-
|
|
38
22
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
39
|
-
|
|
40
23
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
41
|
-
|
|
42
24
|
var _props = require("./props");
|
|
43
|
-
|
|
44
25
|
var _dec, _dec2, _dec3, _class, _class2, _IconCheckSolid, _IconArrowOpenEndSoli;
|
|
45
|
-
|
|
46
26
|
/**
|
|
47
27
|
---
|
|
48
28
|
parent: Menu
|
|
@@ -55,48 +35,39 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
55
35
|
super(props);
|
|
56
36
|
this.labelId = void 0;
|
|
57
37
|
this.ref = null;
|
|
58
|
-
|
|
59
38
|
this.handleRef = el => {
|
|
60
39
|
this.ref = el;
|
|
61
40
|
};
|
|
62
|
-
|
|
63
41
|
this.handleClick = e => {
|
|
64
42
|
const _this$props = this.props,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
43
|
+
onSelect = _this$props.onSelect,
|
|
44
|
+
onClick = _this$props.onClick,
|
|
45
|
+
disabled = _this$props.disabled,
|
|
46
|
+
value = _this$props.value;
|
|
69
47
|
const selected = !this.selected;
|
|
70
|
-
|
|
71
48
|
if (disabled) {
|
|
72
49
|
e.preventDefault();
|
|
73
50
|
return;
|
|
74
51
|
}
|
|
75
|
-
|
|
76
52
|
if (typeof this.props.selected === 'undefined') {
|
|
77
53
|
this.setState({
|
|
78
54
|
selected
|
|
79
55
|
});
|
|
80
56
|
}
|
|
81
|
-
|
|
82
57
|
if (typeof onSelect === 'function') {
|
|
83
58
|
e.persist();
|
|
84
59
|
onSelect(e, value, selected, this);
|
|
85
60
|
}
|
|
86
|
-
|
|
87
61
|
if (typeof onClick === 'function') {
|
|
88
62
|
onClick(e);
|
|
89
63
|
}
|
|
90
64
|
};
|
|
91
|
-
|
|
92
65
|
this.handleKeyDown = e => {
|
|
93
66
|
const spaceKey = e.keyCode === _keycode.default.codes.space;
|
|
94
67
|
const enterKey = e.keyCode === _keycode.default.codes.enter;
|
|
95
|
-
|
|
96
68
|
if (spaceKey || enterKey) {
|
|
97
69
|
e.preventDefault();
|
|
98
70
|
e.stopPropagation();
|
|
99
|
-
|
|
100
71
|
if (enterKey) {
|
|
101
72
|
// handle space key on keyUp for FF
|
|
102
73
|
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
@@ -104,107 +75,82 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
104
75
|
}
|
|
105
76
|
}
|
|
106
77
|
};
|
|
107
|
-
|
|
108
78
|
this.handleKeyUp = e => {
|
|
109
79
|
const spaceKey = e.keyCode === _keycode.default.codes.space;
|
|
110
80
|
const enterKey = e.keyCode === _keycode.default.codes.enter;
|
|
111
|
-
|
|
112
81
|
if (spaceKey || enterKey) {
|
|
113
82
|
e.preventDefault();
|
|
114
83
|
e.stopPropagation();
|
|
115
|
-
|
|
116
84
|
if (spaceKey) {
|
|
117
85
|
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
118
86
|
refNode.click();
|
|
119
87
|
}
|
|
120
88
|
}
|
|
121
89
|
};
|
|
122
|
-
|
|
123
90
|
this.handleMouseOver = event => {
|
|
124
91
|
this.focus();
|
|
125
|
-
|
|
126
92
|
if (typeof this.props.onMouseOver === 'function') {
|
|
127
93
|
this.props.onMouseOver(event, this);
|
|
128
94
|
}
|
|
129
95
|
};
|
|
130
|
-
|
|
131
96
|
if (typeof props.selected === 'undefined') {
|
|
132
97
|
this.state = {
|
|
133
98
|
selected: !!props.defaultSelected
|
|
134
99
|
};
|
|
135
100
|
}
|
|
136
|
-
|
|
137
101
|
this.labelId = props.deterministicId('MenuItem__label');
|
|
138
102
|
}
|
|
139
|
-
|
|
140
103
|
get _node() {
|
|
141
104
|
return this.ref;
|
|
142
105
|
}
|
|
143
|
-
|
|
144
106
|
componentDidMount() {
|
|
145
107
|
var _this$props$makeStyle, _this$props2;
|
|
146
|
-
|
|
147
108
|
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
|
|
148
109
|
const context = this.context;
|
|
149
|
-
|
|
150
110
|
if (context && context.registerMenuItem) {
|
|
151
111
|
context.registerMenuItem(this);
|
|
152
112
|
}
|
|
153
113
|
}
|
|
154
|
-
|
|
155
114
|
componentDidUpdate() {
|
|
156
115
|
var _this$props$makeStyle2, _this$props3;
|
|
157
|
-
|
|
158
116
|
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
|
|
159
117
|
}
|
|
160
|
-
|
|
161
118
|
componentWillUnmount() {
|
|
162
119
|
const context = this.context;
|
|
163
|
-
|
|
164
120
|
if (context && context.removeMenuItem) {
|
|
165
121
|
context.removeMenuItem(this);
|
|
166
122
|
}
|
|
167
123
|
}
|
|
168
|
-
|
|
169
124
|
get elementType() {
|
|
170
125
|
return (0, _getElementType.getElementType)(MenuItem, this.props);
|
|
171
126
|
}
|
|
172
|
-
|
|
173
127
|
get role() {
|
|
174
128
|
switch (this.props.type) {
|
|
175
129
|
case 'checkbox':
|
|
176
130
|
return 'menuitemcheckbox';
|
|
177
|
-
|
|
178
131
|
case 'radio':
|
|
179
132
|
return 'menuitemradio';
|
|
180
|
-
|
|
181
133
|
case 'flyout':
|
|
182
134
|
return 'button';
|
|
183
|
-
|
|
184
135
|
default:
|
|
185
136
|
return 'menuitem';
|
|
186
137
|
}
|
|
187
138
|
}
|
|
188
|
-
|
|
189
139
|
get selected() {
|
|
190
140
|
return typeof this.props.selected === 'undefined' ? this.state.selected : this.props.selected;
|
|
191
141
|
}
|
|
192
|
-
|
|
193
142
|
get focused() {
|
|
194
143
|
return (0, _isActiveElement.isActiveElement)(this.ref);
|
|
195
144
|
}
|
|
196
|
-
|
|
197
145
|
focus() {
|
|
198
146
|
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
199
147
|
refNode.focus();
|
|
200
148
|
}
|
|
201
|
-
|
|
202
149
|
renderContent() {
|
|
203
150
|
var _this$props$styles, _this$props$styles2, _this$props$styles3;
|
|
204
|
-
|
|
205
151
|
const _this$props4 = this.props,
|
|
206
|
-
|
|
207
|
-
|
|
152
|
+
children = _this$props4.children,
|
|
153
|
+
type = _this$props4.type;
|
|
208
154
|
return (0, _emotion.jsx)("span", null, (type === 'checkbox' || type === 'radio') && (0, _emotion.jsx)("span", {
|
|
209
155
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon
|
|
210
156
|
}, this.selected && (_IconCheckSolid || (_IconCheckSolid = (0, _emotion.jsx)(_IconCheckSolid2.IconCheckSolid, null)))), (0, _emotion.jsx)("span", {
|
|
@@ -214,22 +160,19 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
214
160
|
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.icon
|
|
215
161
|
}, _IconArrowOpenEndSoli || (_IconArrowOpenEndSoli = (0, _emotion.jsx)(_IconArrowOpenEndSolid.IconArrowOpenEndSolid, null))));
|
|
216
162
|
}
|
|
217
|
-
|
|
218
163
|
render() {
|
|
219
164
|
var _this$props$styles4;
|
|
220
|
-
|
|
221
165
|
const _this$props5 = this.props,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
166
|
+
disabled = _this$props5.disabled,
|
|
167
|
+
controls = _this$props5.controls,
|
|
168
|
+
onKeyDown = _this$props5.onKeyDown,
|
|
169
|
+
onKeyUp = _this$props5.onKeyUp,
|
|
170
|
+
type = _this$props5.type,
|
|
171
|
+
href = _this$props5.href;
|
|
228
172
|
const props = (0, _omitProps.omitProps)(this.props, MenuItem.allowedProps);
|
|
229
173
|
const ElementType = this.elementType;
|
|
230
174
|
return (0, _emotion.jsx)(ElementType, Object.assign({
|
|
231
175
|
tabIndex: -1 // note: tabIndex can be overridden by Menu or MenuItemGroup components
|
|
232
|
-
|
|
233
176
|
}, props, {
|
|
234
177
|
href: href,
|
|
235
178
|
role: this.role,
|
|
@@ -245,7 +188,6 @@ let MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 =
|
|
|
245
188
|
onMouseOver: this.handleMouseOver
|
|
246
189
|
}), this.renderContent());
|
|
247
190
|
}
|
|
248
|
-
|
|
249
191
|
}, _class2.displayName = "MenuItem", _class2.componentId = 'Menu.Item', _class2.propTypes = _props.propTypes, _class2.allowedProps = _props.allowedProps, _class2.defaultProps = {
|
|
250
192
|
type: 'button',
|
|
251
193
|
disabled: false
|