@instructure/ui-menu 8.8.0 → 8.8.1-snapshot.63
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/LICENSE.md +27 -0
- package/es/Menu/MenuItem/index.js +14 -60
- package/es/Menu/MenuItem/props.js +67 -0
- package/es/Menu/MenuItemGroup/index.js +10 -57
- package/es/Menu/MenuItemGroup/props.js +71 -0
- package/es/Menu/MenuItemSeparator/index.js +5 -8
- package/{src/Menu/MenuItemSeparator/types.ts → es/Menu/MenuItemSeparator/props.js} +5 -5
- package/es/Menu/index.js +5 -151
- package/es/Menu/props.js +167 -0
- package/lib/Menu/MenuItem/index.js +15 -62
- package/lib/Menu/MenuItem/props.js +79 -0
- package/lib/Menu/MenuItemGroup/index.js +11 -62
- package/lib/Menu/MenuItemGroup/props.js +87 -0
- package/lib/Menu/MenuItemSeparator/index.js +6 -9
- package/{src/Menu/MenuItemGroup/types.ts → lib/Menu/MenuItemSeparator/props.js} +13 -16
- package/lib/Menu/index.js +6 -156
- package/lib/Menu/props.js +182 -0
- package/package.json +22 -21
- package/src/Menu/MenuItem/index.tsx +14 -56
- package/src/Menu/MenuItem/props.ts +109 -0
- package/src/Menu/MenuItem/styles.ts +1 -1
- package/src/Menu/MenuItem/theme.ts +1 -1
- package/src/Menu/MenuItemGroup/index.tsx +9 -56
- package/src/Menu/MenuItemGroup/props.ts +110 -0
- package/src/Menu/MenuItemGroup/theme.ts +1 -1
- package/src/Menu/MenuItemSeparator/index.tsx +6 -9
- package/src/Menu/{MenuItem/types.ts → MenuItemSeparator/props.ts} +19 -19
- package/src/Menu/MenuItemSeparator/theme.ts +1 -1
- package/src/Menu/index.tsx +6 -139
- package/src/Menu/props.ts +235 -0
- package/src/Menu/theme.ts +1 -1
- package/src/index.ts +4 -4
- package/types/Menu/MenuItem/index.d.ts +37 -45
- package/types/Menu/MenuItem/index.d.ts.map +1 -1
- package/types/Menu/MenuItem/props.d.ts +27 -0
- package/types/Menu/MenuItem/props.d.ts.map +1 -0
- package/types/Menu/MenuItem/styles.d.ts +1 -1
- package/types/Menu/MenuItem/theme.d.ts +1 -1
- package/types/Menu/MenuItem/theme.d.ts.map +1 -1
- package/types/Menu/MenuItemGroup/index.d.ts +29 -46
- package/types/Menu/MenuItemGroup/index.d.ts.map +1 -1
- package/types/Menu/MenuItemGroup/props.d.ts +25 -0
- package/types/Menu/MenuItemGroup/props.d.ts.map +1 -0
- package/types/Menu/MenuItemGroup/theme.d.ts +1 -1
- package/types/Menu/MenuItemGroup/theme.d.ts.map +1 -1
- package/types/Menu/MenuItemSeparator/index.d.ts +3 -6
- package/types/Menu/MenuItemSeparator/index.d.ts.map +1 -1
- package/types/Menu/MenuItemSeparator/props.d.ts +11 -0
- package/types/Menu/MenuItemSeparator/props.d.ts.map +1 -0
- package/types/Menu/MenuItemSeparator/theme.d.ts +1 -1
- package/types/Menu/MenuItemSeparator/theme.d.ts.map +1 -1
- package/types/Menu/index.d.ts +60 -122
- package/types/Menu/index.d.ts.map +1 -1
- package/types/Menu/{types.d.ts → props.d.ts} +13 -5
- package/types/Menu/props.d.ts.map +1 -0
- package/types/Menu/theme.d.ts +1 -1
- package/types/Menu/theme.d.ts.map +1 -1
- package/types/index.d.ts +4 -4
- package/es/Menu/MenuItem/types.js +0 -1
- package/es/Menu/MenuItemGroup/types.js +0 -1
- package/es/Menu/MenuItemSeparator/types.js +0 -1
- package/es/Menu/types.js +0 -1
- package/lib/Menu/MenuItem/types.js +0 -1
- package/lib/Menu/MenuItemGroup/types.js +0 -1
- package/lib/Menu/MenuItemSeparator/types.js +0 -1
- package/lib/Menu/types.js +0 -1
- package/src/Menu/types.ts +0 -63
- package/types/Menu/MenuItem/types.d.ts +0 -19
- package/types/Menu/MenuItem/types.d.ts.map +0 -1
- package/types/Menu/MenuItemGroup/types.d.ts +0 -17
- package/types/Menu/MenuItemGroup/types.d.ts.map +0 -1
- package/types/Menu/MenuItemSeparator/types.d.ts +0 -5
- package/types/Menu/MenuItemSeparator/types.d.ts.map +0 -1
- package/types/Menu/types.d.ts.map +0 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.allowedProps = exports.propTypes = void 0;
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _PositionPropTypes = require("@instructure/ui-position/lib/PositionPropTypes.js");
|
|
13
|
+
|
|
14
|
+
var _controllable = require("@instructure/ui-prop-types/lib/controllable.js");
|
|
15
|
+
|
|
16
|
+
var _Children = require("@instructure/ui-prop-types/lib/Children.js");
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* The MIT License (MIT)
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
22
|
+
*
|
|
23
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
24
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
25
|
+
* in the Software without restriction, including without limitation the rights
|
|
26
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
27
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
28
|
+
* furnished to do so, subject to the following conditions:
|
|
29
|
+
*
|
|
30
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
31
|
+
* copies or substantial portions of the Software.
|
|
32
|
+
*
|
|
33
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
36
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
37
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
38
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
39
|
+
* SOFTWARE.
|
|
40
|
+
*/
|
|
41
|
+
const propTypes = {
|
|
42
|
+
/**
|
|
43
|
+
* Children of type `Menu.Item`, `Menu.Group`, `Menu.Separator`, or `Menu`
|
|
44
|
+
*/
|
|
45
|
+
children: _Children.Children.oneOf(['MenuItem', 'MenuItemGroup', 'MenuItemSeparator', 'Menu']),
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Description of the `<Menu />`
|
|
49
|
+
*/
|
|
50
|
+
label: _propTypes.default.string,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Is the `<Menu />` disabled
|
|
54
|
+
*/
|
|
55
|
+
disabled: _propTypes.default.bool,
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The trigger element, if the `<Menu />` is to render as a popover
|
|
59
|
+
*/
|
|
60
|
+
trigger: _propTypes.default.node,
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* If a trigger is supplied, where should the `<Menu />` be placed (relative to the trigger)
|
|
64
|
+
*/
|
|
65
|
+
placement: _PositionPropTypes.PositionPropTypes.placement,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Should the `<Menu />` be open for the initial render
|
|
69
|
+
*/
|
|
70
|
+
defaultShow: _propTypes.default.bool,
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Is the `<Menu />` open (should be accompanied by `onToggle`)
|
|
74
|
+
*/
|
|
75
|
+
show: (0, _controllable.controllable)(_propTypes.default.bool, 'onToggle', 'defaultShow'),
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Callback fired when the `<Menu />` is toggled open/closed. When used with `show`,
|
|
79
|
+
* the component will not control its own state.
|
|
80
|
+
*/
|
|
81
|
+
onToggle: _propTypes.default.func,
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Callback fired when an item within the `<Menu />` is selected
|
|
85
|
+
*/
|
|
86
|
+
onSelect: _propTypes.default.func,
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* If a trigger is supplied, callback fired when the `<Menu />` is closed
|
|
90
|
+
*/
|
|
91
|
+
onDismiss: _propTypes.default.func,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* If a trigger is supplied, callback fired when the `<Menu />` trigger is blurred
|
|
95
|
+
*/
|
|
96
|
+
onBlur: _propTypes.default.func,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* If a trigger is supplied, callback fired when the `<Menu />` trigger is focused
|
|
100
|
+
*/
|
|
101
|
+
onFocus: _propTypes.default.func,
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* If a trigger is supplied, callback fired onMouseOver for the `<Menu />` trigger
|
|
105
|
+
*/
|
|
106
|
+
onMouseOver: _propTypes.default.func,
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Callback fired on the onKeyDown of the `<Menu />`
|
|
110
|
+
*/
|
|
111
|
+
onKeyDown: _propTypes.default.func,
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Callback fired on the onKeyUp of the `<Menu />`
|
|
115
|
+
*/
|
|
116
|
+
onKeyUp: _propTypes.default.func,
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A function that returns a reference to the `<Menu />`
|
|
120
|
+
*/
|
|
121
|
+
menuRef: _propTypes.default.func,
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A function that returns a reference to the `<Popover />`
|
|
125
|
+
*/
|
|
126
|
+
popoverRef: _propTypes.default.func,
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* If a trigger is supplied, an element or a function returning an element to use as the mount node
|
|
130
|
+
* for the `<Menu />` (defaults to `document.body`)
|
|
131
|
+
*/
|
|
132
|
+
mountNode: _PositionPropTypes.PositionPropTypes.mountNode,
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The parent in which to constrain the menu.
|
|
136
|
+
* One of: 'window', 'scroll-parent', 'parent', 'none', an element,
|
|
137
|
+
* or a function returning an element
|
|
138
|
+
*/
|
|
139
|
+
constrain: _PositionPropTypes.PositionPropTypes.constrain,
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* If a trigger is supplied, an element, function returning an element, or array of elements that will not
|
|
143
|
+
* be hidden from the screen reader when the `<Menu />` is open
|
|
144
|
+
*/
|
|
145
|
+
liveRegion: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.element), _propTypes.default.element, _propTypes.default.func]),
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* If a trigger is supplied, should the `<Menu />` hide when an item is selected
|
|
149
|
+
*/
|
|
150
|
+
shouldHideOnSelect: _propTypes.default.bool,
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* If a trigger is supplied, should the `<Menu />` focus the trigger on after closing
|
|
154
|
+
*/
|
|
155
|
+
shouldFocusTriggerOnClose: _propTypes.default.bool,
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The type of `<Menu />`
|
|
159
|
+
*/
|
|
160
|
+
type: _propTypes.default.oneOf(['flyout']),
|
|
161
|
+
id: _propTypes.default.string,
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Whether or not an arrow pointing to the trigger should be rendered
|
|
165
|
+
*/
|
|
166
|
+
withArrow: _propTypes.default.bool,
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The horizontal offset for the positioned content.
|
|
170
|
+
* Works only if `trigger` is provided.
|
|
171
|
+
*/
|
|
172
|
+
offsetX: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The vertical offset for the positioned content.
|
|
176
|
+
* Works only if `trigger` is provided.
|
|
177
|
+
*/
|
|
178
|
+
offsetY: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number])
|
|
179
|
+
};
|
|
180
|
+
exports.propTypes = propTypes;
|
|
181
|
+
const allowedProps = ['children', 'label', 'disabled', 'trigger', 'placement', 'defaultShow', 'show', 'onToggle', 'onSelect', 'onDismiss', 'onBlur', 'onFocus', 'onMouseOver', 'onKeyDown', 'onKeyUp', 'menuRef', 'popoverRef', 'mountNode', 'constrain', 'liveRegion', 'shouldHideOnSelect', 'shouldFocusTriggerOnClose', 'type', 'id', 'withArrow', 'offsetX', 'offsetY'];
|
|
182
|
+
exports.allowedProps = allowedProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-menu",
|
|
3
|
-
"version": "8.8.
|
|
3
|
+
"version": "8.8.1-snapshot.63+ec21bbc1d",
|
|
4
4
|
"description": "A dropdown menu component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -24,28 +24,28 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@instructure/
|
|
28
|
-
"@instructure/ui-
|
|
29
|
-
"@instructure/ui-
|
|
30
|
-
"@instructure/ui-test-
|
|
31
|
-
"@instructure/ui-test-
|
|
32
|
-
"@instructure/ui-
|
|
33
|
-
"@instructure/ui-themes": "8.8.0"
|
|
27
|
+
"@instructure/ui-babel-preset": "8.8.1-snapshot.63+ec21bbc1d",
|
|
28
|
+
"@instructure/ui-color-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
29
|
+
"@instructure/ui-test-locator": "8.8.1-snapshot.63+ec21bbc1d",
|
|
30
|
+
"@instructure/ui-test-queries": "8.8.1-snapshot.63+ec21bbc1d",
|
|
31
|
+
"@instructure/ui-test-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
32
|
+
"@instructure/ui-themes": "8.8.1-snapshot.63+ec21bbc1d"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"@babel/runtime": "^7.13.10",
|
|
37
|
-
"@instructure/console": "8.8.
|
|
38
|
-
"@instructure/emotion": "8.8.
|
|
39
|
-
"@instructure/
|
|
40
|
-
"@instructure/ui-
|
|
41
|
-
"@instructure/ui-
|
|
42
|
-
"@instructure/ui-
|
|
43
|
-
"@instructure/ui-
|
|
44
|
-
"@instructure/ui-
|
|
45
|
-
"@instructure/ui-
|
|
46
|
-
"@instructure/ui-
|
|
47
|
-
"@instructure/ui-
|
|
48
|
-
"@instructure/
|
|
36
|
+
"@instructure/console": "8.8.1-snapshot.63+ec21bbc1d",
|
|
37
|
+
"@instructure/emotion": "8.8.1-snapshot.63+ec21bbc1d",
|
|
38
|
+
"@instructure/shared-types": "8.8.1-snapshot.63+ec21bbc1d",
|
|
39
|
+
"@instructure/ui-a11y-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
40
|
+
"@instructure/ui-dom-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
41
|
+
"@instructure/ui-icons": "8.8.1-snapshot.63+ec21bbc1d",
|
|
42
|
+
"@instructure/ui-popover": "8.8.1-snapshot.63+ec21bbc1d",
|
|
43
|
+
"@instructure/ui-position": "8.8.1-snapshot.63+ec21bbc1d",
|
|
44
|
+
"@instructure/ui-prop-types": "8.8.1-snapshot.63+ec21bbc1d",
|
|
45
|
+
"@instructure/ui-react-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
46
|
+
"@instructure/ui-testable": "8.8.1-snapshot.63+ec21bbc1d",
|
|
47
|
+
"@instructure/ui-utils": "8.8.1-snapshot.63+ec21bbc1d",
|
|
48
|
+
"@instructure/uid": "8.8.1-snapshot.63+ec21bbc1d",
|
|
49
49
|
"keycode": "^2",
|
|
50
50
|
"prop-types": "^15"
|
|
51
51
|
},
|
|
@@ -55,5 +55,6 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
|
-
"sideEffects": false
|
|
58
|
+
"sideEffects": false,
|
|
59
|
+
"gitHead": "ec21bbc1dcdd8567b11f2c15f5fadd16709d7e3d"
|
|
59
60
|
}
|
|
@@ -23,12 +23,10 @@
|
|
|
23
23
|
*/
|
|
24
24
|
/** @jsx jsx */
|
|
25
25
|
import { Component } from 'react'
|
|
26
|
-
import PropTypes from 'prop-types'
|
|
27
26
|
import keycode from 'keycode'
|
|
28
27
|
|
|
29
28
|
import { IconCheckSolid, IconArrowOpenEndSolid } from '@instructure/ui-icons'
|
|
30
29
|
import { uid } from '@instructure/uid'
|
|
31
|
-
import { controllable } from '@instructure/ui-prop-types'
|
|
32
30
|
import { omitProps, getElementType } from '@instructure/ui-react-utils'
|
|
33
31
|
import { createChainedFunction } from '@instructure/ui-utils'
|
|
34
32
|
import { isActiveElement, findDOMNode } from '@instructure/ui-dom-utils'
|
|
@@ -39,7 +37,9 @@ import { MenuContext } from '../../MenuContext'
|
|
|
39
37
|
|
|
40
38
|
import generateStyle from './styles'
|
|
41
39
|
import generateComponentTheme from './theme'
|
|
42
|
-
|
|
40
|
+
|
|
41
|
+
import { propTypes, allowedProps } from './props'
|
|
42
|
+
import type { MenuItemProps } from './props'
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
---
|
|
@@ -52,56 +52,14 @@ id: Menu.Item
|
|
|
52
52
|
class MenuItem extends Component<MenuItemProps> {
|
|
53
53
|
static readonly componentId = 'Menu.Item'
|
|
54
54
|
|
|
55
|
-
static propTypes =
|
|
56
|
-
|
|
57
|
-
makeStyles: PropTypes.func,
|
|
58
|
-
// eslint-disable-next-line react/require-default-props
|
|
59
|
-
styles: PropTypes.object,
|
|
60
|
-
/* the menu item label */
|
|
61
|
-
children: PropTypes.node.isRequired,
|
|
62
|
-
/* whether to set the menu item state to selected or not on initial render */
|
|
63
|
-
defaultSelected: PropTypes.bool,
|
|
64
|
-
/**
|
|
65
|
-
* whether the menu item is selected or not (must be accompanied by an `onSelect` prop)
|
|
66
|
-
*/
|
|
67
|
-
selected: controllable(PropTypes.bool, 'onSelect', 'defaultSelected'),
|
|
68
|
-
/**
|
|
69
|
-
* when used with the `selected` prop, the component will not control its own state
|
|
70
|
-
*/
|
|
71
|
-
onSelect: PropTypes.func,
|
|
72
|
-
onClick: PropTypes.func,
|
|
73
|
-
onKeyDown: PropTypes.func,
|
|
74
|
-
onKeyUp: PropTypes.func,
|
|
75
|
-
onMouseOver: PropTypes.func,
|
|
76
|
-
/**
|
|
77
|
-
* the id of the element that the menu item will act upon
|
|
78
|
-
*/
|
|
79
|
-
controls: PropTypes.string,
|
|
80
|
-
disabled: PropTypes.bool,
|
|
81
|
-
/**
|
|
82
|
-
* the element type to render as (will default to `<a>` if href is provided)
|
|
83
|
-
*/
|
|
84
|
-
as: PropTypes.elementType, // eslint-disable-line react/require-default-props
|
|
85
|
-
type: PropTypes.oneOf(['button', 'checkbox', 'radio', 'flyout']),
|
|
86
|
-
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
87
|
-
href: PropTypes.string
|
|
88
|
-
}
|
|
89
|
-
|
|
55
|
+
static propTypes = propTypes
|
|
56
|
+
static allowedProps = allowedProps
|
|
90
57
|
static defaultProps = {
|
|
91
58
|
type: 'button',
|
|
92
59
|
disabled: false,
|
|
93
60
|
// @ts-expect-error ts-migrate(6133) FIXME: 'e' is declared but its value is never read.
|
|
94
|
-
onSelect: function (e, value, selected, item) {}
|
|
95
|
-
|
|
96
|
-
selected: undefined,
|
|
97
|
-
onClick: undefined,
|
|
98
|
-
onKeyDown: undefined,
|
|
99
|
-
onKeyUp: undefined,
|
|
100
|
-
onMouseOver: undefined,
|
|
101
|
-
controls: undefined,
|
|
102
|
-
value: undefined,
|
|
103
|
-
href: undefined
|
|
104
|
-
}
|
|
61
|
+
onSelect: function (e, value, selected, item) {}
|
|
62
|
+
} as const
|
|
105
63
|
|
|
106
64
|
static contextType = MenuContext
|
|
107
65
|
|
|
@@ -249,16 +207,16 @@ class MenuItem extends Component<MenuItemProps> {
|
|
|
249
207
|
return (
|
|
250
208
|
<span>
|
|
251
209
|
{(type === 'checkbox' || type === 'radio') && (
|
|
252
|
-
<span css={this.props.styles
|
|
210
|
+
<span css={this.props.styles?.icon}>
|
|
253
211
|
{this.selected && <IconCheckSolid />}
|
|
254
212
|
</span>
|
|
255
213
|
)}
|
|
256
214
|
{/* @ts-expect-error ts-migrate(2339) FIXME: Property 'labelId' does not exist on type 'MenuIte... Remove this comment to see the full error message */}
|
|
257
|
-
<span css={this.props.styles
|
|
215
|
+
<span css={this.props.styles?.label} id={this.labelId}>
|
|
258
216
|
{children}
|
|
259
217
|
</span>
|
|
260
218
|
{type === 'flyout' && (
|
|
261
|
-
<span css={this.props.styles
|
|
219
|
+
<span css={this.props.styles?.icon}>
|
|
262
220
|
<IconArrowOpenEndSolid />
|
|
263
221
|
</span>
|
|
264
222
|
)}
|
|
@@ -274,20 +232,20 @@ class MenuItem extends Component<MenuItemProps> {
|
|
|
274
232
|
|
|
275
233
|
return (
|
|
276
234
|
<ElementType // eslint-disable-line jsx-a11y/mouse-events-have-key-events
|
|
277
|
-
tabIndex=
|
|
235
|
+
tabIndex={-1} // note: tabIndex can be overridden by Menu or MenuItemGroup components
|
|
278
236
|
{...props}
|
|
279
237
|
href={href}
|
|
280
238
|
role={this.role}
|
|
281
239
|
// @ts-expect-error ts-migrate(2339) FIXME: Property 'labelId' does not exist on type 'MenuIte... Remove this comment to see the full error message
|
|
282
240
|
aria-labelledby={this.labelId}
|
|
283
|
-
aria-disabled={disabled ? 'true' :
|
|
241
|
+
aria-disabled={disabled ? 'true' : undefined}
|
|
284
242
|
aria-controls={controls}
|
|
285
243
|
aria-checked={
|
|
286
244
|
type === 'checkbox' || type === 'radio'
|
|
287
245
|
? this.selected
|
|
288
246
|
? 'true'
|
|
289
247
|
: 'false'
|
|
290
|
-
:
|
|
248
|
+
: undefined
|
|
291
249
|
}
|
|
292
250
|
onClick={this.handleClick}
|
|
293
251
|
onKeyUp={createChainedFunction(onKeyUp, this.handleKeyUp)}
|
|
@@ -297,7 +255,7 @@ class MenuItem extends Component<MenuItemProps> {
|
|
|
297
255
|
// @ts-expect-error ts-migrate(2339) FIXME: Property '_node' does not exist on type 'MenuItem'... Remove this comment to see the full error message
|
|
298
256
|
this._node = c
|
|
299
257
|
}}
|
|
300
|
-
css={this.props.styles
|
|
258
|
+
css={this.props.styles?.menuItem}
|
|
301
259
|
onMouseOver={this.handleMouseOver}
|
|
302
260
|
>
|
|
303
261
|
{this.renderContent()}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import PropTypes from 'prop-types'
|
|
27
|
+
|
|
28
|
+
import { controllable } from '@instructure/ui-prop-types'
|
|
29
|
+
|
|
30
|
+
import type { AsElementType, PropValidators } from '@instructure/shared-types'
|
|
31
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
|
32
|
+
|
|
33
|
+
type MenuItemOwnProps = {
|
|
34
|
+
children: React.ReactNode
|
|
35
|
+
defaultSelected?: boolean
|
|
36
|
+
selected?: any // TODO: controllable(PropTypes.bool, 'onSelect', 'defaultSelected')
|
|
37
|
+
onSelect?: (...args: any[]) => any
|
|
38
|
+
onClick?: (...args: any[]) => any
|
|
39
|
+
onKeyDown?: (...args: any[]) => any
|
|
40
|
+
onKeyUp?: (...args: any[]) => any
|
|
41
|
+
onMouseOver?: (...args: any[]) => any
|
|
42
|
+
controls?: string
|
|
43
|
+
disabled?: boolean
|
|
44
|
+
as?: AsElementType
|
|
45
|
+
type?: 'button' | 'checkbox' | 'radio' | 'flyout'
|
|
46
|
+
value?: string | number
|
|
47
|
+
href?: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type PropKeys = keyof MenuItemOwnProps
|
|
51
|
+
|
|
52
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
53
|
+
|
|
54
|
+
type MenuItemProps = MenuItemOwnProps & WithStyleProps
|
|
55
|
+
|
|
56
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
57
|
+
/**
|
|
58
|
+
* the menu item label
|
|
59
|
+
*/
|
|
60
|
+
children: PropTypes.node.isRequired,
|
|
61
|
+
/**
|
|
62
|
+
* whether to set the menu item state to selected or not on initial render
|
|
63
|
+
*/
|
|
64
|
+
defaultSelected: PropTypes.bool,
|
|
65
|
+
/**
|
|
66
|
+
* whether the menu item is selected or not (must be accompanied by an `onSelect` prop)
|
|
67
|
+
*/
|
|
68
|
+
selected: controllable(PropTypes.bool, 'onSelect', 'defaultSelected'),
|
|
69
|
+
/**
|
|
70
|
+
* when used with the `selected` prop, the component will not control its own state
|
|
71
|
+
*/
|
|
72
|
+
onSelect: PropTypes.func,
|
|
73
|
+
onClick: PropTypes.func,
|
|
74
|
+
onKeyDown: PropTypes.func,
|
|
75
|
+
onKeyUp: PropTypes.func,
|
|
76
|
+
onMouseOver: PropTypes.func,
|
|
77
|
+
/**
|
|
78
|
+
* the id of the element that the menu item will act upon
|
|
79
|
+
*/
|
|
80
|
+
controls: PropTypes.string,
|
|
81
|
+
disabled: PropTypes.bool,
|
|
82
|
+
/**
|
|
83
|
+
* the element type to render as (will default to `<a>` if href is provided)
|
|
84
|
+
*/
|
|
85
|
+
as: PropTypes.elementType, // eslint-disable-line react/require-default-props
|
|
86
|
+
type: PropTypes.oneOf(['button', 'checkbox', 'radio', 'flyout']),
|
|
87
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
88
|
+
href: PropTypes.string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const allowedProps: AllowedPropKeys = [
|
|
92
|
+
'children',
|
|
93
|
+
'defaultSelected',
|
|
94
|
+
'selected',
|
|
95
|
+
'onSelect',
|
|
96
|
+
'onClick',
|
|
97
|
+
'onKeyDown',
|
|
98
|
+
'onKeyUp',
|
|
99
|
+
'onMouseOver',
|
|
100
|
+
'controls',
|
|
101
|
+
'disabled',
|
|
102
|
+
'as',
|
|
103
|
+
'type',
|
|
104
|
+
'value',
|
|
105
|
+
'href'
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
export type { MenuItemProps }
|
|
109
|
+
export { propTypes, allowedProps }
|