-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
React Events: FocusScope tweaks and docs (#15515)
* FocusScope: rename trap to contain. * FocusScope: avoid potential for el.focus() errors. * FocusScope: add docs. * Update docs formatting.
- Loading branch information
Showing
6 changed files
with
88 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# FocusScope | ||
|
||
The `FocusScope` module can be used to manage focus within its subtree. | ||
|
||
```js | ||
// Example | ||
const Modal = () => ( | ||
<FocusScope | ||
autoFocus={true} | ||
contain={true} | ||
restoreFocus={true} | ||
> | ||
<h1>Focus contained within modal</h1> | ||
<input placeholder="Focusable input" /> | ||
<div role="button" tabIndex={0}>Focusable element</div> | ||
<input placeholder="Non-focusable input" tabIndex={-1} /> | ||
<Press onPress={onPressClose}> | ||
<div role="button" tabIndex={0}>Close</div> | ||
</Press> | ||
</FocusScope> | ||
); | ||
``` | ||
|
||
## Props | ||
|
||
### autoFocus: boolean = false | ||
|
||
Automatically moves focus to the first focusable element within scope. | ||
|
||
### contain: boolean = false | ||
|
||
Contain focus within the subtree of the `FocusScope` instance. | ||
|
||
### restoreFocus: boolean = false | ||
|
||
Automatically restores focus to element that was last focused before focus moved | ||
within the scope. |
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