@instructure/ui-menu 11.7.3-snapshot-7 → 11.7.3-snapshot-26

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.
@@ -40,7 +40,7 @@ var _emotion = require("@instructure/emotion");
40
40
  var _styles = _interopRequireDefault(require("./styles"));
41
41
  var _props = require("./props");
42
42
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
43
- var _dec, _dec2, _class, _Menu;
43
+ var _dec, _dec2, _class;
44
44
  /*
45
45
  * The MIT License (MIT)
46
46
  *
@@ -69,158 +69,178 @@ var _dec, _dec2, _class, _Menu;
69
69
  category: components
70
70
  ---
71
71
  **/
72
- let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_Menu = class Menu extends _react.Component {
72
+ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = class Menu extends _react.Component {
73
+ static displayName = "Menu";
74
+ static componentId = 'Menu';
75
+ static allowedProps = _props.allowedProps;
76
+ static defaultProps = {
77
+ label: null,
78
+ disabled: false,
79
+ trigger: null,
80
+ placement: 'bottom center',
81
+ defaultShow: false,
82
+ mountNode: null,
83
+ constrain: 'window',
84
+ shouldHideOnSelect: true,
85
+ shouldFocusTriggerOnClose: true,
86
+ withArrow: true,
87
+ offsetX: 0,
88
+ offsetY: 0
89
+ };
90
+ static Item = _MenuItem.MenuItem;
91
+ static Group = _MenuItemGroup.MenuItemGroup;
92
+ static Separator = _MenuItemSeparator.MenuItemSeparator;
93
+ state = {
94
+ hasFocus: false
95
+ };
96
+ _rootNode = null;
97
+ _menuItems = [];
98
+ _popover = null;
99
+ _trigger = null;
100
+ _menu = null;
101
+ _labelId = this.props.deterministicId('Menu__label');
102
+ _activeSubMenu;
103
+ _id;
104
+ ref = null;
105
+ handleRef = el => {
106
+ const {
107
+ menuRef
108
+ } = this.props;
109
+ this._menu = el;
110
+ if (typeof menuRef === 'function') {
111
+ menuRef(el);
112
+ }
113
+ // If there is no trigger `<ul>` is the ref, otherwise the trigger
114
+ if (!this.props.trigger) {
115
+ this.ref = el;
116
+ }
117
+ };
73
118
  constructor(props) {
74
119
  super(props);
75
- this.state = {
76
- hasFocus: false
77
- };
78
- this._rootNode = null;
79
- this._menuItems = [];
80
- this._popover = null;
81
- this._trigger = null;
82
- this._menu = null;
83
- this._labelId = this.props.deterministicId('Menu__label');
84
- this._activeSubMenu = void 0;
85
- this._id = void 0;
86
- this.ref = null;
87
- this.handleRef = el => {
88
- const menuRef = this.props.menuRef;
89
- this._menu = el;
90
- if (typeof menuRef === 'function') {
91
- menuRef(el);
92
- }
93
- // If there is no trigger `<ul>` is the ref, otherwise the trigger
94
- if (!this.props.trigger) {
95
- this.ref = el;
96
- }
97
- };
98
- this.registerMenuItem = item => {
99
- this._menuItems.push(item);
100
- };
101
- this.removeMenuItem = item => {
102
- const index = this.getMenuItemIndex(item);
103
- (0, _console.logError)(index >= 0, '[Menu] Could not find registered menu item.');
104
- if (index >= 0) {
105
- this._menuItems.splice(index, 1);
106
- }
107
- };
108
- this.getMenuItemIndex = item => {
109
- return this._menuItems.findIndex(i => i === item);
110
- };
111
- this.handleTriggerKeyDown = event => {
112
- if (this.props.type === 'flyout' && event.keyCode === _keycode.default.codes.right) {
113
- event.persist();
114
- this.show(event);
115
- }
116
- };
117
- this.handleTriggerMouseOver = event => {
118
- if (this.props.type === 'flyout') {
119
- this.show(event);
120
- }
121
- };
122
- this.handleToggle = shown => {
123
- if (typeof this.props.onToggle === 'function') {
124
- this.props.onToggle(shown, this);
125
- }
126
- };
127
- this.handleMenuKeyDown = event => {
128
- const key = event && event.keyCode;
129
- const _keycode$codes = _keycode.default.codes,
130
- down = _keycode$codes.down,
131
- up = _keycode$codes.up,
132
- tab = _keycode$codes.tab,
133
- left = _keycode$codes.left;
134
- const pgdn = _keycode.default.codes['page down'];
135
- const pgup = _keycode.default.codes['page up'];
136
- if (key === down || key === pgdn) {
137
- event.preventDefault();
138
- event.stopPropagation();
139
- this.moveFocus(1);
140
- this.hideActiveSubMenu(event);
141
- } else if (key === up || key === pgup) {
142
- event.preventDefault();
143
- event.stopPropagation();
144
- this.moveFocus(-1);
145
- this.hideActiveSubMenu(event);
146
- } else if (key === tab || key === left) {
147
- event.persist();
148
- this.hide(event);
149
- }
150
- if (typeof this.props.onKeyDown === 'function') {
151
- this.props.onKeyDown(event);
152
- }
153
- };
154
- this.handleMenuItemSelect = (event, value, selected, item) => {
155
- if (this.props.shouldHideOnSelect) {
156
- this.hide(event);
157
- }
158
- if (typeof this.props.onSelect === 'function') {
159
- this.props.onSelect(event, value, selected, item);
160
- }
161
- };
162
- this.handleMenuItemFocus = () => {
163
- this.setState({
164
- hasFocus: true
165
- });
166
- };
167
- this.handleMenuItemBlur = () => {
168
- this.setState({
169
- hasFocus: this.focusedIndex >= 0
170
- });
171
- };
172
- this.handleMenuItemMouseOver = (event, menuItem) => {
173
- if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
174
- this.hideActiveSubMenu(event);
175
- }
176
- };
177
- this.hideActiveSubMenu = event => {
178
- if (this._activeSubMenu) {
179
- this._activeSubMenu.hide(event);
180
- this._activeSubMenu = null;
181
- }
182
- };
183
- this.handleSubMenuToggle = (shown, subMenu) => {
184
- if (shown) {
185
- this._activeSubMenu = subMenu;
186
- }
187
- };
188
- this.handleSubMenuDismiss = (event, documentClick) => {
189
- if (event && event.keyCode === _keycode.default.codes.tab || documentClick) {
190
- this.hide(event);
191
- }
192
- };
193
- this.hide = event => {
194
- if (this._popover) {
195
- this._popover.hide(event);
196
- }
197
- };
198
- this.show = event => {
199
- if (this._popover) {
200
- this._popover.show(event);
201
- }
202
- };
203
120
  this._id = this.props.id || props.deterministicId();
204
121
  }
205
122
  componentDidMount() {
206
- var _this$props$makeStyle, _this$props;
207
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
123
+ this.props.makeStyles?.();
208
124
  }
209
125
  componentDidUpdate() {
210
- var _this$props$makeStyle2, _this$props2;
211
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
126
+ this.props.makeStyles?.();
212
127
  }
128
+ static contextType = _MenuContext.MenuContext;
129
+ registerMenuItem = item => {
130
+ this._menuItems.push(item);
131
+ };
132
+ removeMenuItem = item => {
133
+ const index = this.getMenuItemIndex(item);
134
+ (0, _console.logError)(index >= 0, '[Menu] Could not find registered menu item.');
135
+ if (index >= 0) {
136
+ this._menuItems.splice(index, 1);
137
+ }
138
+ };
213
139
  get menuItems() {
214
140
  return this._menuItems;
215
141
  }
142
+ getMenuItemIndex = item => {
143
+ return this._menuItems.findIndex(i => i === item);
144
+ };
145
+ handleTriggerKeyDown = event => {
146
+ if (this.props.type === 'flyout' && event.keyCode === _keycode.default.codes.right) {
147
+ event.persist();
148
+ this.show(event);
149
+ }
150
+ };
151
+ handleTriggerMouseOver = event => {
152
+ if (this.props.type === 'flyout') {
153
+ this.show(event);
154
+ }
155
+ };
156
+ handleToggle = shown => {
157
+ if (typeof this.props.onToggle === 'function') {
158
+ this.props.onToggle(shown, this);
159
+ }
160
+ };
161
+ handleMenuKeyDown = event => {
162
+ const key = event && event.keyCode;
163
+ const {
164
+ down,
165
+ up,
166
+ tab,
167
+ left
168
+ } = _keycode.default.codes;
169
+ const pgdn = _keycode.default.codes['page down'];
170
+ const pgup = _keycode.default.codes['page up'];
171
+ if (key === down || key === pgdn) {
172
+ event.preventDefault();
173
+ event.stopPropagation();
174
+ this.moveFocus(1);
175
+ this.hideActiveSubMenu(event);
176
+ } else if (key === up || key === pgup) {
177
+ event.preventDefault();
178
+ event.stopPropagation();
179
+ this.moveFocus(-1);
180
+ this.hideActiveSubMenu(event);
181
+ } else if (key === tab || key === left) {
182
+ event.persist();
183
+ this.hide(event);
184
+ }
185
+ if (typeof this.props.onKeyDown === 'function') {
186
+ this.props.onKeyDown(event);
187
+ }
188
+ };
189
+ handleMenuItemSelect = (event, value, selected, item) => {
190
+ if (this.props.shouldHideOnSelect) {
191
+ this.hide(event);
192
+ }
193
+ if (typeof this.props.onSelect === 'function') {
194
+ this.props.onSelect(event, value, selected, item);
195
+ }
196
+ };
197
+ handleMenuItemFocus = () => {
198
+ this.setState({
199
+ hasFocus: true
200
+ });
201
+ };
202
+ handleMenuItemBlur = () => {
203
+ this.setState({
204
+ hasFocus: this.focusedIndex >= 0
205
+ });
206
+ };
207
+ handleMenuItemMouseOver = (event, menuItem) => {
208
+ if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
209
+ this.hideActiveSubMenu(event);
210
+ }
211
+ };
212
+ hideActiveSubMenu = event => {
213
+ if (this._activeSubMenu) {
214
+ this._activeSubMenu.hide(event);
215
+ this._activeSubMenu = null;
216
+ }
217
+ };
218
+ handleSubMenuToggle = (shown, subMenu) => {
219
+ if (shown) {
220
+ this._activeSubMenu = subMenu;
221
+ }
222
+ };
223
+ handleSubMenuDismiss = (event, documentClick) => {
224
+ if (event && event.keyCode === _keycode.default.codes.tab || documentClick) {
225
+ this.hide(event);
226
+ }
227
+ };
228
+ hide = event => {
229
+ if (this._popover) {
230
+ this._popover.hide(event);
231
+ }
232
+ };
233
+ show = event => {
234
+ if (this._popover) {
235
+ this._popover.show(event);
236
+ }
237
+ };
216
238
  focus() {
217
239
  if (this.shown) {
218
- var _this$_menu;
219
- (0, _console.logError)(!!((_this$_menu = this._menu) !== null && _this$_menu !== void 0 && _this$_menu.focus), '[Menu] Could not focus the menu.');
240
+ (0, _console.logError)(!!this._menu?.focus, '[Menu] Could not focus the menu.');
220
241
  this._menu.focus();
221
242
  } else {
222
- var _this$_trigger;
223
- (0, _console.logError)(!!((_this$_trigger = this._trigger) !== null && _this$_trigger !== void 0 && _this$_trigger.focus), '[Menu] Could not focus the trigger.');
243
+ (0, _console.logError)(!!this._trigger?.focus, '[Menu] Could not focus the trigger.');
224
244
  this._trigger.focus();
225
245
  }
226
246
  }
