Skip to content

Commit

Permalink
add support for focus options on returnFocus.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitgrelard committed Sep 12, 2019
1 parent 4e779e8 commit 4e66fdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ export interface ReactFocusLockProps {
disabled?: boolean;

/**
* will return focus to the previous position on trap disable.
* if true, will return focus to the previous position on trap disable.
* Optionally, can pass focus options instead of `true` to control the focus
* more precisely (ie. `{ preventScroll: true }`)
*/
returnFocus?: boolean;
returnFocus?: boolean | FocusOptions;

/**
* @deprecated Use persistentFocus=false instead
Expand Down
7 changes: 4 additions & 3 deletions src/Lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ function FocusLock(props) {

const returnFocus = useCallback(() => {
const { current } = originalFocusedElement;
if (shouldReturnFocus && current && current.focus) {
current.focus();
if (Boolean(shouldReturnFocus) && current && current.focus) {
const focusOptions = typeof shouldReturnFocus === 'object' ? shouldReturnFocus : undefined;
current.focus(focusOptions);
originalFocusedElement.current = null;
}
}, []);
Expand Down Expand Up @@ -138,7 +139,7 @@ function FocusLock(props) {
FocusLock.propTypes = {
children: node.isRequired,
disabled: bool,
returnFocus: bool,
returnFocus: oneOfType([bool, object]),
noFocusGuards: bool,

allowTextSelection: bool,
Expand Down

0 comments on commit 4e66fdc

Please sign in to comment.