focus-trap-react 3.1.0 → 3.1.4
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 +16 -0
- package/dist/focus-trap-react.js +9 -17
- package/index.d.ts +8 -8
- package/package.json +6 -1
- package/src/focus-trap-react.js +3 -1
- package/.eslintignore +0 -1
- package/.eslintrc +0 -20
- package/.travis.yml +0 -8
- package/CODE_OF_CONDUCT.md +0 -22
- package/demo/index.html +0 -74
- package/demo/js/demo-five.js +0 -61
- package/demo/js/demo-four.js +0 -76
- package/demo/js/demo-one.js +0 -68
- package/demo/js/demo-three.js +0 -72
- package/demo/js/demo-two.js +0 -75
- package/demo/js/index.js +0 -5
- package/demo/style.css +0 -28
- package/index.js +0 -95
- package/test/activation.test.js +0 -145
- package/test/deactivation.test.js +0 -103
- package/test/dom.test.js +0 -67
- package/test/jest-setup.js +0 -3
- package/yarn.lock +0 -4697
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.1.4
|
|
4
|
+
|
|
5
|
+
- Re-add TypeScript declarations.
|
|
6
|
+
|
|
7
|
+
## 3.1.3
|
|
8
|
+
|
|
9
|
+
- Remove `componentWillMount` usage.
|
|
10
|
+
|
|
11
|
+
## 3.1.2
|
|
12
|
+
|
|
13
|
+
- Fix TypeScript declarations so props are available on the imported namespace.
|
|
14
|
+
|
|
15
|
+
## 3.1.1
|
|
16
|
+
|
|
17
|
+
- Fix React import in TypeScript declarations.
|
|
18
|
+
|
|
3
19
|
## 3.1.0
|
|
4
20
|
|
|
5
21
|
- Add TypeScript declarations.
|
package/dist/focus-trap-react.js
CHANGED
|
@@ -16,30 +16,22 @@ var checkedProps = ['active', 'paused', 'tag', 'focusTrapOptions', '_createFocus
|
|
|
16
16
|
var FocusTrap = function (_React$Component) {
|
|
17
17
|
_inherits(FocusTrap, _React$Component);
|
|
18
18
|
|
|
19
|
-
function FocusTrap() {
|
|
20
|
-
var _ref;
|
|
21
|
-
|
|
22
|
-
var _temp, _this, _ret;
|
|
23
|
-
|
|
19
|
+
function FocusTrap(props) {
|
|
24
20
|
_classCallCheck(this, FocusTrap);
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
args[_key] = arguments[_key];
|
|
28
|
-
}
|
|
22
|
+
var _this = _possibleConstructorReturn(this, (FocusTrap.__proto__ || Object.getPrototypeOf(FocusTrap)).call(this, props));
|
|
29
23
|
|
|
30
|
-
|
|
24
|
+
_this.setNode = function (el) {
|
|
31
25
|
_this.node = el;
|
|
32
|
-
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (typeof document !== 'undefined') {
|
|
29
|
+
_this.previouslyFocusedElement = document.activeElement;
|
|
30
|
+
}
|
|
31
|
+
return _this;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
_createClass(FocusTrap, [{
|
|
36
|
-
key: 'componentWillMount',
|
|
37
|
-
value: function componentWillMount() {
|
|
38
|
-
if (typeof document !== 'undefined') {
|
|
39
|
-
this.previouslyFocusedElement = document.activeElement;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}, {
|
|
43
35
|
key: 'componentDidMount',
|
|
44
36
|
value: function componentDidMount() {
|
|
45
37
|
// We need to hijack the returnFocusOnDeactivate option,
|
package/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import React from "react";
|
|
1
|
+
import { Options as FocusTrapOptions } from 'focus-trap';
|
|
2
|
+
import * as React from 'react';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export = FocusTrap;
|
|
5
|
+
|
|
6
|
+
declare namespace FocusTrap {
|
|
7
7
|
export interface Props extends React.AllHTMLAttributes<any> {
|
|
8
8
|
active?: boolean;
|
|
9
9
|
paused?: boolean;
|
|
10
10
|
tag?: string;
|
|
11
11
|
focusTrapOptions?: FocusTrapOptions;
|
|
12
12
|
// Allow through any properties that weren't picked up
|
|
13
|
-
[
|
|
13
|
+
[prop: string]: any;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
export default class FocusTrap extends React.Component<Props> {}
|
|
17
15
|
}
|
|
16
|
+
|
|
17
|
+
declare class FocusTrap extends React.Component<FocusTrap.Props> {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "focus-trap-react",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
4
4
|
"description": "A React component that traps focus.",
|
|
5
5
|
"main": "dist/focus-trap-react.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "git+https://github.com/davidtheclark/focus-trap-react.git"
|
|
21
21
|
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src",
|
|
25
|
+
"index.d.ts"
|
|
26
|
+
],
|
|
22
27
|
"keywords": [
|
|
23
28
|
"react",
|
|
24
29
|
"reactjs",
|
package/src/focus-trap-react.js
CHANGED
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
**/*-bundle.js
|
package/.eslintrc
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"parser": "babel-eslint",
|
|
3
|
-
"extends": "eslint:recommended",
|
|
4
|
-
"plugins": ["react"],
|
|
5
|
-
"env": {
|
|
6
|
-
"es6": true,
|
|
7
|
-
"node": true,
|
|
8
|
-
"browser": true,
|
|
9
|
-
"jest": true
|
|
10
|
-
},
|
|
11
|
-
"parserOptions": {
|
|
12
|
-
"ecmaFeatures": {
|
|
13
|
-
"jsx": true
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"rules": {
|
|
17
|
-
"react/jsx-uses-react": "error",
|
|
18
|
-
"react/jsx-uses-vars": "error"
|
|
19
|
-
}
|
|
20
|
-
}
|
package/.travis.yml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
language: node_js
|
|
2
|
-
node_js:
|
|
3
|
-
- 'stable'
|
|
4
|
-
cache: yarn
|
|
5
|
-
env:
|
|
6
|
-
global:
|
|
7
|
-
- secure: ApBNjenv66nLPxp+7ItGahjaNN9yoCPutzkYKt9VjfMha5W/wcYwDfZfAhuiKreOFrjJYngfsXTsYM3Uta+ydHi++vcbvo6phfkN7gzWA/EIvezyIoLNkjPzM7+qbpId+od+1l5nztwcuUHAvwG0QwDFLWT6D0AkFT+sXLtQvNKWq34fPqL/KN3Yd456+ecwtPm5/KfnG/nCNRQbMqF4zt/+AJCNZz+ySRNqdkXFYpwGhR4NpdTxla/7X5Uhd7Q7jKRkuN1WiuFhKsqg/ff4U52zxkUAG6qnxVNIffvKB1mpnxmEHI2CVFH1eJlc+U/jsGZvEgkvEEKUyV7+zWGO2t+yR11222XUXnkOq2kIpLb1odhxDd6tz8wrI7iWyrcWfH8W8CITHQ2s4D51KLwKGXbP+Ym1OsMSjewwkT17L03+LMhEwgSO/i9svJfcXk3jwQkaBCqnkK+lBHTs2hsgHMRGTjoFyK30aAJj+rDDaWd6i/Za1Q15J7ziyF79PzKowjfxJsWNma/FhsgtRL/Kyiipg60FSaDgaIXbgW7SZTZpoqda64BuSua23HMt2CD9oZ4FInic+9DbiSZxFu8iPpuGaCuSM6E+Mv2JlXzOkqLlx+GOgnjY4t1SGNgCx84iVEGXzYwKLFts3/KxAxhxewQ4iyhcI37xZP96Htd9lBA=
|
|
8
|
-
- secure: PFibzoXNOxfwRZGx/Qf4tCfY7Zlu1njTA/ya7D7mPHJ+iOPROYRgPBxsdo3nYAbG09bfMIXs5iarQ+29dwDbbtmVbD0eeWV5eHID4cgfAQAYB2ltRZY8is6zVg3RQ53F+ECVzsArHzlvUEbrWbckxUQb51tRVMKHRie9R+wGkoAe8qU36BUqSIHEt/Cu2Wah6yvG+ulmB3bqMPuOVfGQQI74x7xpTajEY+U81N/A5gzeYvlzSMygHgt2HRCIatSJCrGA6ddwoTMKOQo2ncCyXDFjgYuIF8t4DCxNfYc20TypuGaAPmPKICtH6G+H9Do88VnPXebLDdfqxNTfF2HCx38gxYmMzrc3kHEScn8zShS8POonPG+qoEMAmY6Q17ZUarmSsNpp2qYic7H2CGL43AwvnGU+hmFYdxFg4P02LDbSS5xMKCvZrFml+Ck73pTn+etmxAjrpwt4sQ4Rsfte12zDWBecj51aGdpVVo18q4ZuZmYlQkH96vjJTYE1OYyOCAeC9mtUzXAeJX5Dlmwa4BhWOCOXUqxtKaxWa1sANFHR3sLsesVxiVQN3NAj0uD5dPBZ/qYfXTWm3qOutKE6sqWKionJ0al9zb1NNw1uMVnOzsStbCtbsNhsQ7iYTl5KfbGj7U/HnTkApnylZjzVLOPVelmDjWVMKuW3iSTMRO0=
|
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/demo/index.html
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
7
|
-
<title>focus-trap-react demo</title>
|
|
8
|
-
|
|
9
|
-
<link rel="stylesheet" href="style.css">
|
|
10
|
-
<meta name="description" content="A demo of focus-trap-react">
|
|
11
|
-
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<h1 tabindex="0">focus-trap-react demo</h1>
|
|
15
|
-
|
|
16
|
-
<p>
|
|
17
|
-
<span style="font-size:2em;vertical-align:middle;">☜</span>
|
|
18
|
-
<a href="https://github.com/davidtheclark/focus-trap-react" style="vertical-align:middle;">Return to the repository</a>
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
|
-
<h2>demo one</h2>
|
|
22
|
-
<p>
|
|
23
|
-
Default behavior: When this FocusTrap mounts (and activates), the first element in its tab order receives focus.
|
|
24
|
-
</p>
|
|
25
|
-
<div id="demo-one"></div>
|
|
26
|
-
|
|
27
|
-
<h2>demo two</h2>
|
|
28
|
-
<p>
|
|
29
|
-
When this FocusTrap mounts (and activates), focus jumps to a specific, manually specified element.
|
|
30
|
-
</p>
|
|
31
|
-
<p>
|
|
32
|
-
Also, the Escape key does not deactivate this trap: you have to click the button to deactivate.
|
|
33
|
-
</p>
|
|
34
|
-
<div id="demo-two"></div>
|
|
35
|
-
|
|
36
|
-
<h2>demo three</h2>
|
|
37
|
-
<p>
|
|
38
|
-
Inspect this element and you'll see that is not the default plan div,
|
|
39
|
-
but rather a section tag with an id, a class, inline styles, and an
|
|
40
|
-
arbitrary <code>data-</code>attribute.
|
|
41
|
-
</p>
|
|
42
|
-
<p>
|
|
43
|
-
Also, this FocusTrap activates and deactivates while staying mounted.
|
|
44
|
-
</p>
|
|
45
|
-
<p>
|
|
46
|
-
ALSO, when you click outside this FocusTrap, the trap deactivates and your click carries through.
|
|
47
|
-
</p>
|
|
48
|
-
<div id="demo-three"></div>
|
|
49
|
-
|
|
50
|
-
<h2>demo four</h2>
|
|
51
|
-
<p>
|
|
52
|
-
Default behavior with a twist:
|
|
53
|
-
When this FocusTrap activates, the first element in its tab order receives focus,
|
|
54
|
-
<em>but because of positive tabindex attributes the tab order is not the same as the source order</em>.
|
|
55
|
-
</p>
|
|
56
|
-
<p>
|
|
57
|
-
Also, when you deactivate this FocusTrap, the focus will not be returned to the button that activated it.
|
|
58
|
-
</p>
|
|
59
|
-
<div id="demo-four"></div>
|
|
60
|
-
|
|
61
|
-
<h2>demo five</h2>
|
|
62
|
-
<p>
|
|
63
|
-
The trap contains an input with the autofocus attribute.
|
|
64
|
-
</p>
|
|
65
|
-
<div id="demo-five"></div>
|
|
66
|
-
|
|
67
|
-
<p>
|
|
68
|
-
<span style="font-size:2em;vertical-align:middle;">☜</span>
|
|
69
|
-
<a href="https://github.com/davidtheclark/focus-trap-react" style="vertical-align:middle;">Return to the repository</a>
|
|
70
|
-
</p>
|
|
71
|
-
|
|
72
|
-
<script src="demo-bundle.js"></script>
|
|
73
|
-
</body>
|
|
74
|
-
</html>
|
package/demo/js/demo-five.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
const React = require('react');
|
|
2
|
-
const ReactDOM = require('react-dom');
|
|
3
|
-
const FocusTrap = require('../../dist/focus-trap-react');
|
|
4
|
-
|
|
5
|
-
const container = document.getElementById('demo-five');
|
|
6
|
-
|
|
7
|
-
class DemoFive extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
|
|
11
|
-
this.state = {
|
|
12
|
-
activeTrap: false
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
this.mountTrap = this.mountTrap.bind(this);
|
|
16
|
-
this.unmountTrap = this.unmountTrap.bind(this);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
mountTrap() {
|
|
20
|
-
this.setState({ activeTrap: true });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
unmountTrap() {
|
|
24
|
-
this.setState({ activeTrap: false });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
render() {
|
|
28
|
-
const trap = this.state.activeTrap
|
|
29
|
-
? <FocusTrap
|
|
30
|
-
focusTrapOptions={{
|
|
31
|
-
onDeactivate: this.unmountTrap
|
|
32
|
-
}}
|
|
33
|
-
>
|
|
34
|
-
<div className="trap">
|
|
35
|
-
<button onClick={this.unmountTrap}>
|
|
36
|
-
deactivate trap
|
|
37
|
-
</button>
|
|
38
|
-
<div>
|
|
39
|
-
<a href="#">Another focusable thing</a>
|
|
40
|
-
</div>
|
|
41
|
-
<div>
|
|
42
|
-
Autofocused input: <input autoFocus={true} />
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
</FocusTrap>
|
|
46
|
-
: false;
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<div>
|
|
50
|
-
<p>
|
|
51
|
-
<button key="button" onClick={this.mountTrap}>
|
|
52
|
-
activate trap
|
|
53
|
-
</button>
|
|
54
|
-
</p>
|
|
55
|
-
{trap}
|
|
56
|
-
</div>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
ReactDOM.render(<DemoFive />, container);
|
package/demo/js/demo-four.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
const React = require('react');
|
|
2
|
-
const ReactDOM = require('react-dom');
|
|
3
|
-
const FocusTrap = require('../../dist/focus-trap-react');
|
|
4
|
-
|
|
5
|
-
const container = document.getElementById('demo-four');
|
|
6
|
-
|
|
7
|
-
class DemoFour extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
|
|
11
|
-
this.state = {
|
|
12
|
-
activeTrap: false
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
this.mountTrap = this.mountTrap.bind(this);
|
|
16
|
-
this.unmountTrap = this.unmountTrap.bind(this);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
mountTrap() {
|
|
20
|
-
this.setState({ activeTrap: true });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
unmountTrap() {
|
|
24
|
-
this.setState({ activeTrap: false });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
render() {
|
|
28
|
-
const trap = this.state.activeTrap
|
|
29
|
-
? <FocusTrap
|
|
30
|
-
className="trap"
|
|
31
|
-
focusTrapOptions={{
|
|
32
|
-
onDeactivate: this.unmountTrap,
|
|
33
|
-
returnFocusOnDeactivate: false
|
|
34
|
-
}}
|
|
35
|
-
>
|
|
36
|
-
<p>
|
|
37
|
-
<button tabIndex="3">
|
|
38
|
-
tabindex 3
|
|
39
|
-
</button>
|
|
40
|
-
</p>
|
|
41
|
-
<p>
|
|
42
|
-
<button tabIndex="2">
|
|
43
|
-
tabindex 2
|
|
44
|
-
</button>
|
|
45
|
-
</p>
|
|
46
|
-
<p>
|
|
47
|
-
<button tabIndex="4">tabindex 4</button>
|
|
48
|
-
</p>
|
|
49
|
-
<p>
|
|
50
|
-
<button>no tabindex</button>
|
|
51
|
-
</p>
|
|
52
|
-
<p>
|
|
53
|
-
<button onClick={this.unmountTrap} tabIndex="1">
|
|
54
|
-
deactivate trap (tabindex 1)
|
|
55
|
-
</button>
|
|
56
|
-
</p>
|
|
57
|
-
</FocusTrap>
|
|
58
|
-
: false;
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<div>
|
|
62
|
-
<p>
|
|
63
|
-
<button onClick={this.mountTrap}>
|
|
64
|
-
activate trap
|
|
65
|
-
</button>
|
|
66
|
-
</p>
|
|
67
|
-
<p>
|
|
68
|
-
<a href="#">other focusable element</a>
|
|
69
|
-
</p>
|
|
70
|
-
{trap}
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
ReactDOM.render(<DemoFour />, container);
|
package/demo/js/demo-one.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
const React = require('react');
|
|
2
|
-
const ReactDOM = require('react-dom');
|
|
3
|
-
const FocusTrap = require('../../dist/focus-trap-react');
|
|
4
|
-
|
|
5
|
-
const container = document.getElementById('demo-one');
|
|
6
|
-
|
|
7
|
-
class DemoOne extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
|
|
11
|
-
this.state = {
|
|
12
|
-
activeTrap: false
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
this.mountTrap = this.mountTrap.bind(this);
|
|
16
|
-
this.unmountTrap = this.unmountTrap.bind(this);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
mountTrap() {
|
|
20
|
-
this.setState({ activeTrap: true });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
unmountTrap() {
|
|
24
|
-
this.setState({ activeTrap: false });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
render() {
|
|
28
|
-
const trap = this.state.activeTrap
|
|
29
|
-
? <FocusTrap
|
|
30
|
-
focusTrapOptions={{
|
|
31
|
-
onDeactivate: this.unmountTrap
|
|
32
|
-
}}
|
|
33
|
-
>
|
|
34
|
-
<div className="trap">
|
|
35
|
-
<p>
|
|
36
|
-
Here is a focus trap
|
|
37
|
-
{' '}
|
|
38
|
-
<a href="#">with</a>
|
|
39
|
-
{' '}
|
|
40
|
-
<a href="#">some</a>
|
|
41
|
-
{' '}
|
|
42
|
-
<a href="#">focusable</a>
|
|
43
|
-
{' '}
|
|
44
|
-
parts.
|
|
45
|
-
</p>
|
|
46
|
-
<p>
|
|
47
|
-
<button onClick={this.unmountTrap}>
|
|
48
|
-
deactivate trap
|
|
49
|
-
</button>
|
|
50
|
-
</p>
|
|
51
|
-
</div>
|
|
52
|
-
</FocusTrap>
|
|
53
|
-
: false;
|
|
54
|
-
|
|
55
|
-
return (
|
|
56
|
-
<div>
|
|
57
|
-
<p>
|
|
58
|
-
<button onClick={this.mountTrap}>
|
|
59
|
-
activate trap
|
|
60
|
-
</button>
|
|
61
|
-
</p>
|
|
62
|
-
{trap}
|
|
63
|
-
</div>
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
ReactDOM.render(<DemoOne />, container);
|
package/demo/js/demo-three.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
const React = require('react');
|
|
2
|
-
const ReactDOM = require('react-dom');
|
|
3
|
-
const FocusTrap = require('../../dist/focus-trap-react');
|
|
4
|
-
|
|
5
|
-
const container = document.getElementById('demo-three');
|
|
6
|
-
|
|
7
|
-
class DemoThree extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
|
|
11
|
-
this.state = {
|
|
12
|
-
activeTrap: false
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
this.mountTrap = this.mountTrap.bind(this);
|
|
16
|
-
this.unmountTrap = this.unmountTrap.bind(this);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
mountTrap() {
|
|
20
|
-
this.setState({ activeTrap: true });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
unmountTrap() {
|
|
24
|
-
this.setState({ activeTrap: false });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
render() {
|
|
28
|
-
let trapClass = 'trap';
|
|
29
|
-
if (this.state.activeTrap) trapClass += ' is-active';
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div>
|
|
33
|
-
<p>
|
|
34
|
-
<button onClick={this.mountTrap}>
|
|
35
|
-
activate trap
|
|
36
|
-
</button>
|
|
37
|
-
</p>
|
|
38
|
-
<FocusTrap
|
|
39
|
-
id="focus-trap-three"
|
|
40
|
-
tag="section"
|
|
41
|
-
style={{ background: '#eee' }}
|
|
42
|
-
data-whatever="nothing"
|
|
43
|
-
active={this.state.activeTrap}
|
|
44
|
-
className={trapClass}
|
|
45
|
-
focusTrapOptions={{
|
|
46
|
-
onDeactivate: this.unmountTrap,
|
|
47
|
-
clickOutsideDeactivates: true
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
50
|
-
<p>
|
|
51
|
-
Here is a focus trap
|
|
52
|
-
{' '}
|
|
53
|
-
<a href="#">with</a>
|
|
54
|
-
{' '}
|
|
55
|
-
<a href="#">some</a>
|
|
56
|
-
{' '}
|
|
57
|
-
<a href="#">focusable</a>
|
|
58
|
-
{' '}
|
|
59
|
-
parts.
|
|
60
|
-
</p>
|
|
61
|
-
<p>
|
|
62
|
-
<button onClick={this.unmountTrap}>
|
|
63
|
-
deactivate trap
|
|
64
|
-
</button>
|
|
65
|
-
</p>
|
|
66
|
-
</FocusTrap>
|
|
67
|
-
</div>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
ReactDOM.render(<DemoThree />, container);
|
package/demo/js/demo-two.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
const React = require('react');
|
|
2
|
-
const ReactDOM = require('react-dom');
|
|
3
|
-
const FocusTrap = require('../../dist/focus-trap-react');
|
|
4
|
-
|
|
5
|
-
const container = document.getElementById('demo-two');
|
|
6
|
-
|
|
7
|
-
class DemoTwo extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
|
|
11
|
-
this.state = {
|
|
12
|
-
activeTrap: false
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
this.mountTrap = this.mountTrap.bind(this);
|
|
16
|
-
this.unmountTrap = this.unmountTrap.bind(this);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
mountTrap() {
|
|
20
|
-
this.setState({ activeTrap: true });
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
unmountTrap() {
|
|
24
|
-
this.setState({ activeTrap: false });
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
render() {
|
|
28
|
-
const trap = this.state.activeTrap
|
|
29
|
-
? <FocusTrap
|
|
30
|
-
className="trap"
|
|
31
|
-
focusTrapOptions={{
|
|
32
|
-
onDeactivate: this.unmountTrap,
|
|
33
|
-
initialFocus: '#focused-input',
|
|
34
|
-
escapeDeactivates: false
|
|
35
|
-
}}
|
|
36
|
-
>
|
|
37
|
-
<p>
|
|
38
|
-
Here is a focus trap
|
|
39
|
-
{' '}
|
|
40
|
-
<a href="#">with</a>
|
|
41
|
-
{' '}
|
|
42
|
-
<a href="#">some</a>
|
|
43
|
-
{' '}
|
|
44
|
-
<a href="#">focusable</a>
|
|
45
|
-
{' '}
|
|
46
|
-
parts.
|
|
47
|
-
</p>
|
|
48
|
-
<p>
|
|
49
|
-
<label htmlFor="focused-input" style={{ marginRight: 10 }}>
|
|
50
|
-
Initially focused input
|
|
51
|
-
</label>
|
|
52
|
-
<input ref="input" id="focused-input" />
|
|
53
|
-
</p>
|
|
54
|
-
<p>
|
|
55
|
-
<button onClick={this.unmountTrap}>
|
|
56
|
-
deactivate trap
|
|
57
|
-
</button>
|
|
58
|
-
</p>
|
|
59
|
-
</FocusTrap>
|
|
60
|
-
: false;
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<div>
|
|
64
|
-
<p>
|
|
65
|
-
<button onClick={this.mountTrap}>
|
|
66
|
-
activate trap
|
|
67
|
-
</button>
|
|
68
|
-
</p>
|
|
69
|
-
{trap}
|
|
70
|
-
</div>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
ReactDOM.render(<DemoTwo />, container);
|
package/demo/js/index.js
DELETED
package/demo/style.css
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
body {
|
|
2
|
-
color: #333;
|
|
3
|
-
font-family: "Helvetica Neue", "Helvetica", Helvetica, Arial, sans-serif;
|
|
4
|
-
font-size: 14px;
|
|
5
|
-
line-height: 1.4;
|
|
6
|
-
-webkit-box-sizing: border-box;
|
|
7
|
-
-moz-box-sizing: border-box;
|
|
8
|
-
box-sizing: border-box;
|
|
9
|
-
-webkit-font-smoothing: antialiased;
|
|
10
|
-
max-width: 600px;
|
|
11
|
-
margin: 0 auto 200px;
|
|
12
|
-
padding: 10px;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
input:focus,
|
|
16
|
-
a:focus,
|
|
17
|
-
button:focus {
|
|
18
|
-
outline: 5px solid lightblue;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.trap {
|
|
22
|
-
border: 1px solid #ccc;
|
|
23
|
-
padding: 1em 2em;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.trap.is-active {
|
|
27
|
-
background: #FEE9FF;
|
|
28
|
-
}
|