@@ -250,9 +270,10 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
250
270
  return this._popover ? this._popover.shown : true;
251
271
  }
252
272
  renderChildren() {
253
- const _this$props3 = this.props,
254
- children = _this$props3.children,
255
- disabled = _this$props3.disabled;
273
+ const {
274
+ children,
275
+ disabled
276
+ } = this.props;
256
277
  let count = 0;
257
278
  return _react.Children.map(children, child => {
258
279
  if (!(0, _matchComponentTypes.matchComponentTypes)(child, ['MenuItemSeparator', 'MenuItem', 'MenuItemGroup', 'Menu'])) {
@@ -318,12 +339,12 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
318
339
  });
319
340
  }
320
341
  renderMenu() {
321
- var _this$props$styles;
322
- const _this$props4 = this.props,
323
- disabled = _this$props4.disabled,
324
- label = _this$props4.label,
325
- trigger = _this$props4.trigger,
326
- onKeyUp = _this$props4.onKeyUp;
342
+ const {
343
+ disabled,
344
+ label,
345
+ trigger,
346
+ onKeyUp
347
+ } = this.props;
327
348
  const labelledBy = this.props['aria-labelledby'];
328
349
  const controls = this.props['aria-controls'];
329
350
  return (0, _jsxRuntime.jsx)(_MenuContext.MenuContext.Provider, {
@@ -335,10 +356,10 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
335
356
  role: "menu",
336
357
  "aria-label": label,
337
358
  tabIndex: 0,
338
- css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.menu,
339
- "aria-labelledby": labelledBy || (trigger ? this._labelId : void 0),
359
+ css: this.props.styles?.menu,
360
+ "aria-labelledby": labelledBy || (trigger ? this._labelId : undefined),
340
361
  "aria-controls": controls,
341
- "aria-disabled": disabled ? 'true' : void 0,
362
+ "aria-disabled": disabled ? 'true' : undefined,
342
363
  onKeyDown: this.handleMenuKeyDown,
343
364
  onKeyUp: onKeyUp,
344
365
  ref: this.handleRef,
@@ -348,21 +369,22 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
348
369
  });
349
370
  }
350
371
  render() {
351
- const _this$props5 = this.props,
352
- show = _this$props5.show,
353
- defaultShow = _this$props5.defaultShow,
354
- placement = _this$props5.placement,
355
- withArrow = _this$props5.withArrow,
356
- trigger = _this$props5.trigger,
357
- mountNode = _this$props5.mountNode,
358
- popoverRef = _this$props5.popoverRef,
359
- disabled = _this$props5.disabled,
360
- onDismiss = _this$props5.onDismiss,
361
- onFocus = _this$props5.onFocus,
362
- onMouseOver = _this$props5.onMouseOver,
363
- positionContainerDisplay = _this$props5.positionContainerDisplay,
364
- offsetX = _this$props5.offsetX,
365
- offsetY = _this$props5.offsetY;
372
+ const {
373
+ show,
374
+ defaultShow,
375
+ placement,
376
+ withArrow,
377
+ trigger,
378
+ mountNode,
379
+ popoverRef,
380
+ disabled,
381
+ onDismiss,
382
+ onFocus,
383
+ onMouseOver,
384
+ positionContainerDisplay,
385
+ offsetX,
386
+ offsetY
387
+ } = this.props;
366
388
  return trigger ? (0, _jsxRuntime.jsx)(_latest.Popover, {
367
389
  "data-cid": "Menu",
368
390
  isShowingContent: show,
@@ -407,25 +429,9 @@ let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(
407
429
  onKeyDown: this.handleTriggerKeyDown,
408
430
  disabled: trigger.props.disabled || disabled
409
431
  }),
410
- defaultFocusElement: () => {
411
- var _this$_popover, _this$_popover$_conte;
412
- return (_this$_popover = this._popover) === null || _this$_popover === void 0 ? void 0 : (_this$_popover$_conte = _this$_popover._contentElement) === null || _this$_popover$_conte === void 0 ? void 0 : _this$_popover$_conte.querySelector('[class$="menuItem"]');
413
- },
432
+ defaultFocusElement: () => this._popover?._contentElement?.querySelector('[class$="menuItem"]'),
414
433
  children: this.renderMenu()
415
434
  }) : this.renderMenu();
416
435
  }
