Skip to content

Commit

Permalink
Set is-active style on trap demos, special-elem returns focus (#101)
Browse files Browse the repository at this point in the history
And the 'special element' demo is now set to return focus
after deactivation, in particular to make it easier to
reproduce the issue that focus is NOT returned when deactivating
with the ESC key, which is the issue #54 is trying to fix.
  • Loading branch information
stefcameron committed Aug 30, 2020
1 parent c92eaf4 commit 4351286
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
8 changes: 6 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1 tabindex="0">focus-trap-react demo</h1>

<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>
<a href="https://github.com/focus-trap/focus-trap-react" style="vertical-align:middle;">Return to the repository</a>
</p>

<h2>defaults</h2>
Expand Down Expand Up @@ -45,6 +45,10 @@ <h2>special element</h2>
<p>
ALSO, when you click outside this FocusTrap, the trap deactivates and your click carries through.
</p>
<p>
Finally, focus should return to the "activate trap" button, whether you click the "deactivate trap"
button, or press the ESC key.
</p>
<div id="demo-special-element"></div>

<h2>demo autofocus</h2>
Expand All @@ -55,7 +59,7 @@ <h2>demo autofocus</h2>

<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>
<a href="https://github.com/focus-trap/focus-trap-react" style="vertical-align:middle;">Return to the repository</a>
</p>

<script src="demo-bundle.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion demo/js/demo-autofocus.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DemoAutofocus extends React.Component {
onDeactivate: this.unmountTrap,
}}
>
<div className="trap">
<div className="trap is-active">
<button onClick={this.unmountTrap}>deactivate trap</button>
<div>
<a href="#">Another focusable thing</a>
Expand Down
2 changes: 1 addition & 1 deletion demo/js/demo-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class DemoDefaults extends React.Component {
onDeactivate: this.unmountTrap,
}}
>
<div className="trap">
<div className="trap is-active">
<p>
Here is a focus trap <a href="#">with</a> <a href="#">some</a>{' '}
<a href="#">focusable</a> parts.
Expand Down
2 changes: 1 addition & 1 deletion demo/js/demo-ffne.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DemoFfne extends React.Component {
escapeDeactivates: false,
}}
>
<div className="trap">
<div className="trap is-active">
<p>
Here is a focus trap <a href="#">with</a> <a href="#">some</a>{' '}
<a href="#">focusable</a> parts.
Expand Down
7 changes: 5 additions & 2 deletions demo/js/demo-special-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class DemoSpecialElement extends React.Component {

render() {
let trapClass = 'trap';
if (this.state.activeTrap) trapClass += ' is-active';
if (this.state.activeTrap) {
trapClass += ' is-active';
}

return (
<div>
Expand All @@ -38,11 +40,12 @@ class DemoSpecialElement extends React.Component {
focusTrapOptions={{
onDeactivate: this.unmountTrap,
clickOutsideDeactivates: true,
returnFocusOnDeactivate: true,
}}
>
<section
id="focus-trap-three"
style={{ background: '#eee' }}
style={this.state.activeTrap ? null : { background: '#eee' }}
data-whatever="nothing"
className={trapClass}
>
Expand Down

0 comments on commit 4351286

Please sign in to comment.