diff --git a/CHANGELOG.md b/CHANGELOG.md index e41a495..484df76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# [2.12.0](https://github.com/theKashey/react-focus-lock/compare/v2.11.3...v2.12.0) (2024-04-20) + + +### Bug Fixes + +* remove conflicting type ([7245bde](https://github.com/theKashey/react-focus-lock/commit/7245bde25148562462986feb15ab106a2f9f0202)) + + + ## [2.11.3](https://github.com/theKashey/react-focus-lock/compare/v2.11.2...v2.11.3) (2024-04-13) diff --git a/_tests/keep-focus.spec.js b/_tests/keep-focus.spec.js new file mode 100644 index 0000000..ee0a507 --- /dev/null +++ b/_tests/keep-focus.spec.js @@ -0,0 +1,20 @@ +import React from 'react'; +import { + render, screen, +} from '@testing-library/react'; +import { expect } from 'chai'; +import FocusLock from '../src'; + +describe('Focus restoration', () => { + it('maintains focus on element removal', async () => { + render( + + + , + ); + // + expect(document.activeElement).to.be.equal(screen.getByRole('button')); + }); + + it.todo('selects closes element to restore focus'); +}); diff --git a/stories/Iframe.js b/stories/Iframe.js index 6929cbf..93bf29d 100644 --- a/stories/Iframe.js +++ b/stories/Iframe.js @@ -1,74 +1,117 @@ -import * as React from "react"; -import { Component } from "react"; -import FocusLock from "../src/index"; +import * as React from 'react'; +import { Component } from 'react'; +import FocusLock from '../src/index'; const styles = { - fontFamily: "sans-serif", - textAlign: "center", - fontSize: "16px" + fontFamily: 'sans-serif', + textAlign: 'center', + fontSize: '16px', }; const bg = { - backgroundColor: '#FEE' + backgroundColor: '#FEE', }; class Trap extends Component { state = { - disabled: true + disabled: true, } - toggle = () => this.setState({disabled: !this.state.disabled}); + toggle = () => this.setState({ disabled: !this.state.disabled }); render() { - const {disabled} = this.state; + const { disabled } = this.state; return ( - - {disabled &&
- ! this is a real trap.
- We will steal your focus !

+ + {disabled && ( +
+ ! this is a + {' '} + real trap + . +
+ We will steal your focus ! + {' '} +
+


+ ) } - You will cycle over this. Never leaving
- - {this.props.children} - + You will cycle over this. Never leaving + {' '} +
+ + {this.props.children} + - { !disabled &&
-

PRESS this to end the trial.

+ { !disabled && ( +
+
+
+ PRESS this to end the trial. +
+
-
+
All your focus belongs to us! -
} +
+ )}
- ) + ); } } -export const IFrame = (props) => +export const IFrame = props => (
- -
Inaccessible Link outside
+ +
+ {' '} + Inaccessible + Link + {' '} + outside +
-