-
Notifications
You must be signed in to change notification settings - Fork 47.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[react-interactions] Add allowModifiers flag to FocusList + FocusTable (
- Loading branch information
Showing
6 changed files
with
172 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/react-interactions/accessibility/src/emulateBrowserTab.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import {createEventTarget} from 'react-interactions/events/src/dom/testing-library'; | ||
|
||
// This function is used by the a11y modules for testing | ||
export function emulateBrowserTab(backwards) { | ||
const activeElement = document.activeElement; | ||
const focusedElem = createEventTarget(activeElement); | ||
let defaultPrevented = false; | ||
focusedElem.keydown({ | ||
key: 'Tab', | ||
shiftKey: backwards, | ||
preventDefault() { | ||
defaultPrevented = true; | ||
}, | ||
}); | ||
if (!defaultPrevented) { | ||
// This is not a full spec compliant version, but should be suffice for this test | ||
const focusableElems = Array.from( | ||
document.querySelectorAll( | ||
'input, button, select, textarea, a[href], [tabindex], [contenteditable], iframe, object, embed', | ||
), | ||
).filter( | ||
elem => elem.tabIndex > -1 && !elem.disabled && !elem.contentEditable, | ||
); | ||
const idx = focusableElems.indexOf(activeElement); | ||
if (idx !== -1) { | ||
focusableElems[backwards ? idx - 1 : idx + 1].focus(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters