Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Menu][joy] Remove open and onClose props #38354

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 11 additions & 26 deletions docs/data/joy/components/breadcrumbs/BreadcrumbsWithMenu.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
import * as React from 'react';
import Breadcrumbs from '@mui/joy/Breadcrumbs';
import Button from '@mui/joy/Button';
import MenuButton from '@mui/joy/MenuButton';
import Dropdown from '@mui/joy/Dropdown';
import Link from '@mui/joy/Link';
import Menu from '@mui/joy/Menu';
import MenuItem from '@mui/joy/MenuItem';
import * as React from 'react';

export default function BreadcrumbsWithMenu() {
const [anchorEl, setAnchorEl] = React.useState(null);
const open = Boolean(anchorEl);
const handleClick = (event) => {
if (event) {
setAnchorEl(event.currentTarget);
}
};
const handleClose = () => {
setAnchorEl(null);
};

return (
<React.Fragment>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
aria-labelledby="with-menu-demo-breadcrumbs"
>
<MenuItem onClick={handleClose}>Breadcrumb 2</MenuItem>
<MenuItem onClick={handleClose}>Breadcrumb 3</MenuItem>
<MenuItem onClick={handleClose}>Breadcrumb 4</MenuItem>
<Dropdown>
<Menu>
<MenuItem>Breadcrumb 2</MenuItem>
<MenuItem>Breadcrumb 3</MenuItem>
<MenuItem>Breadcrumb 4</MenuItem>
</Menu>
<Breadcrumbs aria-label="breadcrumbs">
<Link color="primary" href="#condensed-with-menu">
Breadcrumb 1
</Link>
<Button size="sm" onClick={handleClick} variant="plain" color="primary">
<MenuButton size="sm" variant="plain" color="primary">
•••
</Button>
</MenuButton>
<Link color="primary" href="#condensed-with-menu">
Breadcrumb 5
</Link>
<Link color="primary" href="#condensed-with-menu">
Breadcrumb 6
</Link>
</Breadcrumbs>
</React.Fragment>
</Dropdown>
);
}
37 changes: 11 additions & 26 deletions docs/data/joy/components/breadcrumbs/BreadcrumbsWithMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
import * as React from 'react';
import Breadcrumbs from '@mui/joy/Breadcrumbs';
import Button from '@mui/joy/Button';
import MenuButton from '@mui/joy/MenuButton';
import Dropdown from '@mui/joy/Dropdown';
import Link from '@mui/joy/Link';
import Menu from '@mui/joy/Menu';
import MenuItem from '@mui/joy/MenuItem';
import * as React from 'react';

export default function BreadcrumbsWithMenu() {
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null);
const open = Boolean(anchorEl);
const handleClick = (event: React.MouseEvent<HTMLButtonElement> | null) => {
if (event) {
setAnchorEl(event.currentTarget);
}
};
const handleClose = () => {
setAnchorEl(null);
};

return (
<React.Fragment>
<Menu
anchorEl={anchorEl}
open={open}
onClose={handleClose}
aria-labelledby="with-menu-demo-breadcrumbs"
>
<MenuItem onClick={handleClose}>Breadcrumb 2</MenuItem>
<MenuItem onClick={handleClose}>Breadcrumb 3</MenuItem>
<MenuItem onClick={handleClose}>Breadcrumb 4</MenuItem>
<Dropdown>
<Menu>
<MenuItem>Breadcrumb 2</MenuItem>
<MenuItem>Breadcrumb 3</MenuItem>
<MenuItem>Breadcrumb 4</MenuItem>
</Menu>
<Breadcrumbs aria-label="breadcrumbs">
<Link color="primary" href="#condensed-with-menu">
Breadcrumb 1
</Link>
<Button size="sm" onClick={handleClick} variant="plain" color="primary">
<MenuButton size="sm" variant="plain" color="primary">
•••
</Button>
</MenuButton>
<Link color="primary" href="#condensed-with-menu">
Breadcrumb 5
</Link>
<Link color="primary" href="#condensed-with-menu">
Breadcrumb 6
</Link>
</Breadcrumbs>
</React.Fragment>
</Dropdown>
);
}
37 changes: 8 additions & 29 deletions docs/data/joy/components/button-group/SplitButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import IconButton from '@mui/joy/IconButton';
import ButtonGroup from '@mui/joy/ButtonGroup';
import Menu from '@mui/joy/Menu';
import MenuItem from '@mui/joy/MenuItem';
import MenuButton from '@mui/joy/MenuButton';
import Dropdown from '@mui/joy/Dropdown';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';

const options = ['Create a merge commit', 'Squash and merge', 'Rebase and merge'];

