Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TrapFocus] Improve tab test and simplify demo (#34008)
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
- Loading branch information
1 parent
605abba
commit 479663a
Showing
16 changed files
with
70 additions
and
145 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
25 changes: 8 additions & 17 deletions
25
docs/data/base/components/trap-focus/ContainedToggleTrappedFocus.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 |
---|---|---|
@@ -1,33 +1,24 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Stack from '@mui/system/Stack'; | ||
import TrapFocus from '@mui/base/TrapFocus'; | ||
|
||
export default function BasicTrapFocus() { | ||
export default function ContainedToggleTrappedFocus() { | ||
const [open, setOpen] = React.useState(false); | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
<React.Fragment> | ||
<TrapFocus open={open} disableRestoreFocus disableAutoFocus> | ||
<Stack> | ||
<Stack alignItems="center"> | ||
<button type="button" onClick={() => setOpen(!open)}> | ||
{open ? 'Close' : 'Open'} | ||
</button> | ||
</Stack> | ||
<Stack alignItems="center" spacing={2}> | ||
<button type="button" onClick={() => setOpen(!open)}> | ||
{open ? 'Close' : 'Open'} | ||
</button> | ||
{open && ( | ||
<label> | ||
First name: <input type="text" /> | ||
</label> | ||
)} | ||
</Stack> | ||
</TrapFocus> | ||
</Box> | ||
</React.Fragment> | ||
); | ||
} |
25 changes: 8 additions & 17 deletions
25
docs/data/base/components/trap-focus/ContainedToggleTrappedFocus.tsx
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 |
---|---|---|
@@ -1,33 +1,24 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Stack from '@mui/system/Stack'; | ||
import TrapFocus from '@mui/base/TrapFocus'; | ||
|
||
export default function BasicTrapFocus() { | ||
export default function ContainedToggleTrappedFocus() { | ||
const [open, setOpen] = React.useState(false); | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
<React.Fragment> | ||
<TrapFocus open={open} disableRestoreFocus disableAutoFocus> | ||
<Stack> | ||
<Stack alignItems="center"> | ||
<button type="button" onClick={() => setOpen(!open)}> | ||
{open ? 'Close' : 'Open'} | ||
</button> | ||
</Stack> | ||
<Stack alignItems="center" spacing={2}> | ||
<button type="button" onClick={() => setOpen(!open)}> | ||
{open ? 'Close' : 'Open'} | ||
</button> | ||
{open && ( | ||
<label> | ||
First name: <input type="text" /> | ||
</label> | ||
)} | ||
</Stack> | ||
</TrapFocus> | ||
</Box> | ||
</React.Fragment> | ||
); | ||
} |
20 changes: 10 additions & 10 deletions
20
docs/data/base/components/trap-focus/ContainedToggleTrappedFocus.tsx.preview
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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<TrapFocus open={open} disableRestoreFocus disableAutoFocus> | ||
<Stack> | ||
<Stack alignItems="center"> | ||
<React.Fragment> | ||
<TrapFocus open={open} disableRestoreFocus disableAutoFocus> | ||
<Stack alignItems="center" spacing={2}> | ||
<button type="button" onClick={() => setOpen(!open)}> | ||
{open ? 'Close' : 'Open'} | ||
</button> | ||
{open && ( | ||
<label> | ||
First name: <input type="text" /> | ||
</label> | ||
)} | ||
</Stack> | ||
{open && ( | ||
<label> | ||
First name: <input type="text" /> | ||
</label> | ||
)} | ||
</Stack> | ||
</TrapFocus> | ||
</TrapFocus> | ||
</React.Fragment> |
10 changes: 2 additions & 8 deletions
10
docs/data/base/components/trap-focus/DisableEnforceFocus.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
10 changes: 2 additions & 8 deletions
10
docs/data/base/components/trap-focus/DisableEnforceFocus.tsx
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import TrapFocus from '@mui/base/TrapFocus'; | ||
|
||
export default function ClosedTrapFocus() { | ||
return ( | ||
<React.Fragment> | ||
<button type="button" autoFocus> | ||
initial focus | ||
</button> | ||
<TrapFocus open={false}> | ||
<div data-testid="root"> | ||
<button type="button">inside focusable</button> | ||
</div> | ||
</TrapFocus> | ||
<button type="button">final tab target</button> | ||
</React.Fragment> | ||
); | ||
} |
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