417
- }, _Menu.displayName = "Menu", _Menu.componentId = 'Menu', _Menu.allowedProps = _props.allowedProps, _Menu.defaultProps = {
418
- label: null,
419
- disabled: false,
420
- trigger: null,
421
- placement: 'bottom center',
422
- defaultShow: false,
423
- mountNode: null,
424
- constrain: 'window',
425
- shouldHideOnSelect: true,
426
- shouldFocusTriggerOnClose: true,
427
- withArrow: true,
428
- offsetX: 0,
429
- offsetY: 0
430
- }, _Menu.Item = _MenuItem.MenuItem, _Menu.Group = _MenuItemGroup.MenuItemGroup, _Menu.Separator = _MenuItemSeparator.MenuItemSeparator, _Menu.contextType = _MenuContext.MenuContext, _Menu)) || _class) || _class);
436
+ }) || _class) || _class);
431
437
  var _default = exports.default = Menu;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-menu",
3
- "version": "11.7.3-snapshot-7",
3
+ "version": "11.7.3-snapshot-26",
4
4
  "description": "A dropdown menu component",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -14,29 +14,29 @@
14
14
  "bugs": "https://github.com/instructure/instructure-ui/issues",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@babel/runtime": "^7.27.6",
17
+ "@babel/runtime": "^7.29.2",
18
18
  "keycode": "^2",
