react-aria-menubutton 7.0.2 → 8.0.0
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/README.md +140 -122
- package/dist/index.d.ts +59 -0
- package/dist/react-aria-menubutton.cjs.js +1 -0
- package/dist/react-aria-menubutton.es.js +566 -0
- package/dist/react-aria-menubutton.umd.js +1 -0
- package/package.json +62 -57
- package/CHANGELOG.md +0 -173
- package/CODE_OF_CONDUCT.md +0 -22
- package/dist/Button.js +0 -140
- package/dist/ManagerContext.js +0 -7
- package/dist/Menu.js +0 -131
- package/dist/MenuItem.js +0 -96
- package/dist/Wrapper.js +0 -66
- package/dist/createManager.js +0 -154
- package/dist/externalStateControl.js +0 -32
- package/dist/index.js +0 -12
- package/dist/propTypes.js +0 -7
- package/dist/specialAssign.js +0 -11
- package/src/Button.js +0 -129
- package/src/ManagerContext.js +0 -5
- package/src/Menu.js +0 -118
- package/src/MenuItem.js +0 -84
- package/src/Wrapper.js +0 -54
- package/src/__tests__/Button.test.js +0 -169
- package/src/__tests__/Menu.test.js +0 -130
- package/src/__tests__/MenuItem.test.js +0 -106
- package/src/__tests__/__snapshots__/Button.test.js.snap +0 -41
- package/src/__tests__/__snapshots__/Menu.test.js.snap +0 -54
- package/src/__tests__/__snapshots__/MenuItem.test.js.snap +0 -37
- package/src/__tests__/createManager.test.js +0 -190
- package/src/__tests__/helpers/MockWrapper.js +0 -24
- package/src/__tests__/helpers/createMockKeyEvent.js +0 -7
- package/src/__tests__/helpers/createMockManager.js +0 -22
- package/src/__tests__/helpers/jest-setup.js +0 -5
- package/src/__tests__/helpers/raf.js +0 -3
- package/src/createManager.js +0 -162
- package/src/externalStateControl.js +0 -31
- package/src/index.js +0 -10
- package/src/propTypes.js +0 -8
- package/src/specialAssign.js +0 -9
- package/umd/ReactAriaMenuButton.js +0 -1
- package/webpack-demo.config.js +0 -14
- package/webpack-umd.config.js +0 -35
package/package.json
CHANGED
|
@@ -1,21 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-aria-menubutton",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "A fully accessible and flexible React-powered menu button",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/react-aria-menubutton.cjs.js",
|
|
7
|
+
"module": "dist/react-aria-menubutton.es.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/react-aria-menubutton.es.js",
|
|
13
|
+
"require": "./dist/react-aria-menubutton.cjs.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
6
23
|
"scripts": {
|
|
7
24
|
"lint": "eslint .",
|
|
8
|
-
"
|
|
9
|
-
"demo-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"test": "
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
25
|
+
"start": "vite",
|
|
26
|
+
"demo-build": "vite build",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"test:coverage": "vitest run --coverage",
|
|
30
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\" \"demo/js/*.{ts,tsx}\"",
|
|
31
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx}\" \"demo/js/*.{ts,tsx}\"",
|
|
32
|
+
"build": "vite build -c vite.lib.config.ts",
|
|
33
|
+
"prepare": "husky install",
|
|
34
|
+
"prepublishOnly": "npm run build",
|
|
35
|
+
"typecheck": "tsc",
|
|
36
|
+
"start:dist": "npm run build && vite -c vite.demo-dist.config.ts"
|
|
19
37
|
},
|
|
20
38
|
"husky": {
|
|
21
39
|
"hooks": {
|
|
@@ -23,7 +41,10 @@
|
|
|
23
41
|
}
|
|
24
42
|
},
|
|
25
43
|
"lint-staged": {
|
|
26
|
-
"*.
|
|
44
|
+
"*.{ts,tsx}": [
|
|
45
|
+
"eslint",
|
|
46
|
+
"prettier --check"
|
|
47
|
+
]
|
|
27
48
|
},
|
|
28
49
|
"repository": {
|
|
29
50
|
"type": "git",
|
|
@@ -51,54 +72,38 @@
|
|
|
51
72
|
],
|
|
52
73
|
"dependencies": {
|
|
53
74
|
"focus-group": "^0.3.1",
|
|
54
|
-
"prop-types": "^15.6.0",
|
|
55
75
|
"teeny-tap": "^0.2.0"
|
|
56
76
|
},
|
|
57
77
|
"peerDependencies": {
|
|
58
|
-
"react": "^16.3.0 || ^17.0.0"
|
|
78
|
+
"react": "^16.3.0 || ^17.0.0 || ^18.0.0"
|
|
59
79
|
},
|
|
60
80
|
"devDependencies": {
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"eslint": "^
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
81
|
+
"@eslint/js": "^9.28.0",
|
|
82
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
83
|
+
"@testing-library/react": "^14.3.1",
|
|
84
|
+
"@testing-library/user-event": "^14.6.1",
|
|
85
|
+
"@types/node": "^25.0.8",
|
|
86
|
+
"@types/react": "^18.3.23",
|
|
87
|
+
"@types/react-dom": "^18.3.7",
|
|
88
|
+
"@types/react-transition-group": "^4.4.12",
|
|
89
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
90
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
91
|
+
"eslint": "^9.28.0",
|
|
92
|
+
"eslint-config-prettier": "^10.1.5",
|
|
93
|
+
"eslint-plugin-react": "^7.37.5",
|
|
94
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
95
|
+
"husky": "^8.0.0",
|
|
96
|
+
"jiti": "^2.6.1",
|
|
97
|
+
"jsdom": "^26.1.0",
|
|
75
98
|
"lint-staged": "^8.2.1",
|
|
76
|
-
"prettier": "^
|
|
77
|
-
"react": "^
|
|
78
|
-
"react-dom": "^
|
|
79
|
-
"react-
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
"react",
|
|
86
|
-
[
|
|
87
|
-
"env",
|
|
88
|
-
{
|
|
89
|
-
"loose": true
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
],
|
|
93
|
-
"plugins": [
|
|
94
|
-
"transform-class-properties"
|
|
95
|
-
]
|
|
96
|
-
},
|
|
97
|
-
"jest": {
|
|
98
|
-
"setupFiles": [
|
|
99
|
-
"./src/__tests__/helpers/jest-setup.js"
|
|
100
|
-
],
|
|
101
|
-
"testRegex": "/__tests__/.*\\.test.js$",
|
|
102
|
-
"clearMocks": true
|
|
99
|
+
"prettier": "^3.5.3",
|
|
100
|
+
"react": "^18.3.1",
|
|
101
|
+
"react-dom": "^18.3.1",
|
|
102
|
+
"react-transition-group": "^4.4.5",
|
|
103
|
+
"typescript": "^5.7.3",
|
|
104
|
+
"typescript-eslint": "^8.34.0",
|
|
105
|
+
"vite": "^7.2.6",
|
|
106
|
+
"vite-plugin-dts": "^4.5.4",
|
|
107
|
+
"vitest": "^3.2.4"
|
|
103
108
|
}
|
|
104
109
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 7.0.2
|
|
4
|
-
- Fix blur handler breaking due to unavailability of button
|
|
5
|
-
|
|
6
|
-
## 7.0.1
|
|
7
|
-
- Added React v17+ in peer dependency
|
|
8
|
-
|
|
9
|
-
## 7.0.0
|
|
10
|
-
- **Breaking:** Removed usage of `ReactDOM.findDOMNode` and `create-react-context`. This will no longer support older versions of React, it now requires `^16.3.0`
|
|
11
|
-
|
|
12
|
-
## 6.3.0
|
|
13
|
-
- Removed usage of legacy React context API, the package now use `create-react-context` which uses new context API if available else fallsback to the legacy API.
|
|
14
|
-
|
|
15
|
-
## 6.2.0
|
|
16
|
-
|
|
17
|
-
- Bind `Home` key to jump to first item in the current menu.
|
|
18
|
-
- Bind `End` key to jump to the last item in the current menu.
|
|
19
|
-
- Removed use of deprecated React lifecycle methods.
|
|
20
|
-
|
|
21
|
-
## 6.1.0
|
|
22
|
-
|
|
23
|
-
- Add `closeOnBlur` prop.
|
|
24
|
-
|
|
25
|
-
## 6.0.1
|
|
26
|
-
|
|
27
|
-
- Chore: Use loose mode for Babel compilation.
|
|
28
|
-
|
|
29
|
-
## 6.0.0
|
|
30
|
-
|
|
31
|
-
- **Breaking:** Pass `disabled` attribute to `Button` component's inner element if it is a regular HTML element that supports `disabled`.
|
|
32
|
-
Considered a potentially breaking (though positive) change because it may affect behavior and styling of your UI.
|
|
33
|
-
|
|
34
|
-
## 5.1.1
|
|
35
|
-
|
|
36
|
-
- Fix keydown behavior of link menu items, so Enter and Space open the link the same way a click does.
|
|
37
|
-
- Make prop `onSelection` optional, because it's not necessary if your menu items are link.
|
|
38
|
-
|
|
39
|
-
## 5.1.0
|
|
40
|
-
|
|
41
|
-
- React 16 support.
|
|
42
|
-
|
|
43
|
-
## 5.0.2
|
|
44
|
-
|
|
45
|
-
- Satisfy React deprecation warnings.
|
|
46
|
-
|
|
47
|
-
## 5.0.1
|
|
48
|
-
|
|
49
|
-
- Clicks inside the menu that are not on a `MenuItem` move focus to the first `MenuItem`.
|
|
50
|
-
- When the menu opens, focus only moves to the first menu item *if you opened with keyboard interactions*.
|
|
51
|
-
With a mouse click on the trigger, for example, focus remains on the trigger.
|
|
52
|
-
|
|
53
|
-
## 5.0.0
|
|
54
|
-
|
|
55
|
-
- When the menu opens, move focus to the first item (by default).
|
|
56
|
-
This represents a change to [the WAI-ARIA Menu Button Design Pattern](http://www.w3.org/TR/wai-aria-practices/#menubutton).
|
|
57
|
-
|
|
58
|
-
## 4.3.1
|
|
59
|
-
|
|
60
|
-
- Introduce `dist/`, where `src/` now compiles to, since React 15.5+ demands `class`es, so Babel-compilation.
|
|
61
|
-
Which is actually a huge overhaul, though in semver it's just a patch.
|
|
62
|
-
|
|
63
|
-
## 4.3.0
|
|
64
|
-
|
|
65
|
-
- Add `onMenuToggle` prop to `Wrapper`.
|
|
66
|
-
|
|
67
|
-
## 4.2.0
|
|
68
|
-
|
|
69
|
-
- Use `ownerDocument` instead of `document.documentElement` in case this is used in an iframe.
|
|
70
|
-
- Rewrite test suite using Jest.
|
|
71
|
-
|
|
72
|
-
## 4.1.3
|
|
73
|
-
|
|
74
|
-
- Fix UMD build.
|
|
75
|
-
|
|
76
|
-
## 4.1.2
|
|
77
|
-
|
|
78
|
-
- Allow React 15 as a `peerDependency`.
|
|
79
|
-
|
|
80
|
-
## 4.1.1
|
|
81
|
-
|
|
82
|
-
- Update UMD build.
|
|
83
|
-
|
|
84
|
-
## 4.1.0
|
|
85
|
-
|
|
86
|
-
- Add `openMenu()` and `closeMenu()` to API.
|
|
87
|
-
- Improve (fix) UMD build.
|
|
88
|
-
- Allow arbitrary props to pass through to Button, Menu, MenuItem, and Wrapper elements.
|
|
89
|
-
|
|
90
|
-
## 4.0.2
|
|
91
|
-
|
|
92
|
-
- Move `react` and `react-dom` to peer dependencies.
|
|
93
|
-
|
|
94
|
-
## 4.0.1
|
|
95
|
-
|
|
96
|
-
- Update `focus-group` due to important fix there.
|
|
97
|
-
|
|
98
|
-
## 4.0.0
|
|
99
|
-
|
|
100
|
-
- Use `focus-group` for focus management, which includes improving letter navigation.
|
|
101
|
-
- Switch from `tap.js` to `teeny-tap`.
|
|
102
|
-
- Move UMD build to `umd/` directory that is only distributed with the npm package (available on unpkg).
|
|
103
|
-
|
|
104
|
-
## 3.1.0
|
|
105
|
-
|
|
106
|
-
- Add `disabled` prop to `Button`.
|
|
107
|
-
|
|
108
|
-
## 3.0.0
|
|
109
|
-
|
|
110
|
-
- Upgrade to React 0.14.
|
|
111
|
-
- Use React's `context` to simplify API.
|
|
112
|
-
- Add `<Wrapper>` component (replacing the need for the factory function `ariaMenuButton()`).
|
|
113
|
-
- Add `style` prop to all components.
|
|
114
|
-
|
|
115
|
-
## 2.0.4 and 2.0.5
|
|
116
|
-
|
|
117
|
-
- Better cleanup of Tap.js listeners.
|
|
118
|
-
- Key code 91 is not a letter so I should stop treating it like one.
|
|
119
|
-
|
|
120
|
-
## 2.0.2 and 2.0.3
|
|
121
|
-
|
|
122
|
-
- Avoid presuming that `document` exists, to avoid breaking `React.renderToString()`.
|
|
123
|
-
|
|
124
|
-
## 2.0.1
|
|
125
|
-
|
|
126
|
-
- Allow for the case that selecting a menu item unmounts the menu (mostly by manager timers more intelligently).
|
|
127
|
-
|
|
128
|
-
## 2.0.0
|
|
129
|
-
|
|
130
|
-
- Ignore letter key presses if the letter is paired with `alt`, `ctrl`, or `meta` keys.
|
|
131
|
-
- Use [tap.js](https://github.com/alexgibson/tap.js) to improve click-outside-closes behavior: no overlay required anymore, meaning that a click outside can *both* close the menu *and* do something else — with both mouse and touch events.
|
|
132
|
-
|
|
133
|
-
## 1.1.0
|
|
134
|
-
|
|
135
|
-
- Allow objects as MenuItem `value`s.
|
|
136
|
-
|
|
137
|
-
## 1.0.0
|
|
138
|
-
|
|
139
|
-
- Nothing really: it was just time to start the real versioning.
|
|
140
|
-
|
|
141
|
-
## 0.8.0
|
|
142
|
-
- Overlay to enable close-when-clicking-outside for mobile.
|
|
143
|
-
|
|
144
|
-
## 0.7.0
|
|
145
|
-
- New, more flexible API: provided components are just wrappers around whatever elements they're given.
|
|
146
|
-
|
|
147
|
-
## 0.6.0
|
|
148
|
-
- Pass `event` to `handleSelection`.
|
|
149
|
-
|
|
150
|
-
## 0.5.2
|
|
151
|
-
- Add keywords to `package.json`.
|
|
152
|
-
|
|
153
|
-
## 0.5.1
|
|
154
|
-
- Update build.
|
|
155
|
-
|
|
156
|
-
## 0.5.0
|
|
157
|
-
- Make class names a little more explicit (change `menuWrapper--trans` to `menuWrapper--transition` and `li` to `menuItemWrapper`).
|
|
158
|
-
- Add `transition` option to factory and remove `transition` prop from component.
|
|
159
|
-
|
|
160
|
-
## 0.4.0
|
|
161
|
-
- Options to customize css classes' component name and namespace.
|
|
162
|
-
- Remove the need to pass in React by distinguishing `dist-modules/` with (transpiled) CommonJS modules and `dist/` with a UMD library that expects React to be global.
|
|
163
|
-
- Switch from browserify to webpack for JS module compilation.
|
|
164
|
-
|
|
165
|
-
## 0.3.0
|
|
166
|
-
- Remove `classnames` dependency.
|
|
167
|
-
|
|
168
|
-
## 0.2.0
|
|
169
|
-
- Add `dist-modules` for modular consumption.
|
|
170
|
-
- Upgrade dependencies.
|
|
171
|
-
|
|
172
|
-
## 0.1.0
|
|
173
|
-
- Initial release.
|
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Contributor Code of Conduct
|
|
2
|
-
|
|
3
|
-
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
|
4
|
-
|
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
|
|
6
|
-
|
|
7
|
-
Examples of unacceptable behavior by participants include:
|
|
8
|
-
|
|
9
|
-
* The use of sexualized language or imagery
|
|
10
|
-
* Personal attacks
|
|
11
|
-
* Trolling or insulting/derogatory comments
|
|
12
|
-
* Public or private harassment
|
|
13
|
-
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
|
|
14
|
-
* Other unethical or unprofessional conduct.
|
|
15
|
-
|
|
16
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
|
|
17
|
-
|
|
18
|
-
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
|
|
19
|
-
|
|
20
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
|
21
|
-
|
|
22
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
|
package/dist/Button.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
-
|
|
5
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
6
|
-
|
|
7
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
8
|
-
|
|
9
|
-
var React = require('react');
|
|
10
|
-
var PropTypes = require('prop-types');
|
|
11
|
-
var ManagerContext = require('./ManagerContext');
|
|
12
|
-
|
|
13
|
-
var _require = require("./propTypes"),
|
|
14
|
-
refType = _require.refType;
|
|
15
|
-
|
|
16
|
-
var specialAssign = require('./specialAssign');
|
|
17
|
-
|
|
18
|
-
var checkedProps = {
|
|
19
|
-
ambManager: PropTypes.object.isRequired,
|
|
20
|
-
children: PropTypes.node.isRequired,
|
|
21
|
-
disabled: PropTypes.bool,
|
|
22
|
-
forwardedRef: refType,
|
|
23
|
-
tag: PropTypes.string
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// List retrieved from https://www.w3schools.com/tags/att_disabled.asp
|
|
27
|
-
var disabledSupportedTags = function disabledSupportedTags() {
|
|
28
|
-
return ['button', 'fieldset', 'input', 'optgroup', 'option', 'select', 'textarea'];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var AriaMenuButtonButton = function (_React$Component) {
|
|
32
|
-
_inherits(AriaMenuButtonButton, _React$Component);
|
|
33
|
-
|
|
34
|
-
function AriaMenuButtonButton() {
|
|
35
|
-
var _temp, _this, _ret;
|
|
36
|
-
|
|
37
|
-
_classCallCheck(this, AriaMenuButtonButton);
|
|
38
|
-
|
|
39
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
40
|
-
args[_key] = arguments[_key];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.ref = React.createRef(), _this.handleKeyDown = function (event) {
|
|
44
|
-
if (_this.props.disabled) return;
|
|
45
|
-
|
|
46
|
-
var ambManager = _this.props.ambManager;
|
|
47
|
-
|
|
48
|
-
switch (event.key) {
|
|
49
|
-
case 'ArrowDown':
|
|
50
|
-
event.preventDefault();
|
|
51
|
-
if (!ambManager.isOpen) {
|
|
52
|
-
ambManager.openMenu();
|
|
53
|
-
} else {
|
|
54
|
-
ambManager.focusItem(0);
|
|
55
|
-
}
|
|
56
|
-
break;
|
|
57
|
-
case 'Enter':
|
|
58
|
-
case ' ':
|
|
59
|
-
event.preventDefault();
|
|
60
|
-
ambManager.toggleMenu();
|
|
61
|
-
break;
|
|
62
|
-
case 'Escape':
|
|
63
|
-
ambManager.handleMenuKey(event);
|
|
64
|
-
break;
|
|
65
|
-
default:
|
|
66
|
-
// (Potential) letter keys
|
|
67
|
-
ambManager.handleButtonNonArrowKey(event);
|
|
68
|
-
}
|
|
69
|
-
}, _this.handleClick = function () {
|
|
70
|
-
if (_this.props.disabled) return;
|
|
71
|
-
_this.props.ambManager.toggleMenu({}, { focusMenu: false });
|
|
72
|
-
}, _this.setRef = function (instance) {
|
|
73
|
-
_this.ref.current = instance;
|
|
74
|
-
if (typeof _this.props.forwardedRef === "function") {
|
|
75
|
-
_this.props.forwardedRef(instance);
|
|
76
|
-
} else if (_this.props.forwardedRef) {
|
|
77
|
-
_this.props.forwardedRef.current = instance;
|
|
78
|
-
}
|
|
79
|
-
}, _temp), _possibleConstructorReturn(_this, _ret);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
AriaMenuButtonButton.prototype.componentDidMount = function componentDidMount() {
|
|
83
|
-
this.props.ambManager.button = this;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
AriaMenuButtonButton.prototype.componentWillUnmount = function componentWillUnmount() {
|
|
87
|
-
this.props.ambManager.destroy();
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
AriaMenuButtonButton.prototype.render = function render() {
|
|
91
|
-
var props = this.props;
|
|
92
|
-
var ambManager = this.props.ambManager;
|
|
93
|
-
|
|
94
|
-
var buttonProps = {
|
|
95
|
-
// "The menu button itself has a role of button."
|
|
96
|
-
role: 'button',
|
|
97
|
-
tabIndex: props.disabled ? '' : '0',
|
|
98
|
-
// "The menu button has an aria-haspopup property, set to true."
|
|
99
|
-
'aria-haspopup': true,
|
|
100
|
-
'aria-expanded': ambManager.isOpen,
|
|
101
|
-
'aria-disabled': props.disabled,
|
|
102
|
-
onKeyDown: this.handleKeyDown,
|
|
103
|
-
onClick: this.handleClick
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
var reserved = {};
|
|
107
|
-
specialAssign(reserved, checkedProps);
|
|
108
|
-
// The disabled property should be passed down to the Button element
|
|
109
|
-
// if the tag has support for disabled attribute. So it needs to be removed
|
|
110
|
-
// from the reserved property object
|
|
111
|
-
if (disabledSupportedTags().indexOf(props.tag) >= 0) {
|
|
112
|
-
delete reserved.disabled;
|
|
113
|
-
}
|
|
114
|
-
if (ambManager.options.closeOnBlur) {
|
|
115
|
-
buttonProps.onBlur = ambManager.handleBlur;
|
|
116
|
-
}
|
|
117
|
-
specialAssign(buttonProps, props, reserved);
|
|
118
|
-
specialAssign(buttonProps, { ref: this.setRef });
|
|
119
|
-
|
|
120
|
-
return React.createElement(props.tag, buttonProps, props.children);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
return AriaMenuButtonButton;
|
|
124
|
-
}(React.Component);
|
|
125
|
-
|
|
126
|
-
AriaMenuButtonButton.propTypes = checkedProps;
|
|
127
|
-
AriaMenuButtonButton.defaultProps = { tag: 'span' };
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
module.exports = React.forwardRef(function (props, ref) {
|
|
131
|
-
return React.createElement(ManagerContext.Consumer, null, function (ambManager) {
|
|
132
|
-
var buttonProps = { ambManager: ambManager, forwardedRef: ref };
|
|
133
|
-
specialAssign(buttonProps, props, {
|
|
134
|
-
ambManager: checkedProps.ambManager,
|
|
135
|
-
children: checkedProps.children,
|
|
136
|
-
forwardedRef: checkedProps.forwardedRef
|
|
137
|
-
});
|
|
138
|
-
return React.createElement(AriaMenuButtonButton, buttonProps, props.children);
|
|
139
|
-
});
|
|
140
|
-
});
|
package/dist/ManagerContext.js
DELETED
package/dist/Menu.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
-
|
|
5
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
6
|
-
|
|
7
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
8
|
-
|
|
9
|
-
var React = require('react');
|
|
10
|
-
var PropTypes = require('prop-types');
|
|
11
|
-
var createTapListener = require('teeny-tap');
|
|
12
|
-
var ManagerContext = require('./ManagerContext');
|
|
13
|
-
|
|
14
|
-
var _require = require("./propTypes"),
|
|
15
|
-
refType = _require.refType;
|
|
16
|
-
|
|
17
|
-
var specialAssign = require('./specialAssign');
|
|
18
|
-
|
|
19
|
-
var checkedProps = {
|
|
20
|
-
ambManager: PropTypes.object.isRequired,
|
|
21
|
-
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired,
|
|
22
|
-
forwardedRef: refType,
|
|
23
|
-
tag: PropTypes.string
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
var AriaMenuButtonMenu = function (_React$Component) {
|
|
27
|
-
_inherits(AriaMenuButtonMenu, _React$Component);
|
|
28
|
-
|
|
29
|
-
function AriaMenuButtonMenu() {
|
|
30
|
-
var _temp, _this, _ret;
|
|
31
|
-
|
|
32
|
-
_classCallCheck(this, AriaMenuButtonMenu);
|
|
33
|
-
|
|
34
|
-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
35
|
-
args[_key] = arguments[_key];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.ref = React.createRef(), _this.addTapListener = function () {
|
|
39
|
-
var el = _this.ref.current;
|
|
40
|
-
if (!el) return;
|
|
41
|
-
var doc = el.ownerDocument;
|
|
42
|
-
if (!doc) return;
|
|
43
|
-
_this.tapListener = createTapListener(doc.documentElement, _this.handleTap);
|
|
44
|
-
}, _this.handleTap = function (event) {
|
|
45
|
-
if (_this.ref.current.contains(event.target)) return;
|
|
46
|
-
if (_this.props.ambManager.button.ref.current.contains(event.target)) return;
|
|
47
|
-
_this.props.ambManager.closeMenu();
|
|
48
|
-
}, _this.setRef = function (instance) {
|
|
49
|
-
_this.ref.current = instance;
|
|
50
|
-
if (typeof _this.props.forwardedRef === "function") {
|
|
51
|
-
_this.props.forwardedRef(instance);
|
|
52
|
-
} else if (_this.props.forwardedRef) {
|
|
53
|
-
_this.props.forwardedRef.current = instance;
|
|
54
|
-
}
|
|
55
|
-
}, _temp), _possibleConstructorReturn(_this, _ret);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
AriaMenuButtonMenu.prototype.componentDidMount = function componentDidMount() {
|
|
59
|
-
this.props.ambManager.menu = this;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
AriaMenuButtonMenu.prototype.componentDidUpdate = function componentDidUpdate() {
|
|
63
|
-
var ambManager = this.props.ambManager;
|
|
64
|
-
if (!ambManager.options.closeOnBlur) return;
|
|
65
|
-
if (ambManager.isOpen && !this.tapListener) {
|
|
66
|
-
this.addTapListener();
|
|
67
|
-
} else if (!ambManager.isOpen && this.tapListener) {
|
|
68
|
-
this.tapListener.remove();
|
|
69
|
-
delete this.tapListener;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!ambManager.isOpen) {
|
|
73
|
-
// Clear the ambManager's items, so they
|
|
74
|
-
// can be reloaded next time this menu opens
|
|
75
|
-
ambManager.clearItems();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
AriaMenuButtonMenu.prototype.componentWillUnmount = function componentWillUnmount() {
|
|
80
|
-
if (this.tapListener) this.tapListener.remove();
|
|
81
|
-
this.props.ambManager.destroy();
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
AriaMenuButtonMenu.prototype.render = function render() {
|
|
85
|
-
var props = this.props;
|
|
86
|
-
var ambManager = this.props.ambManager;
|
|
87
|
-
|
|
88
|
-
var childrenToRender = function () {
|
|
89
|
-
if (typeof props.children === 'function') {
|
|
90
|
-
return props.children({ isOpen: ambManager.isOpen });
|
|
91
|
-
}
|
|
92
|
-
if (ambManager.isOpen) return props.children;
|
|
93
|
-
return false;
|
|
94
|
-
}();
|
|
95
|
-
|
|
96
|
-
if (!childrenToRender) return false;
|
|
97
|
-
|
|
98
|
-
var menuProps = {
|
|
99
|
-
onKeyDown: ambManager.handleMenuKey,
|
|
100
|
-
role: 'menu',
|
|
101
|
-
tabIndex: -1
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
if (ambManager.options.closeOnBlur) {
|
|
105
|
-
menuProps.onBlur = ambManager.handleBlur;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
specialAssign(menuProps, props, checkedProps);
|
|
109
|
-
specialAssign(menuProps, { ref: this.setRef });
|
|
110
|
-
|
|
111
|
-
return React.createElement(props.tag, menuProps, childrenToRender);
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
return AriaMenuButtonMenu;
|
|
115
|
-
}(React.Component);
|
|
116
|
-
|
|
117
|
-
AriaMenuButtonMenu.propTypes = checkedProps;
|
|
118
|
-
AriaMenuButtonMenu.defaultProps = { tag: 'div' };
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
module.exports = React.forwardRef(function (props, ref) {
|
|
122
|
-
return React.createElement(ManagerContext.Consumer, null, function (ambManager) {
|
|
123
|
-
var buttonProps = { ambManager: ambManager, forwardedRef: ref };
|
|
124
|
-
specialAssign(buttonProps, props, {
|
|
125
|
-
ambManager: checkedProps.ambManager,
|
|
126
|
-
children: checkedProps.children,
|
|
127
|
-
forwardedRef: checkedProps.forwardedRef
|
|
128
|
-
});
|
|
129
|
-
return React.createElement(AriaMenuButtonMenu, buttonProps, props.children);
|
|
130
|
-
});
|
|
131
|
-
});
|