@instructure/ui-menu 8.56.2-pr-snapshot-1721749364069 → 8.56.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 +5 -2
- package/lib/Menu/MenuItem/index.js +20 -16
- package/lib/Menu/MenuItem/props.js +2 -2
- package/lib/Menu/MenuItemGroup/index.js +12 -9
- package/lib/Menu/MenuItemGroup/props.js +4 -3
- package/lib/Menu/MenuItemSeparator/index.js +4 -4
- package/lib/Menu/__new-tests__/Menu.test.js +4 -4
- package/lib/Menu/index.js +19 -17
- package/lib/Menu/props.js +8 -7
- package/package.json +18 -18
- package/src/Menu/MenuItem/index.tsx +2 -2
- package/src/Menu/MenuItem/props.ts +14 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Menu/MenuItem/index.d.ts.map +1 -1
- package/types/Menu/MenuItem/props.d.ts +13 -1
- package/types/Menu/MenuItem/props.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [8.56.2
|
|
6
|
+
## [8.56.2](https://github.com/instructure/instructure-ui/compare/v8.56.1...v8.56.2) (2024-08-06)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **ui-menu:** menuItem's onSelect type did not expose its value and selected types ([98ca20e](https://github.com/instructure/instructure-ui/commit/98ca20e215808283b891b13a47b2bb54e12967e2))
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
|
|
@@ -8,11 +8,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.default = exports.MenuItem = void 0;
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _keycode = _interopRequireDefault(require("keycode"));
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
11
|
+
var _IconCheckSolid2 = require("@instructure/ui-icons/lib/IconCheckSolid.js");
|
|
12
|
+
var _IconArrowOpenEndSolid = require("@instructure/ui-icons/lib/IconArrowOpenEndSolid.js");
|
|
13
|
+
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
14
|
+
var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
|
|
15
|
+
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
16
|
+
var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
|
|
17
|
+
var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
|
|
18
|
+
var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
|
|
19
|
+
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
16
20
|
var _emotion = require("@instructure/emotion");
|
|
17
21
|
var _MenuContext = require("../../MenuContext");
|
|
18
22
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
@@ -49,7 +53,7 @@ parent: Menu
|
|
|
49
53
|
id: Menu.Item
|
|
50
54
|
---
|
|
51
55
|
**/
|
|
52
|
-
let MenuItem = exports.MenuItem = (_dec = (0,
|
|
56
|
+
let MenuItem = exports.MenuItem = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec3 = (0, _testable.testable)(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class MenuItem extends _react.Component {
|
|
53
57
|
constructor(props) {
|
|
54
58
|
super(props);
|
|
55
59
|
this.labelId = void 0;
|
|
@@ -89,7 +93,7 @@ let MenuItem = exports.MenuItem = (_dec = (0, _uiReactUtils.withDeterministicId)
|
|
|
89
93
|
e.stopPropagation();
|
|
90
94
|
if (enterKey) {
|
|
91
95
|
// handle space key on keyUp for FF
|
|
92
|
-
const refNode = (0,
|
|
96
|
+
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
93
97
|
refNode.click();
|
|
94
98
|
}
|
|
95
99
|
}
|
|
@@ -101,7 +105,7 @@ let MenuItem = exports.MenuItem = (_dec = (0, _uiReactUtils.withDeterministicId)
|
|
|
101
105
|
e.preventDefault();
|
|
102
106
|
e.stopPropagation();
|
|
103
107
|
if (spaceKey) {
|
|
104
|
-
const refNode = (0,
|
|
108
|
+
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
105
109
|
refNode.click();
|
|
106
110
|
}
|
|
107
111
|
}
|
|
@@ -141,7 +145,7 @@ let MenuItem = exports.MenuItem = (_dec = (0, _uiReactUtils.withDeterministicId)
|
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
147
|
get elementType() {
|
|
144
|
-
return (0,
|
|
148
|
+
return (0, _getElementType.getElementType)(MenuItem, this.props);
|
|
145
149
|
}
|
|
146
150
|
get role() {
|
|
147
151
|
switch (this.props.type) {
|
|
@@ -159,10 +163,10 @@ let MenuItem = exports.MenuItem = (_dec = (0, _uiReactUtils.withDeterministicId)
|
|
|
159
163
|
return typeof this.props.selected === 'undefined' ? this.state.selected : this.props.selected;
|
|
160
164
|
}
|
|
161
165
|
get focused() {
|
|
162
|
-
return (0,
|
|
166
|
+
return (0, _isActiveElement.isActiveElement)(this.ref);
|
|
163
167
|
}
|
|
164
168
|
focus() {
|
|
165
|
-
const refNode = (0,
|
|
169
|
+
const refNode = (0, _findDOMNode.findDOMNode)(this.ref);
|
|
166
170
|
refNode.focus();
|
|
167
171
|
}
|
|
168
172
|
renderContent() {
|
|
@@ -172,12 +176,12 @@ let MenuItem = exports.MenuItem = (_dec = (0, _uiReactUtils.withDeterministicId)
|
|
|
172
176
|
type = _this$props4.type;
|
|
173
177
|
return (0, _emotion.jsx)("span", null, (type === 'checkbox' || type === 'radio') && (0, _emotion.jsx)("span", {
|
|
174
178
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.icon
|
|
175
|
-
}, this.selected && (_IconCheckSolid || (_IconCheckSolid = (0, _emotion.jsx)(
|
|
179
|
+
}, this.selected && (_IconCheckSolid || (_IconCheckSolid = (0, _emotion.jsx)(_IconCheckSolid2.IconCheckSolid, null)))), (0, _emotion.jsx)("span", {
|
|
176
180
|
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.label,
|
|
177
181
|
id: this.labelId
|
|
178
182
|
}, children), type === 'flyout' && (0, _emotion.jsx)("span", {
|
|
179
183
|
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.icon
|
|
180
|
-
}, _IconArrowOpenEndSoli || (_IconArrowOpenEndSoli = (0, _emotion.jsx)(
|
|
184
|
+
}, _IconArrowOpenEndSoli || (_IconArrowOpenEndSoli = (0, _emotion.jsx)(_IconArrowOpenEndSolid.IconArrowOpenEndSolid, null))));
|
|
181
185
|
}
|
|
182
186
|
render() {
|
|
183
187
|
var _this$props$styles4;
|
|
@@ -188,7 +192,7 @@ let MenuItem = exports.MenuItem = (_dec = (0, _uiReactUtils.withDeterministicId)
|
|
|
188
192
|
onKeyUp = _this$props5.onKeyUp,
|
|
189
193
|
type = _this$props5.type,
|
|
190
194
|
href = _this$props5.href;
|
|
191
|
-
const props = (0,
|
|
195
|
+
const props = (0, _omitProps.omitProps)(this.props, MenuItem.allowedProps);
|
|
192
196
|
const ElementType = this.elementType;
|
|
193
197
|
return (0, _emotion.jsx)(ElementType, Object.assign({
|
|
194
198
|
tabIndex: -1 // note: tabIndex can be overridden by Menu or MenuItemGroup components
|
|
@@ -200,8 +204,8 @@ let MenuItem = exports.MenuItem = (_dec = (0, _uiReactUtils.withDeterministicId)
|
|
|
200
204
|
"aria-controls": controls,
|
|
201
205
|
"aria-checked": type === 'checkbox' || type === 'radio' ? this.selected ? 'true' : 'false' : void 0,
|
|
202
206
|
onClick: this.handleClick,
|
|
203
|
-
onKeyUp: (0,
|
|
204
|
-
onKeyDown: (0,
|
|
207
|
+
onKeyUp: (0, _createChainedFunction.createChainedFunction)(onKeyUp, this.handleKeyUp),
|
|
208
|
+
onKeyDown: (0, _createChainedFunction.createChainedFunction)(onKeyDown, this.handleKeyDown),
|
|
205
209
|
ref: this.handleRef,
|
|
206
210
|
css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.menuItem,
|
|
207
211
|
onMouseOver: this.handleMouseOver
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.propTypes = exports.allowedProps = void 0;
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var
|
|
9
|
+
var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
|
|
10
10
|
/*
|
|
11
11
|
* The MIT License (MIT)
|
|
12
12
|
*
|
|
@@ -34,7 +34,7 @@ var _uiPropTypes = require("@instructure/ui-prop-types");
|
|
|
34
34
|
const propTypes = exports.propTypes = {
|
|
35
35
|
children: _propTypes.default.node.isRequired,
|
|
36
36
|
defaultSelected: _propTypes.default.bool,
|
|
37
|
-
selected: (0,
|
|
37
|
+
selected: (0, _controllable.controllable)(_propTypes.default.bool, 'onSelect', 'defaultSelected'),
|
|
38
38
|
onSelect: _propTypes.default.func,
|
|
39
39
|
onClick: _propTypes.default.func,
|
|
40
40
|
onKeyDown: _propTypes.default.func,
|
|
@@ -8,9 +8,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.default = exports.MenuItemGroup = void 0;
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _emotion = require("@instructure/emotion");
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
11
|
+
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
12
|
+
var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
|
|
13
|
+
var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
|
|
14
|
+
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
15
|
+
var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
|
|
16
|
+
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
14
17
|
var _MenuItem = require("../MenuItem");
|
|
15
18
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
16
19
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
@@ -46,7 +49,7 @@ parent: Menu
|
|
|
46
49
|
id: Menu.Group
|
|
47
50
|
---
|
|
48
51
|
**/
|
|
49
|
-
let MenuItemGroup = exports.MenuItemGroup = (_dec = (0,
|
|
52
|
+
let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec3 = (0, _testable.testable)(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class MenuItemGroup extends _react.Component {
|
|
50
53
|
constructor(props) {
|
|
51
54
|
super(props);
|
|
52
55
|
this._labelId = void 0;
|
|
@@ -106,7 +109,7 @@ let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _uiReactUtils.withDeterm
|
|
|
106
109
|
allowMultiple = props.allowMultiple;
|
|
107
110
|
const selected = [];
|
|
108
111
|
const items = _react.Children.toArray(children).filter(child => {
|
|
109
|
-
return (0,
|
|
112
|
+
return (0, _matchComponentTypes.matchComponentTypes)(child, [_MenuItem.MenuItem]);
|
|
110
113
|
});
|
|
111
114
|
items.forEach((item, index) => {
|
|
112
115
|
if ((selected.length === 0 || allowMultiple) && (item.props.selected || item.props.defaultSelected)) {
|
|
@@ -125,7 +128,7 @@ let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _uiReactUtils.withDeterm
|
|
|
125
128
|
renderLabel() {
|
|
126
129
|
var _this$props$styles;
|
|
127
130
|
const label = this.props.label;
|
|
128
|
-
return (0,
|
|
131
|
+
return (0, _hasVisibleChildren.hasVisibleChildren)(label) ? (0, _emotion.jsx)("span", {
|
|
129
132
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.label
|
|
130
133
|
}, label) : label;
|
|
131
134
|
}
|
|
@@ -139,12 +142,12 @@ let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _uiReactUtils.withDeterm
|
|
|
139
142
|
const children = this.props.children;
|
|
140
143
|
let index = -1;
|
|
141
144
|
return _react.Children.map(children, child => {
|
|
142
|
-
if ((0,
|
|
145
|
+
if ((0, _matchComponentTypes.matchComponentTypes)(child, [_MenuItem.MenuItem])) {
|
|
143
146
|
++index;
|
|
144
147
|
const value = child.props.value || index;
|
|
145
148
|
return (0, _emotion.jsx)("li", {
|
|
146
149
|
role: "none"
|
|
147
|
-
}, ' ', (0,
|
|
150
|
+
}, ' ', (0, _safeCloneElement.safeCloneElement)(child, {
|
|
148
151
|
tabIndex: isTabbable && index === 0 ? 0 : -1,
|
|
149
152
|
controls,
|
|
150
153
|
value,
|
|
@@ -163,7 +166,7 @@ let MenuItemGroup = exports.MenuItemGroup = (_dec = (0, _uiReactUtils.withDeterm
|
|
|
163
166
|
}
|
|
164
167
|
render() {
|
|
165
168
|
var _this$props$styles2, _this$props$styles3;
|
|
166
|
-
const props = (0,
|
|
169
|
+
const props = (0, _omitProps.omitProps)(this.props, MenuItemGroup.allowedProps);
|
|
167
170
|
return (0, _emotion.jsx)("span", Object.assign({}, props, {
|
|
168
171
|
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.menuItemGroup,
|
|
169
172
|
role: "presentation",
|
|
@@ -6,7 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.propTypes = exports.allowedProps = void 0;
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var
|
|
9
|
+
var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
|
|
10
|
+
var _Children = require("@instructure/ui-prop-types/lib/Children.js");
|
|
10
11
|
var _MenuItem = require("../MenuItem");
|
|
11
12
|
var _MenuItemSeparator = require("../MenuItemSeparator");
|
|
12
13
|
/*
|
|
@@ -36,8 +37,8 @@ var _MenuItemSeparator = require("../MenuItemSeparator");
|
|
|
36
37
|
const propTypes = exports.propTypes = {
|
|
37
38
|
label: _propTypes.default.node.isRequired,
|
|
38
39
|
allowMultiple: _propTypes.default.bool,
|
|
39
|
-
children:
|
|
40
|
-
selected: (0,
|
|
40
|
+
children: _Children.Children.oneOf([_MenuItem.MenuItem, _MenuItemSeparator.MenuItemSeparator]),
|
|
41
|
+
selected: (0, _controllable.controllable)(_propTypes.default.array, 'onSelect', 'defaultSelected'),
|
|
41
42
|
defaultSelected: _propTypes.default.array,
|
|
42
43
|
onSelect: _propTypes.default.func,
|
|
43
44
|
onMouseOver: _propTypes.default.func,
|
|
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.MenuItemSeparator = void 0;
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _emotion = require("@instructure/emotion");
|
|
10
|
-
var
|
|
11
|
-
var
|
|
10
|
+
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
11
|
+
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
12
12
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
13
13
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
14
14
|
var _props = require("./props");
|
|
@@ -44,7 +44,7 @@ id: Menu.Separator
|
|
|
44
44
|
---
|
|
45
45
|
@module MenuItemSeparator
|
|
46
46
|
**/
|
|
47
|
-
let MenuItemSeparator = exports.MenuItemSeparator = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0,
|
|
47
|
+
let MenuItemSeparator = exports.MenuItemSeparator = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class MenuItemSeparator extends _react.Component {
|
|
48
48
|
constructor(...args) {
|
|
49
49
|
super(...args);
|
|
50
50
|
this.ref = null;
|
|
@@ -62,7 +62,7 @@ let MenuItemSeparator = exports.MenuItemSeparator = (_dec = (0, _emotion.withSty
|
|
|
62
62
|
}
|
|
63
63
|
render() {
|
|
64
64
|
var _this$props$styles;
|
|
65
|
-
const props = (0,
|
|
65
|
+
const props = (0, _omitProps.omitProps)(this.props, MenuItemSeparator.allowedProps);
|
|
66
66
|
return (0, _emotion.jsx)("div", Object.assign({}, props, {
|
|
67
67
|
role: "presentation",
|
|
68
68
|
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.menuItemSeparator,
|
|
@@ -5,7 +5,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
5
5
|
var _react2 = require("@testing-library/react");
|
|
6
6
|
var _userEvent = require("@testing-library/user-event");
|
|
7
7
|
require("@testing-library/jest-dom");
|
|
8
|
-
var
|
|
8
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
9
9
|
var _index = require("../index");
|
|
10
10
|
var _Menu, _Menu2, _Menu3, _Menu4, _MenuItem, _MenuItem2, _MenuItem3, _Menu5, _button, _MenuItem4, _Menu6, _button2, _MenuItem5, _MenuItem6, _button3, _MenuItem7, _MenuItem8, _Menu7, _Menu8, _button4, _MenuItem9, _MenuItem10, _button5, _MenuItem11, _MenuItem12, _button6, _MenuItem13, _MenuItem14, _Menu9, _button7, _MenuItem15, _MenuItem16;
|
|
11
11
|
/*
|
|
@@ -47,7 +47,7 @@ describe('<Menu />', () => {
|
|
|
47
47
|
label: "Menu-label-text"
|
|
48
48
|
}, /*#__PURE__*/_react.default.createElement(_index.MenuItem, null, "Menu Item Text")))),
|
|
49
49
|
container = _render.container;
|
|
50
|
-
const axeCheck = await (0,
|
|
50
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
51
51
|
expect(axeCheck).toBe(true);
|
|
52
52
|
});
|
|
53
53
|
it('should meet standards when menu is closed', async () => {
|
|
@@ -57,7 +57,7 @@ describe('<Menu />', () => {
|
|
|
57
57
|
disabled: true
|
|
58
58
|
}, "Gradebook")))),
|
|
59
59
|
container = _render2.container;
|
|
60
|
-
const axeCheck = await (0,
|
|
60
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
61
61
|
expect(axeCheck).toBe(true);
|
|
62
62
|
});
|
|
63
63
|
it('should meet standards when menu is open', async () => {
|
|
@@ -68,7 +68,7 @@ describe('<Menu />', () => {
|
|
|
68
68
|
disabled: true
|
|
69
69
|
}, "Gradebook")))),
|
|
70
70
|
container = _render3.container;
|
|
71
|
-
const axeCheck = await (0,
|
|
71
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
|
|
72
72
|
expect(axeCheck).toBe(true);
|
|
73
73
|
});
|
|
74
74
|
it('should call onSelect when menu item is selected', async () => {
|
package/lib/Menu/index.js
CHANGED
|
@@ -27,11 +27,13 @@ Object.defineProperty(exports, "MenuItemSeparator", {
|
|
|
27
27
|
exports.default = void 0;
|
|
28
28
|
var _react = _interopRequireWildcard(require("react"));
|
|
29
29
|
var _keycode = _interopRequireDefault(require("keycode"));
|
|
30
|
-
var
|
|
31
|
-
var
|
|
30
|
+
var _Popover = require("@instructure/ui-popover/lib/Popover");
|
|
31
|
+
var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
|
|
32
|
+
var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
|
|
33
|
+
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
32
34
|
var _console = require("@instructure/console");
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
+
var _containsActiveElement = require("@instructure/ui-dom-utils/lib/containsActiveElement.js");
|
|
36
|
+
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
35
37
|
var _MenuContext = require("../MenuContext");
|
|
36
38
|
var _MenuItem = require("./MenuItem");
|
|
37
39
|
var _MenuItemGroup = require("./MenuItemGroup");
|
|
@@ -70,7 +72,7 @@ var _dec, _dec2, _dec3, _class, _class2;
|
|
|
70
72
|
category: components
|
|
71
73
|
---
|
|
72
74
|
**/
|
|
73
|
-
let Menu = exports.Menu = (_dec = (0,
|
|
75
|
+
let Menu = exports.Menu = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec3 = (0, _testable.testable)(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class Menu extends _react.Component {
|
|
74
76
|
constructor(props) {
|
|
75
77
|
super(props);
|
|
76
78
|
this.state = {
|
|
@@ -227,9 +229,9 @@ let Menu = exports.Menu = (_dec = (0, _uiReactUtils.withDeterministicId)(), _dec
|
|
|
227
229
|
}
|
|
228
230
|
focused() {
|
|
229
231
|
if (this.shown) {
|
|
230
|
-
return (0,
|
|
232
|
+
return (0, _containsActiveElement.containsActiveElement)(this._menu) || this.state.hasFocus;
|
|
231
233
|
} else {
|
|
232
|
-
return (0,
|
|
234
|
+
return (0, _containsActiveElement.containsActiveElement)(this._trigger);
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
237
|
get focusedIndex() {
|
|
@@ -256,22 +258,22 @@ let Menu = exports.Menu = (_dec = (0, _uiReactUtils.withDeterministicId)(), _dec
|
|
|
256
258
|
disabled = _this$props3.disabled;
|
|
257
259
|
let count = 0;
|
|
258
260
|
return _react.Children.map(children, child => {
|
|
259
|
-
if (!(0,
|
|
261
|
+
if (!(0, _matchComponentTypes.matchComponentTypes)(child, ['MenuItemSeparator', 'MenuItem', 'MenuItemGroup', 'Menu'])) {
|
|
260
262
|
return;
|
|
261
263
|
}
|
|
262
264
|
count += 1;
|
|
263
265
|
const isTabbable = !this.state.hasFocus && count === 1;
|
|
264
|
-
if ((0,
|
|
266
|
+
if ((0, _matchComponentTypes.matchComponentTypes)(child, ['MenuItemSeparator'])) {
|
|
265
267
|
return (0, _emotion.jsx)("li", {
|
|
266
268
|
role: "none"
|
|
267
269
|
}, child);
|
|
268
270
|
}
|
|
269
271
|
const menuItemChild = child;
|
|
270
272
|
const controls = menuItemChild.props['aria-controls'] || menuItemChild.props.controls || this.props['aria-controls'] || this.props.controls;
|
|
271
|
-
if ((0,
|
|
273
|
+
if ((0, _matchComponentTypes.matchComponentTypes)(child, ['MenuItem'])) {
|
|
272
274
|
return (0, _emotion.jsx)("li", {
|
|
273
275
|
role: "none"
|
|
274
|
-
}, (0,
|
|
276
|
+
}, (0, _safeCloneElement.safeCloneElement)(child, {
|
|
275
277
|
controls,
|
|
276
278
|
children: child.props.children,
|
|
277
279
|
disabled: disabled || child.props.disabled,
|
|
@@ -282,10 +284,10 @@ let Menu = exports.Menu = (_dec = (0, _uiReactUtils.withDeterministicId)(), _dec
|
|
|
282
284
|
tabIndex: isTabbable ? 0 : -1
|
|
283
285
|
}));
|
|
284
286
|
}
|
|
285
|
-
if ((0,
|
|
287
|
+
if ((0, _matchComponentTypes.matchComponentTypes)(child, ['MenuItemGroup'])) {
|
|
286
288
|
return (0, _emotion.jsx)("li", {
|
|
287
289
|
role: "none"
|
|
288
|
-
}, (0,
|
|
290
|
+
}, (0, _safeCloneElement.safeCloneElement)(child, {
|
|
289
291
|
label: child.props.label,
|
|
290
292
|
controls,
|
|
291
293
|
disabled: disabled || child.props.disabled,
|
|
@@ -296,11 +298,11 @@ let Menu = exports.Menu = (_dec = (0, _uiReactUtils.withDeterministicId)(), _dec
|
|
|
296
298
|
isTabbable
|
|
297
299
|
}));
|
|
298
300
|
}
|
|
299
|
-
if ((0,
|
|
301
|
+
if ((0, _matchComponentTypes.matchComponentTypes)(child, ['Menu'])) {
|
|
300
302
|
const submenuDisabled = disabled || child.props.disabled;
|
|
301
303
|
return (0, _emotion.jsx)("li", {
|
|
302
304
|
role: "none"
|
|
303
|
-
}, (0,
|
|
305
|
+
}, (0, _safeCloneElement.safeCloneElement)(child, {
|
|
304
306
|
type: 'flyout',
|
|
305
307
|
controls,
|
|
306
308
|
disabled: submenuDisabled,
|
|
@@ -367,7 +369,7 @@ let Menu = exports.Menu = (_dec = (0, _uiReactUtils.withDeterministicId)(), _dec
|
|
|
367
369
|
positionContainerDisplay = _this$props5.positionContainerDisplay,
|
|
368
370
|
offsetX = _this$props5.offsetX,
|
|
369
371
|
offsetY = _this$props5.offsetY;
|
|
370
|
-
return trigger ? (0, _emotion.jsx)(
|
|
372
|
+
return trigger ? (0, _emotion.jsx)(_Popover.Popover, {
|
|
371
373
|
isShowingContent: show,
|
|
372
374
|
defaultIsShowingContent: defaultShow,
|
|
373
375
|
onHideContent: (event, {
|
|
@@ -400,7 +402,7 @@ let Menu = exports.Menu = (_dec = (0, _uiReactUtils.withDeterministicId)(), _dec
|
|
|
400
402
|
popoverRef(el);
|
|
401
403
|
}
|
|
402
404
|
},
|
|
403
|
-
renderTrigger: (0,
|
|
405
|
+
renderTrigger: (0, _safeCloneElement.safeCloneElement)(trigger, {
|
|
404
406
|
ref: el => {
|
|
405
407
|
this._trigger = el;
|
|
406
408
|
},
|
package/lib/Menu/props.js
CHANGED
|
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.propTypes = exports.allowedProps = void 0;
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var _PositionPropTypes = require("@instructure/ui-position/lib/PositionPropTypes.js");
|
|
10
|
+
var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
|
|
11
|
+
var _Children = require("@instructure/ui-prop-types/lib/Children.js");
|
|
11
12
|
/*
|
|
12
13
|
* The MIT License (MIT)
|
|
13
14
|
*
|
|
@@ -33,13 +34,13 @@ var _uiPropTypes = require("@instructure/ui-prop-types");
|
|
|
33
34
|
*/
|
|
34
35
|
|
|
35
36
|
const propTypes = exports.propTypes = {
|
|
36
|
-
children:
|
|
37
|
+
children: _Children.Children.oneOf(['MenuItem', 'MenuItemGroup', 'MenuItemSeparator', 'Menu']),
|
|
37
38
|
label: _propTypes.default.string,
|
|
38
39
|
disabled: _propTypes.default.bool,
|
|
39
40
|
trigger: _propTypes.default.node,
|
|
40
|
-
placement:
|
|
41
|
+
placement: _PositionPropTypes.PositionPropTypes.placement,
|
|
41
42
|
defaultShow: _propTypes.default.bool,
|
|
42
|
-
show: (0,
|
|
43
|
+
show: (0, _controllable.controllable)(_propTypes.default.bool, 'onToggle', 'defaultShow'),
|
|
43
44
|
onToggle: _propTypes.default.func,
|
|
44
45
|
onSelect: _propTypes.default.func,
|
|
45
46
|
onDismiss: _propTypes.default.func,
|
|
@@ -49,8 +50,8 @@ const propTypes = exports.propTypes = {
|
|
|
49
50
|
onKeyUp: _propTypes.default.func,
|
|
50
51
|
menuRef: _propTypes.default.func,
|
|
51
52
|
popoverRef: _propTypes.default.func,
|
|
52
|
-
mountNode:
|
|
53
|
-
constrain:
|
|
53
|
+
mountNode: _PositionPropTypes.PositionPropTypes.mountNode,
|
|
54
|
+
constrain: _PositionPropTypes.PositionPropTypes.constrain,
|
|
54
55
|
shouldHideOnSelect: _propTypes.default.bool,
|
|
55
56
|
shouldFocusTriggerOnClose: _propTypes.default.bool,
|
|
56
57
|
positionContainerDisplay: _propTypes.default.oneOf(['inline-block', 'block']),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-menu",
|
|
3
|
-
"version": "8.56.2
|
|
3
|
+
"version": "8.56.2",
|
|
4
4
|
"description": "A dropdown menu component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,29 +23,29 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-axe-check": "8.56.2
|
|
27
|
-
"@instructure/ui-babel-preset": "8.56.2
|
|
28
|
-
"@instructure/ui-color-utils": "8.56.2
|
|
29
|
-
"@instructure/ui-test-utils": "8.56.2
|
|
30
|
-
"@instructure/ui-themes": "8.56.2
|
|
26
|
+
"@instructure/ui-axe-check": "8.56.2",
|
|
27
|
+
"@instructure/ui-babel-preset": "8.56.2",
|
|
28
|
+
"@instructure/ui-color-utils": "8.56.2",
|
|
29
|
+
"@instructure/ui-test-utils": "8.56.2",
|
|
30
|
+
"@instructure/ui-themes": "8.56.2",
|
|
31
31
|
"@testing-library/jest-dom": "^6.1.4",
|
|
32
32
|
"@testing-library/react": "^14.0.0",
|
|
33
33
|
"@testing-library/user-event": "^14.5.1"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/runtime": "^7.23.2",
|
|
37
|
-
"@instructure/console": "8.56.2
|
|
38
|
-
"@instructure/emotion": "8.56.2
|
|
39
|
-
"@instructure/shared-types": "8.56.2
|
|
40
|
-
"@instructure/ui-a11y-utils": "8.56.2
|
|
41
|
-
"@instructure/ui-dom-utils": "8.56.2
|
|
42
|
-
"@instructure/ui-icons": "8.56.2
|
|
43
|
-
"@instructure/ui-popover": "8.56.2
|
|
44
|
-
"@instructure/ui-position": "8.56.2
|
|
45
|
-
"@instructure/ui-prop-types": "8.56.2
|
|
46
|
-
"@instructure/ui-react-utils": "8.56.2
|
|
47
|
-
"@instructure/ui-testable": "8.56.2
|
|
48
|
-
"@instructure/ui-utils": "8.56.2
|
|
37
|
+
"@instructure/console": "8.56.2",
|
|
38
|
+
"@instructure/emotion": "8.56.2",
|
|
39
|
+
"@instructure/shared-types": "8.56.2",
|
|
40
|
+
"@instructure/ui-a11y-utils": "8.56.2",
|
|
41
|
+
"@instructure/ui-dom-utils": "8.56.2",
|
|
42
|
+
"@instructure/ui-icons": "8.56.2",
|
|
43
|
+
"@instructure/ui-popover": "8.56.2",
|
|
44
|
+
"@instructure/ui-position": "8.56.2",
|
|
45
|
+
"@instructure/ui-prop-types": "8.56.2",
|
|
46
|
+
"@instructure/ui-react-utils": "8.56.2",
|
|
47
|
+
"@instructure/ui-testable": "8.56.2",
|
|
48
|
+
"@instructure/ui-utils": "8.56.2",
|
|
49
49
|
"keycode": "^2.2.1",
|
|
50
50
|
"prop-types": "^15.8.1"
|
|
51
51
|
},
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
/** @jsx jsx */
|
|
25
|
-
import React, { Component
|
|
25
|
+
import React, { Component } from 'react'
|
|
26
26
|
import keycode from 'keycode'
|
|
27
27
|
|
|
28
28
|
import { IconCheckSolid, IconArrowOpenEndSolid } from '@instructure/ui-icons'
|
|
@@ -253,7 +253,7 @@ class MenuItem extends Component<MenuItemProps, MenuItemState> {
|
|
|
253
253
|
: 'false'
|
|
254
254
|
: undefined
|
|
255
255
|
}
|
|
256
|
-
onClick={this.handleClick
|
|
256
|
+
onClick={this.handleClick}
|
|
257
257
|
onKeyUp={createChainedFunction(onKeyUp, this.handleKeyUp)}
|
|
258
258
|
onKeyDown={createChainedFunction(onKeyDown, this.handleKeyDown)}
|
|
259
259
|
ref={this.handleRef}
|
|
@@ -39,8 +39,8 @@ import type { ViewOwnProps } from '@instructure/ui-view'
|
|
|
39
39
|
|
|
40
40
|
type OnMenuItemSelect = (
|
|
41
41
|
e: React.MouseEvent<ViewOwnProps>,
|
|
42
|
-
value:
|
|
43
|
-
selected:
|
|
42
|
+
value: MenuItemProps['value'],
|
|
43
|
+
selected: MenuItemProps['selected'],
|
|
44
44
|
args: MenuItem
|
|
45
45
|
) => void
|
|
46
46
|
|
|
@@ -74,8 +74,20 @@ type MenuItemOwnProps = {
|
|
|
74
74
|
* the element type to render as (will default to `<a>` if href is provided)
|
|
75
75
|
*/
|
|
76
76
|
as?: AsElementType
|
|
77
|
+
/**
|
|
78
|
+
* How this component should be rendered. If it's `checkbox` or `radio` it will
|
|
79
|
+
* display a checkmark based on its own 'selected' state, if it's `flyout` it will
|
|
80
|
+
* render an arrow after the label.
|
|
81
|
+
*/
|
|
77
82
|
type?: 'button' | 'checkbox' | 'radio' | 'flyout'
|
|
83
|
+
/**
|
|
84
|
+
* Arbitrary value that you can store in this component. Is sent out by the
|
|
85
|
+
* `onSelect` event
|
|
86
|
+
*/
|
|
78
87
|
value?: string | number
|
|
88
|
+
/**
|
|
89
|
+
* Value of the `href` prop that will be put on the underlying DOM element.
|
|
90
|
+
*/
|
|
79
91
|
href?: string
|
|
80
92
|
}
|
|
81
93
|
|