19
- "@instructure/console": "11.7.3-snapshot-7",
20
- "@instructure/ui-dom-utils": "11.7.3-snapshot-7",
21
- "@instructure/shared-types": "11.7.3-snapshot-7",
22
- "@instructure/ui-a11y-utils": "11.7.3-snapshot-7",
23
- "@instructure/emotion": "11.7.3-snapshot-7",
24
- "@instructure/ui-popover": "11.7.3-snapshot-7",
25
- "@instructure/ui-position": "11.7.3-snapshot-7",
26
- "@instructure/ui-react-utils": "11.7.3-snapshot-7",
27
- "@instructure/ui-icons": "11.7.3-snapshot-7",
28
- "@instructure/ui-themes": "11.7.3-snapshot-7",
29
- "@instructure/ui-utils": "11.7.3-snapshot-7",
30
- "@instructure/ui-view": "11.7.3-snapshot-7"
19
+ "@instructure/console": "11.7.3-snapshot-26",
20
+ "@instructure/ui-a11y-utils": "11.7.3-snapshot-26",
21
+ "@instructure/ui-dom-utils": "11.7.3-snapshot-26",
22
+ "@instructure/emotion": "11.7.3-snapshot-26",
23
+ "@instructure/shared-types": "11.7.3-snapshot-26",
24
+ "@instructure/ui-icons": "11.7.3-snapshot-26",
25
+ "@instructure/ui-popover": "11.7.3-snapshot-26",
26
+ "@instructure/ui-position": "11.7.3-snapshot-26",
27
+ "@instructure/ui-react-utils": "11.7.3-snapshot-26",
28
+ "@instructure/ui-themes": "11.7.3-snapshot-26",
29
+ "@instructure/ui-utils": "11.7.3-snapshot-26",
30
+ "@instructure/ui-view": "11.7.3-snapshot-26"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@testing-library/jest-dom": "^6.6.3",
34
34
  "@testing-library/react": "15.0.7",
35
35
  "@testing-library/user-event": "^14.6.1",
36
36
  "vitest": "^3.2.2",
37
- "@instructure/ui-axe-check": "11.7.3-snapshot-7",
38
- "@instructure/ui-babel-preset": "11.7.3-snapshot-7",
39
- "@instructure/ui-color-utils": "11.7.3-snapshot-7"
37
+ "@instructure/ui-babel-preset": "11.7.3-snapshot-26",
38
+ "@instructure/ui-color-utils": "11.7.3-snapshot-26",
39
+ "@instructure/ui-axe-check": "11.7.3-snapshot-26"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": ">=18 <=19"