Skip to content

Commit 9f98306

Browse files
authored
feat: Hooks and API simplifications (#288)
BREAKING CHANGE: removes RootCloseWrapper for useRootClose
1 parent 2e80864 commit 9f98306

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+8856
-6052
lines changed

.eslintrc

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,8 @@
11
{
2-
"extends": [
3-
"eslint:recommended",
4-
"plugin:react/recommended",
5-
"prettier",
6-
"prettier/react"
7-
],
8-
"env": {
9-
"es6": true,
10-
"browser": true,
11-
"node": true
12-
},
13-
"parser": "babel-eslint",
14-
"plugins": ["react"],
2+
"extends": ["@react-bootstrap"],
3+
"plugins": ["prettier"],
154
"rules": {
16-
"comma-spacing": "error",
17-
"comma-style": ["error", "last"],
18-
"no-var": "error",
19-
"one-var": ["error", { "initialized": "never" }],
20-
"quotes": ["error", "single", "avoid-escape"],
21-
"space-infix-ops": "error",
22-
"strict": ["error", "never"],
23-
"react/no-find-dom-node": "off",
24-
"react/jsx-boolean-value": ["error", "never"],
25-
"react/jsx-wrap-multilines": "error",
26-
"react/prop-types": [
27-
"error",
28-
{
29-
"ignore": ["children", "className"]
30-
}
31-
],
32-
"react/self-closing-comp": "error",
33-
"no-unused-vars": [
34-
"error",
35-
{
36-
"vars": "all",
37-
"args": "after-used",
38-
"varsIgnorePattern": "^_",
39-
"argsIgnorePattern": "^_"
40-
}
41-
]
5+
"prettier/prettier": "error",
6+
"jsx-a11y/no-autofocus": "off"
427
}
438
}

karma.conf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { rules, plugins } = require('webpack-atoms')
1+
const { rules, plugins } = require('webpack-atoms');
22

33
module.exports = config => {
4-
const { env } = process
4+
const { env } = process;
55

66
config.set({
77
frameworks: ['mocha', 'sinon-chai'],
@@ -49,5 +49,5 @@ module.exports = config => {
4949
},
5050

5151
browsers: env.BROWSER ? env.BROWSER.split(',') : ['Chrome'],
52-
})
53-
}
52+
});
53+
};

package.json

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,44 @@
5151
"conventionalCommits": true
5252
},
5353
"dependencies": {
54+
"@restart/hooks": "^0.2.12",
5455
"classnames": "^2.2.6",
5556
"dom-helpers": "^3.4.0",
56-
"prop-types": "^15.6.2",
57+
"prop-types": "^15.7.2",
5758
"prop-types-extra": "^1.1.0",
58-
"react-context-toolbox": "^2.0.2",
59-
"react-popper": "^1.3.2",
60-
"uncontrollable": "^6.0.0",
61-
"warning": "^4.0.2"
59+
"react-popper": "^1.3.3",
60+
"uncontrollable": "^6.1.0",
61+
"warning": "^4.0.3"
6262
},
6363
"peerDependencies": {
6464
"react": ">=16.3.0",
6565
"react-dom": ">=16.3.0"
6666
},
6767
"devDependencies": {
68-
"@4c/rollout": "^1.2.0",
69-
"@babel/cli": "^7.2.3",
70-
"@babel/core": "^7.2.2",
71-
"@babel/plugin-proposal-class-properties": "^7.3.0",
72-
"@babel/polyfill": "^7.2.5",
73-
"@babel/preset-env": "^7.3.1",
68+
"@4c/rollout": "^1.3.5",
69+
"@babel/cli": "^7.4.4",
70+
"@babel/core": "^7.4.4",
71+
"@babel/plugin-proposal-class-properties": "^7.4.4",
72+
"@babel/polyfill": "^7.4.4",
73+
"@babel/preset-env": "^7.4.4",
7474
"@babel/preset-react": "^7.0.0",
75+
"@emotion/core": "^10.0.9",
76+
"@react-bootstrap/eslint-config": "^1.2.0",
7577
"babel-eslint": "^10.0.1",
76-
"babel-plugin-add-module-exports": "^1.0.0",
77-
"babel-plugin-istanbul": "^5.1.0",
78+
"babel-plugin-add-module-exports": "^1.0.2",
79+
"babel-plugin-istanbul": "^5.1.4",
7880
"chai": "^4.2.0",
7981
"codecov": "^3.2.0",
80-
"enzyme": "^3.8.0",
81-
"enzyme-adapter-react-16": "^1.9.1",
82-
"eslint": "^5.13.0",
83-
"eslint-config-prettier": "^4.0.0",
82+
"enzyme": "^3.9.0",
83+
"enzyme-adapter-react-16": "^1.13.0",
84+
"eslint": "^5.16.0",
85+
"eslint-config-prettier": "^4.2.0",
86+
"eslint-plugin-import": "^2.17.2",
87+
"eslint-plugin-jsx-a11y": "^6.2.1",
8488
"eslint-plugin-mocha": "^5.3.0",
85-
"eslint-plugin-react": "^7.12.4",
89+
"eslint-plugin-prettier": "^3.1.0",
90+
"eslint-plugin-react": "^7.13.0",
91+
"eslint-plugin-react-hooks": "^1.6.0",
8692
"gh-pages": "^2.0.1",
8793
"husky": "^1.3.1",
8894
"jquery": "^3.3.1",
@@ -98,9 +104,8 @@
98104
"lodash": "^4.17.11",
99105
"mocha": "^5.2.0",
100106
"prettier": "^1.16.4",
101-
"react": "^16.8.2",
102-
"react-bootstrap": "^0.32.4",
103-
"react-dom": "^16.8.2",
107+
"react": "^16.8.6",
108+
"react-dom": "^16.8.6",
104109
"react-live": "^1.12.0",
105110
"react-transition-group": "^2.5.3",
106111
"rimraf": "^2.6.3",

src/Dropdown.js

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ class Dropdown extends React.Component {
104104
};
105105
}
106106

