@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.
@@ -1,4 +1,4 @@
1
- var _dec, _dec2, _class, _Menu;
1
+ var _dec, _dec2, _class;
2
2
  /*
3
3
  * The MIT License (MIT)
4
4
  *
@@ -42,158 +42,178 @@ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
42
42
  category: components
43
43
  ---
44
44
  **/
45
- let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_Menu = class Menu extends Component {
45
+ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = class Menu extends Component {
46
+ static displayName = "Menu";
47
+ static componentId = 'Menu';
48
+ static allowedProps = allowedProps;
49
+ static defaultProps = {
50
+ label: null,
51
+ disabled: false,
52
+ trigger: null,
53
+ placement: 'bottom center',
54
+ defaultShow: false,
55
+ mountNode: null,
56
+ constrain: 'window',
57
+ shouldHideOnSelect: true,
58
+ shouldFocusTriggerOnClose: true,
59
+ withArrow: true,
60
+ offsetX: 0,
61
+ offsetY: 0
62
+ };
63
+ static Item = MenuItem;
64
+ static Group = MenuItemGroup;
65
+ static Separator = MenuItemSeparator;
66
+ state = {
67
+ hasFocus: false
68
+ };
69
+ _rootNode = null;
70
+ _menuItems = [];
71
+ _popover = null;
72
+ _trigger = null;
73
+ _menu = null;
74
+ _labelId = this.props.deterministicId('Menu__label');
75
+ _activeSubMenu;
76
+ _id;
77
+ ref = null;
78
+ handleRef = el => {
79
+ const {
80
+ menuRef
81
+ } = this.props;
82
+ this._menu = el;
83
+ if (typeof menuRef === 'function') {
84
+ menuRef(el);
85
+ }
86
+ // If there is no trigger `<ul>` is the ref, otherwise the trigger
87
+ if (!this.props.trigger) {
88
+ this.ref = el;
89
+ }
90
+ };
46
91
  constructor(props) {
47
92
  super(props);
48
- this.state = {
49
- hasFocus: false
50
- };
51
- this._rootNode = null;
52
- this._menuItems = [];
53
- this._popover = null;
54
- this._trigger = null;
55
- this._menu = null;
56
- this._labelId = this.props.deterministicId('Menu__label');
57
- this._activeSubMenu = void 0;
58
- this._id = void 0;
59
- this.ref = null;
60
- this.handleRef = el => {
61
- const menuRef = this.props.menuRef;
62
- this._menu = el;
63
- if (typeof menuRef === 'function') {
64
- menuRef(el);
65
- }
66
- // If there is no trigger `<ul>` is the ref, otherwise the trigger
67
- if (!this.props.trigger) {
68
- this.ref = el;
69
- }
70
- };
71
- this.registerMenuItem = item => {
72
- this._menuItems.push(item);
73
- };
74
- this.removeMenuItem = item => {
75
- const index = this.getMenuItemIndex(item);
76
- error(index >= 0, '[Menu] Could not find registered menu item.');
77
- if (index >= 0) {
78
- this._menuItems.splice(index, 1);
79
- }
80
- };
81
- this.getMenuItemIndex = item => {
82
- return this._menuItems.findIndex(i => i === item);
83
- };
84
- this.handleTriggerKeyDown = event => {
85
- if (this.props.type === 'flyout' && event.keyCode === keycode.codes.right) {
86
- event.persist();
87
- this.show(event);
88
- }
89
- };
90
- this.handleTriggerMouseOver = event => {
91
- if (this.props.type === 'flyout') {
92
- this.show(event);
93
- }
94
- };
95
- this.handleToggle = shown => {
96
- if (typeof this.props.onToggle === 'function') {
97
- this.props.onToggle(shown, this);
98
- }
99
- };
100
- this.handleMenuKeyDown = event => {
101
- const key = event && event.keyCode;
102
- const _keycode$codes = keycode.codes,
103
- down = _keycode$codes.down,
104
- up = _keycode$codes.up,
105
- tab = _keycode$codes.tab,
106
- left = _keycode$codes.left;
107
- const pgdn = keycode.codes['page down'];
108
- const pgup = keycode.codes['page up'];
109
- if (key === down || key === pgdn) {
110
- event.preventDefault();
111
- event.stopPropagation();
112
- this.moveFocus(1);
113
- this.hideActiveSubMenu(event);
114
- } else if (key === up || key === pgup) {
115
- event.preventDefault();
116
- event.stopPropagation();
117
- this.moveFocus(-1);
118
- this.hideActiveSubMenu(event);
119
- } else if (key === tab || key === left) {
120
- event.persist();
121
- this.hide(event);
122
- }
123
- if (typeof this.props.onKeyDown === 'function') {
124
- this.props.onKeyDown(event);
125
- }
126
- };
127
- this.handleMenuItemSelect = (event, value, selected, item) => {
128
- if (this.props.shouldHideOnSelect) {
129
- this.hide(event);
130
- }
131
- if (typeof this.props.onSelect === 'function') {
132
- this.props.onSelect(event, value, selected, item);
133
- }
134
- };
135
- this.handleMenuItemFocus = () => {
136
- this.setState({
137
- hasFocus: true
138
- });
139
- };
140
- this.handleMenuItemBlur = () => {
141
- this.setState({
142
- hasFocus: this.focusedIndex >= 0
143
- });
144
- };
145
- this.handleMenuItemMouseOver = (event, menuItem) => {
146
- if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
147
- this.hideActiveSubMenu(event);
148
- }
149
- };
150
- this.hideActiveSubMenu = event => {
151
- if (this._activeSubMenu) {
152
- this._activeSubMenu.hide(event);
153
- this._activeSubMenu = null;
154
- }
155
- };
156
- this.handleSubMenuToggle = (shown, subMenu) => {
157
- if (shown) {
158
- this._activeSubMenu = subMenu;
159
- }
160
- };
161
- this.handleSubMenuDismiss = (event, documentClick) => {
162
- if (event && event.keyCode === keycode.codes.tab || documentClick) {
163
- this.hide(event);
164
- }
165
- };
166
- this.hide = event => {
167
- if (this._popover) {
168
- this._popover.hide(event);
169
- }
170
- };
171
- this.show = event => {
172
- if (this._popover) {
173
- this._popover.show(event);
174
- }
175
- };
176
93
  this._id = this.props.id || props.deterministicId();
177
94
  }
178
95
  componentDidMount() {
179
- var _this$props$makeStyle, _this$props;
180
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
96
+ this.props.makeStyles?.();
181
97
  }
182
98
  componentDidUpdate() {
183
- var _this$props$makeStyle2, _this$props2;
184
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
99
+ this.props.makeStyles?.();
185
100
  }
101
+ static contextType = MenuContext;
102
+ registerMenuItem = item => {
103
+ this._menuItems.push(item);
104
+ };
105
+ removeMenuItem = item => {
106
+ const index = this.getMenuItemIndex(item);
107
+ error(index >= 0, '[Menu] Could not find registered menu item.');
108
+ if (index >= 0) {
109
+ this._menuItems.splice(index, 1);
110
+ }
111
+ };
186
112
  get menuItems() {
187
113
  return this._menuItems;
188
114
  }
115
+ getMenuItemIndex = item => {
116
+ return this._menuItems.findIndex(i => i === item);
117
+ };
118
+ handleTriggerKeyDown = event => {
119
+ if (this.props.type === 'flyout' && event.keyCode === keycode.codes.right) {
120
+ event.persist();
121
+ this.show(event);
122
+ }
123
+ };
124
+ handleTriggerMouseOver = event => {
125
+ if (this.props.type === 'flyout') {
126
+ this.show(event);
127
+ }
128
+ };
129
+ handleToggle = shown => {
130
+ if (typeof this.props.onToggle === 'function') {
131
+ this.props.onToggle(shown, this);
132
+ }
133
+ };
134
+ handleMenuKeyDown = event => {
135
+ const key = event && event.keyCode;
136
+ const {
137
+ down,
138
+ up,
139
+ tab,
140
+ left
141
+ } = keycode.codes;
142
+ const pgdn = keycode.codes['page down'];
143
+ const pgup = keycode.codes['page up'];
144
+ if (key === down || key === pgdn) {
145
+ event.preventDefault();
146
+ event.stopPropagation();
147
+ this.moveFocus(1);
148
+ this.hideActiveSubMenu(event);
149
+ } else if (key === up || key === pgup) {
150
+ event.preventDefault();
151
+ event.stopPropagation();
152
+ this.moveFocus(-1);
153
+ this.hideActiveSubMenu(event);
154
+ } else if (key === tab || key === left) {
155
+ event.persist();
156
+ this.hide(event);
157
+ }
158
+ if (typeof this.props.onKeyDown === 'function') {
159
+ this.props.onKeyDown(event);
160
+ }
161
+ };
162
+ handleMenuItemSelect = (event, value, selected, item) => {
163
+ if (this.props.shouldHideOnSelect) {
164
+ this.hide(event);
165
+ }
166
+ if (typeof this.props.onSelect === 'function') {
167
+ this.props.onSelect(event, value, selected, item);
168
+ }
169
+ };
170
+ handleMenuItemFocus = () => {
171
+ this.setState({
172
+ hasFocus: true
173
+ });
174
+ };
175
+ handleMenuItemBlur = () => {
176
+ this.setState({
177
+ hasFocus: this.focusedIndex >= 0
178
+ });
179
+ };
180
+ handleMenuItemMouseOver = (event, menuItem) => {
181
+ if (this._activeSubMenu && menuItem !== this._activeSubMenu._trigger) {
182
+ this.hideActiveSubMenu(event);
183
+ }
184
+ };
185
+ hideActiveSubMenu = event => {
186
+ if (this._activeSubMenu) {
187
+ this._activeSubMenu.hide(event);
188
+ this._activeSubMenu = null;
189
+ }
190
+ };
191
+ handleSubMenuToggle = (shown, subMenu) => {
192
+ if (shown) {
193
+ this._activeSubMenu = subMenu;
194
+ }
195
+ };
196
+ handleSubMenuDismiss = (event, documentClick) => {
197
+ if (event && event.keyCode === keycode.codes.tab || documentClick) {
198
+ this.hide(event);
199
+ }
200
+ };
201
+ hide = event => {
202
+ if (this._popover) {
203
+ this._popover.hide(event);
204
+ }
205
+ };
206
+ show = event => {
207
+ if (this._popover) {
208
+ this._popover.show(event);
209
+ }
210
+ };
189
211
  focus() {
190
212
  if (this.shown) {
191
- var _this$_menu;
192
- error(!!((_this$_menu = this._menu) !== null && _this$_menu !== void 0 && _this$_menu.focus), '[Menu] Could not focus the menu.');
213
+ error(!!this._menu?.focus, '[Menu] Could not focus the menu.');
193
214
  this._menu.focus();
194
215
  } else {
195
- var _this$_trigger;
196
- error(!!((_this$_trigger = this._trigger) !== null && _this$_trigger !== void 0 && _this$_trigger.focus), '[Menu] Could not focus the trigger.');
216
+ error(!!this._trigger?.focus, '[Menu] Could not focus the trigger.');
197
217
  this._trigger.focus();
198
218
  }
199
219
  }
@@ -223,9 +243,10 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec
223
243
  return this._popover ? this._popover.shown : true;
224
244
  }
