Skip to content

Commit

Permalink
fix: Safary and Negative TabIndex, #33
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Jul 15, 2018
1 parent c3c04c1 commit f4a6a6d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Trap.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const activateTrap = () => {
if (
workingNode &&
!(focusInside(workingNode) ||
focusIsPortaledPair(activeElement, workingNode))
focusIsPortaledPair(activeElement, workingNode) ||
(workingNode.contains && workingNode.contains(activeElement))
)
) {
onActivation();
if (document && !lastActiveFocus && activeElement && !autoFocus) {
Expand Down
21 changes: 20 additions & 1 deletion stories/TextSelection.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ class Trap extends Component {
<br/>
<br/>
Some text
{this.props.children}
<input placeholder="input2"/>
<input placeholder="input3"/> <br/>
{ Array(100).fill(1).map(x => <div>{x}---</div>)}
Some text
<button>A BUTTON</button>
</FocusLock>
Expand Down Expand Up @@ -62,8 +64,25 @@ const TextSelectionDisabled = () =>
<input placeholder="input1"/>
</div>;

const TextSelectionTabIndexEnabled = () =>
<div style={styles}>
<input placeholder="input1"/>
Some text
<div style={bg}>
<Trap allowTextSelection>
<div tabIndex={-1}>
test
<input />
set
</div>
</Trap>
</div>
Some text
<input placeholder="input1"/>
</div>;

export {
TextSelectionEnabled,
TextSelectionDisabled
TextSelectionDisabled,
TextSelectionTabIndexEnabled,
}
5 changes: 3 additions & 2 deletions stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TabIndex from './TabIndex';
import AutoFocus from './Autofocus';
import ReturnFocus from './ReturnFocus';
import {Trap1, Trap2, Trap3, Trap4} from './Checkboxes';
import {TextSelectionEnabled, TextSelectionDisabled} from './TextSelection';
import {TextSelectionEnabled, TextSelectionDisabled, TextSelectionTabIndexEnabled} from './TextSelection';
import JumpCase from './Jump';
import GroupCase from './Group';
import PortalCase from './Portal';
Expand Down Expand Up @@ -38,7 +38,8 @@ storiesOf('Checkboxes', module)

storiesOf('Text selection', module)
.add('enabled', () => <Frame><TextSelectionEnabled/></Frame>)
.add('disabled', () => <Frame><TextSelectionDisabled/></Frame>);
.add('disabled', () => <Frame><TextSelectionDisabled/></Frame>)
.add('tabindex -1', () => <Frame><TextSelectionTabIndexEnabled/></Frame>);

storiesOf('Jump', module)
.add('jump', () => <Frame><JumpCase /></Frame>);
Expand Down

0 comments on commit f4a6a6d

Please sign in to comment.