Skip to content

Commit

Permalink
Add demo and note about autoFocus
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
David Clark committed Jan 10, 2017
1 parent 43d6040 commit 71b174a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"node": true,
"browser": true
},
"ecmaFeatures": {
"jsx": true,
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
}
},
"rules": {
"comma-dangle": [2, "always-multiline"],
Expand Down
6 changes: 6 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ <h2>demo four</h2>
</p>
<div id="demo-four"></div>

<h2>demo five</h2>
<p>
The trap contains an input with the autofocus attribute.
</p>
<div id="demo-five"></div>

<p>
<span style="font-size:2em;vertical-align:middle;"></span>
<a href="https://github.com/davidtheclark/focus-trap-react" style="vertical-align:middle;">Return to the repository</a>
Expand Down
56 changes: 56 additions & 0 deletions demo/js/demo-five.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var React = require('react');
var ReactDOM = require('react-dom');
var FocusTrap = require('../../');

var container = document.getElementById('demo-five');

var DemoFive = React.createClass({
getInitialState: function() {
return {
activeTrap: false,
};
},

mountTrap: function() {
this.setState({ activeTrap: true });
},

unmountTrap: function() {
this.setState({ activeTrap: false });
},

render: function() {
var trap = (this.state.activeTrap) ? (
<FocusTrap
focusTrapOptions={{
onDeactivate: this.unmountTrap,
}}
>
<div className='trap'>
<button onClick={this.unmountTrap}>
deactivate trap
</button>
<div>
<a href='#'>Another focusable thing</a>
</div>
<div>
Autofocused input: <input autoFocus={true} />
</div>
</div>
</FocusTrap>
) : false;

return (
<div>
<p>
<button key='button' onClick={this.mountTrap}>
activate trap
</button>
</p>
{trap}
</div>
);
},
});

ReactDOM.render(<DemoFive />, container);
2 changes: 1 addition & 1 deletion demo/js/demo-two.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var DemoTwo = React.createClass({
<label htmlFor='focused-input' style={{ marginRight: 10 }}>
Initially focused input
</label>
<input refs='input' id='focused-input' />
<input ref='input' id='focused-input' />
</p>
<p>
<button onClick={this.unmountTrap}>
Expand Down
1 change: 1 addition & 0 deletions demo/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ require('./demo-one');
require('./demo-two');
require('./demo-three');
require('./demo-four');
require('./demo-five');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"lint": "eslint .",
"demo-bundle": "browserify demo/js -t babelify --extension=.jsx -o demo/demo-bundle.js",
"start": "budo demo/js/index.js:demo-bundle.js --dir demo -- -t babelify --extension=.jsx",
"start": "budo demo/js/index.js:demo-bundle.js --dir demo --live -- -t babelify --extension=.jsx",
"test-dev": "zuul --local 8080 --open -- test/index.js",
"pretest": "npm run lint",
"test": "zuul -- test/index.js"
Expand Down

0 comments on commit 71b174a

Please sign in to comment.