225
245
  renderChildren() {
226
- const _this$props3 = this.props,
227
- children = _this$props3.children,
228
- disabled = _this$props3.disabled;
246
+ const {
247
+ children,
248
+ disabled
249
+ } = this.props;
229
250
  let count = 0;
230
251
  return Children.map(children, child => {
231
252
  if (!matchComponentTypes(child, ['MenuItemSeparator', 'MenuItem', 'MenuItemGroup', 'Menu'])) {
@@ -291,12 +312,12 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec
291
312
  });
292
313
  }
293
314
  renderMenu() {
294
- var _this$props$styles;
295
- const _this$props4 = this.props,
296
- disabled = _this$props4.disabled,
297
- label = _this$props4.label,
298
- trigger = _this$props4.trigger,
299
- onKeyUp = _this$props4.onKeyUp;
315
+ const {
316
+ disabled,
317
+ label,
318
+ trigger,
319
+ onKeyUp
320
+ } = this.props;
300
321
  const labelledBy = this.props['aria-labelledby'];
301
322
  const controls = this.props['aria-controls'];
302
323
  return _jsx(MenuContext.Provider, {
@@ -308,10 +329,10 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec
308
329
  role: "menu",
309
330
  "aria-label": label,
310
331
  tabIndex: 0,
311
- css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.menu,
312
- "aria-labelledby": labelledBy || (trigger ? this._labelId : void 0),
332
+ css: this.props.styles?.menu,
333
+ "aria-labelledby": labelledBy || (trigger ? this._labelId : undefined),
313
334
  "aria-controls": controls,
314
- "aria-disabled": disabled ? 'true' : void 0,
335
+ "aria-disabled": disabled ? 'true' : undefined,
315
336
  onKeyDown: this.handleMenuKeyDown,
316
337
  onKeyUp: onKeyUp,
317
338
  ref: this.handleRef,
@@ -321,21 +342,22 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec
321
342
  });
322
343
  }
323
344
  render() {
324
- const _this$props5 = this.props,
325
- show = _this$props5.show,
326
- defaultShow = _this$props5.defaultShow,
327
- placement = _this$props5.placement,
328
- withArrow = _this$props5.withArrow,
329
- trigger = _this$props5.trigger,
330
- mountNode = _this$props5.mountNode,
331
- popoverRef = _this$props5.popoverRef,
332
- disabled = _this$props5.disabled,
333
- onDismiss = _this$props5.onDismiss,
334
- onFocus = _this$props5.onFocus,
335
- onMouseOver = _this$props5.onMouseOver,
336
- positionContainerDisplay = _this$props5.positionContainerDisplay,
337
- offsetX = _this$props5.offsetX,
338
- offsetY = _this$props5.offsetY;
345
+ const {
346
+ show,
347
+ defaultShow,
348
+ placement,
349
+ withArrow,
350
+ trigger,
351
+ mountNode,
352
+ popoverRef,
353
+ disabled,
354
+ onDismiss,
355
+ onFocus,
356
+ onMouseOver,
357
+ positionContainerDisplay,
358
+ offsetX,
359
+ offsetY
360
+ } = this.props;
339
361
  return trigger ? _jsx(Popover, {
340
362
  "data-cid": "Menu",
341
363
  isShowingContent: show,
@@ -380,26 +402,10 @@ let Menu = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec
380
402
  onKeyDown: this.handleTriggerKeyDown,
381
403
  disabled: trigger.props.disabled || disabled
382
404
  }),
383
- defaultFocusElement: () => {
384
- var _this$_popover, _this$_popover$_conte;
385
- 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"]');
386
- },
405
+ defaultFocusElement: () => this._popover?._contentElement?.querySelector('[class$="menuItem"]'),
387
406
  children: this.renderMenu()
388
407
  }) : this.renderMenu();
389
408
  }
390
- }, _Menu.displayName = "Menu", _Menu.componentId = 'Menu', _Menu.allowedProps = allowedProps, _Menu.defaultProps = {
391
- label: null,
392
- disabled: false,
393
- trigger: null,
394
- placement: 'bottom center',
395
- defaultShow: false,
396
- mountNode: null,
397
- constrain: 'window',
398
- shouldHideOnSelect: true,
399
- shouldFocusTriggerOnClose: true,
400
- withArrow: true,
401
- offsetX: 0,
402
- offsetY: 0
403
- }, _Menu.Item = MenuItem, _Menu.Group = MenuItemGroup, _Menu.Separator = MenuItemSeparator, _Menu.contextType = MenuContext, _Menu)) || _class) || _class);
409
+ }) || _class) || _class);
404
410
  export default Menu;
405
411
  export { Menu, MenuItem, MenuItemGroup, MenuItemSeparator };