107-
constructor(props, context) {
108-
super(props, context);
107+
constructor(...args) {
108+
super(...args);
109109

110110
this._focusInDropdown = false;
111111

@@ -159,36 +159,6 @@ class Dropdown extends React.Component {
159159
return items[index];
160160
}
161161

162-
hasMenuRole() {
163-
return this.menu && matches(this.menu, '[role=menu]');
164-
}
165-
166-
focus() {
167-
const { toggleNode } = this.state.context;
168-
if (toggleNode && toggleNode.focus) {
169-
toggleNode.focus();
170-
}
171-
}
172-
173-
maybeFocusFirst() {
174-
const type = this._lastSourceEvent;
175-
let { focusFirstItemOnShow } = this.props;
176-
if (focusFirstItemOnShow == null) {
177-
focusFirstItemOnShow = this.hasMenuRole() ? 'keyboard' : false;
178-
}
179-
180-
if (
181-
focusFirstItemOnShow === false ||
182-
(focusFirstItemOnShow === 'keyboard' && !/^key.+$/.test(type))
183-
) {
184-
return;
185-
}
186-
187-
const { itemSelector } = this.props;
188-
let first = qsa(this.menu, itemSelector)[0];
189-
if (first && first.focus) first.focus();
190-
}
191-
192162
handleClick = event => {
193163
this.toggleOpen(event);
194164
};
@@ -234,6 +204,36 @@ class Dropdown extends React.Component {
234204
}
235205
};
236206

207+
hasMenuRole() {
208+
return this.menu && matches(this.menu, '[role=menu]');
209+
}
210+
211+
focus() {
212+
const { toggleNode } = this.state.context;
213+
if (toggleNode && toggleNode.focus) {
214+
toggleNode.focus();
215+
}
216+
}
217+
218+
maybeFocusFirst() {
219+
const type = this._lastSourceEvent;
220+
let { focusFirstItemOnShow } = this.props;
221+
if (focusFirstItemOnShow == null) {
222+
focusFirstItemOnShow = this.hasMenuRole() ? 'keyboard' : false;
223+
}
224+
225+
if (
226+
focusFirstItemOnShow === false ||
227+
(focusFirstItemOnShow === 'keyboard' && !/^key.+$/.test(type))
228+
) {
229+
return;
230+
}
231+
232+
const { itemSelector } = this.props;
233+
let first = qsa(this.menu, itemSelector)[0];
234+
if (first && first.focus) first.focus();
235+
}
236+
237237
toggleOpen(event) {
238238
let show = !this.props.show;
239239

src/DropdownContext.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React from 'react';
22

33
const DropdownContext = React.createContext({
44
menuRef() {},
@@ -8,6 +8,6 @@ const DropdownContext = React.createContext({
88
alignEnd: null,
99
show: null,
1010
drop: null,
11-
})
11+
});
1212

13-
export default DropdownContext
13+
export default DropdownContext;

0 commit comments

Comments
 (0)