Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] simplify ContainedToggleTrappedFocus examples
- Loading branch information
1 parent
2b2c556
commit e181658
Showing
3 changed files
with
24 additions
and
42 deletions.
There are no files selected for viewing
23 changes: 7 additions & 16 deletions
23
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 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> | ||
); | ||
} |
23 changes: 7 additions & 16 deletions
23
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 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> |