export default function SplitButton() {
const [open, setOpen] = React.useState(false);
const actionRef = React.useRef(null);
const anchorRef = React.useRef(null);
const [selectedIndex, setSelectedIndex] = React.useState(1);

const handleClick = () => {
Expand All @@ -20,37 +19,17 @@ export default function SplitButton() {

const handleMenuItemClick = (event, index) => {
setSelectedIndex(index);
setOpen(false);
};

return (
<React.Fragment>
<ButtonGroup
ref={anchorRef}
variant="solid"
color="success"
aria-label="split button"
>
<Dropdown>
<ButtonGroup variant="solid" color="success" aria-label="split button">
<Button onClick={handleClick}>{options[selectedIndex]}</Button>
<IconButton
aria-controls={open ? 'split-button-menu' : undefined}
aria-expanded={open ? 'true' : undefined}
aria-label="select merge strategy"
aria-haspopup="menu"
onMouseDown={() => {
actionRef.current = () => setOpen(!open);
}}
onKeyDown={() => {
actionRef.current = () => setOpen(!open);
}}
onClick={() => {
actionRef.current?.();
}}
>
<MenuButton slots={{ root: IconButton }} aria-label="select merge strategy">
<ArrowDropDownIcon />
</IconButton>
</MenuButton>
</ButtonGroup>
<Menu open={open} onClose={() => setOpen(false)} anchorEl={anchorRef.current}>
<Menu>
{options.map((option, index) => (
<MenuItem
key={option}
Expand All @@ -62,6 +41,6 @@ export default function SplitButton() {
</MenuItem>
))}
</Menu>
</React.Fragment>
</Dropdown>
);
}
39 changes: 8 additions & 31 deletions docs/data/joy/components/button-group/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import IconButton from '@mui/joy/IconButton';
import ButtonGroup from '@mui/joy/ButtonGroup';
import Menu from '@mui/joy/Menu';
import MenuItem from '@mui/joy/MenuItem';
import MenuButton from '@mui/joy/MenuButton';
import Dropdown from '@mui/joy/Dropdown';
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';

const options = ['Create a merge commit', 'Squash and merge', 'Rebase and merge'];

export default function SplitButton() {
const [open, setOpen] = React.useState(false);
const actionRef = React.useRef<() => void | null>(null);
const anchorRef = React.useRef<HTMLDivElement>(null);
const [selectedIndex, setSelectedIndex] = React.useState(1);

const handleClick = () => {
Expand All @@ -23,39 +22,17 @@ export default function SplitButton() {
index: number,
) => {
setSelectedIndex(index);
setOpen(false);
};

return (
<React.Fragment>
<ButtonGroup
ref={anchorRef}
variant="solid"
color="success"
aria-label="split button"
>
<Dropdown>
<ButtonGroup variant="solid" color="success" aria-label="split button">
<Button onClick={handleClick}>{options[selectedIndex]}</Button>
<IconButton
aria-controls={open ? 'split-button-menu' : undefined}
aria-expanded={open ? 'true' : undefined}
aria-label="select merge strategy"
aria-haspopup="menu"
onMouseDown={() => {
// @ts-ignore
actionRef.current = () => setOpen(!open);
}}
onKeyDown={() => {
// @ts-ignore
actionRef.current = () => setOpen(!open);
}}
onClick={() => {
actionRef.current?.();
}}
>
<MenuButton slots={{ root: IconButton }} aria-label="select merge strategy">
<ArrowDropDownIcon />
</IconButton>
</MenuButton>
</ButtonGroup>
<Menu open={open} onClose={() => setOpen(false)} anchorEl={anchorRef.current}>
<Menu>
{options.map((option, index) => (
<MenuItem
key={option}
Expand All @@ -67,6 +44,6 @@ export default function SplitButton() {
</MenuItem>
))}
</Menu>
</React.Fragment>
</Dropdown>
);
}
6 changes: 3 additions & 3 deletions docs/data/joy/components/menu/MenuIconSideNavExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default function MenuIconSideNavExample() {
onOpen={() => setMenuIndex(0)}
onLeaveMenu={createHandleLeaveMenu(0)}
menu={
<Menu onClose={() => setMenuIndex(null)}>
<Menu>
<MenuItem {...itemProps}>Application 1</MenuItem>
<MenuItem {...itemProps}>Application 2</MenuItem>
<MenuItem {...itemProps}>Application 3</MenuItem>
Expand All @@ -164,7 +164,7 @@ export default function MenuIconSideNavExample() {
onOpen={() => setMenuIndex(1)}
onLeaveMenu={createHandleLeaveMenu(1)}
menu={
<Menu onClose={() => setMenuIndex(null)}>
<Menu>
<MenuItem {...itemProps}>Setting 1</MenuItem>
<MenuItem {...itemProps}>Setting 2</MenuItem>
<MenuItem {...itemProps}>Setting 3</MenuItem>
Expand All @@ -181,7 +181,7 @@ export default function MenuIconSideNavExample() {
onOpen={() => setMenuIndex(2)}
onLeaveMenu={createHandleLeaveMenu(2)}
menu={
<Menu onClose={() => setMenuIndex(null)}>
<Menu>
<MenuItem {...itemProps}>Personal 1</MenuItem>
<MenuItem {...itemProps}>Personal 2</MenuItem>
<MenuItem {...itemProps}>Personal 3</MenuItem>
Expand Down
6 changes: 3 additions & 3 deletions docs/data/joy/components/menu/MenuIconSideNavExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default function MenuIconSideNavExample() {
onOpen={() => setMenuIndex(0)}
onLeaveMenu={createHandleLeaveMenu(0)}
menu={
<Menu onClose={() => setMenuIndex(null)}>
<Menu>
<MenuItem {...itemProps}>Application 1</MenuItem>
<MenuItem {...itemProps}>Application 2</MenuItem>
<MenuItem {...itemProps}>Application 3</MenuItem>
Expand All @@ -167,7 +167,7 @@ export default function MenuIconSideNavExample() {
onOpen={() => setMenuIndex(1)}
onLeaveMenu={createHandleLeaveMenu(1)}
menu={
<Menu onClose={() => setMenuIndex(null)}>
<Menu>
<MenuItem {...itemProps}>Setting 1</MenuItem>
<MenuItem {...itemProps}>Setting 2</MenuItem>
<MenuItem {...itemProps}>Setting 3</MenuItem>
Expand All @@ -184,7 +184,7 @@ export default function MenuIconSideNavExample() {
onOpen={() => setMenuIndex(2)}
onLeaveMenu={createHandleLeaveMenu(2)}
menu={
<Menu onClose={() => setMenuIndex(null)}>
<Menu>
<MenuItem {...itemProps}>Personal 1</MenuItem>
<MenuItem {...itemProps}>Personal 2</MenuItem>
<MenuItem {...itemProps}>Personal 3</MenuItem>
Expand Down
Loading