Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove positive tabIndex #182

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ I've got a good [article about focus management, dialogs and WAI-ARIA](https://
- `whiteList=fn` you could _whitelist_ locations FocusLock should carry about. Everything outside it will ignore. For example - any modals.
- `as='div'` if you need to change internal `div` element, to any other. Use ref forwarding to give FocusLock the node to work with.
- `lockProps={}` to pass any extra props (except className) to the internal wrapper.
- `usePositiveIndices` to maintain a focus lock when elements exterior to the focus lock have a tabIndex greater than 0.

### Focusing in OSX (Safari/Firefox) is strange!
By default `tabbing` in OSX `sees` only controls, but not links or anything else `tabbable`. This is system settings, and Safari/Firefox obey.
Expand Down
7 changes: 6 additions & 1 deletion src/Lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const FocusLock = React.forwardRef(function FocusLockUI(props, parentRef) {
group,
className,
whiteList,
usePositiveIndices,
shards = emptyArray,
as: Container = 'div',
lockProps: containerProps = {},
Expand All @@ -39,6 +40,8 @@ const FocusLock = React.forwardRef(function FocusLockUI(props, parentRef) {
onDeactivation: onDeactivationCallback,
} = props;

const maxTabIndex = usePositiveIndices ? 1 : 0;

const [id] = React.useState({});

// SIDE EFFECT CALLBACKS
Expand Down Expand Up @@ -136,7 +139,7 @@ const FocusLock = React.forwardRef(function FocusLockUI(props, parentRef) {
<React.Fragment>
{hasLeadingGuards && [
<div key="guard-first" data-focus-guard tabIndex={disabled ? -1 : 0} style={hiddenGuard}/>, // nearest focus guard
<div key="guard-nearest" data-focus-guard tabIndex={disabled ? -1 : 1} style={hiddenGuard}/>, // first tabbed element guard
<div key="guard-nearest" data-focus-guard tabIndex={disabled ? -1 : maxTabIndex} style={hiddenGuard}/>, // first tabbed element guard
]}
{!disabled && (
<SideCar
Expand Down Expand Up @@ -176,6 +179,7 @@ FocusLock.propTypes = {
disabled: bool,
returnFocus: oneOfType([bool, object]),
noFocusGuards: bool,
usePositiveIndices: bool,

allowTextSelection: bool,
autoFocus: bool,
Expand Down Expand Up @@ -205,6 +209,7 @@ FocusLock.defaultProps = {
autoFocus: true,
persistentFocus: false,
crossFrame: true,
usePositiveIndices: undefined,
allowTextSelection: undefined,
group: undefined,
className: undefined,
Expand Down