-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs][Menu][joy] Explain how to control the open state (#38355)
Signed-off-by: Michał Dudak <[email protected]> Co-authored-by: Sam Sycamore <[email protected]>
- Loading branch information
1 parent
aa41bc0
commit a80bc05
Showing
4 changed files
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import Dropdown from '@mui/joy/Dropdown'; | ||
import Menu from '@mui/joy/Menu'; | ||
import MenuButton from '@mui/joy/MenuButton'; | ||
import MenuItem from '@mui/joy/MenuItem'; | ||
|
||
export default function ControlledDropdown() { | ||
const [open, setOpen] = React.useState(false); | ||
|
||
const handleOpenChange = React.useCallback((event, isOpen) => { | ||
setOpen(isOpen); | ||
}, []); | ||
|
||
return ( | ||
<Dropdown open={open} onOpenChange={handleOpenChange}> | ||
<MenuButton>Dashboard...</MenuButton> | ||
<Menu> | ||
<MenuItem>Profile</MenuItem> | ||
<MenuItem>My account</MenuItem> | ||
<MenuItem>Logout</MenuItem> | ||
</Menu> | ||
</Dropdown> | ||
); | ||
} |
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,27 @@ | ||
import * as React from 'react'; | ||
import Dropdown from '@mui/joy/Dropdown'; | ||
import Menu from '@mui/joy/Menu'; | ||
import MenuButton from '@mui/joy/MenuButton'; | ||
import MenuItem from '@mui/joy/MenuItem'; | ||
|
||
export default function ControlledDropdown() { | ||
const [open, setOpen] = React.useState(false); | ||
|
||
const handleOpenChange = React.useCallback( | ||
(event: React.SyntheticEvent | null, isOpen: boolean) => { | ||
setOpen(isOpen); | ||
}, | ||
[], | ||
); | ||
|
||
return ( | ||
<Dropdown open={open} onOpenChange={handleOpenChange}> | ||
<MenuButton>Dashboard...</MenuButton> | ||
<Menu> | ||
<MenuItem>Profile</MenuItem> | ||
<MenuItem>My account</MenuItem> | ||
<MenuItem>Logout</MenuItem> | ||
</Menu> | ||
</Dropdown> | ||
); | ||
} |
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,8 @@ | ||
<Dropdown open={open} onOpenChange={handleOpenChange}> | ||
<MenuButton>Dashboard...</MenuButton> | ||
<Menu> | ||
<MenuItem>Profile</MenuItem> | ||
<MenuItem>My account</MenuItem> | ||
<MenuItem>Logout</MenuItem> | ||
</Menu> | ||
</Dropdown> |
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