-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
[utils] Explicitly register roving tab items with parent #48122
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d989266
Refactor
mj12albert 417dd3b
reduce menu focus glue
mj12albert 2441105
stepper cleanup
mj12albert 7b74f1c
tabs cleanup
mj12albert 4665338
further cleanup
mj12albert 4335667
fix ci
mj12albert 965c2bd
fix unregister
mj12albert 998e0b1
fix MenuContentAnchors
mj12albert 236aca3
fixes
mj12albert 6b67574
clean up contexts
mj12albert fa3aaf1
review comments
mj12albert fa5d14e
fix tests
mj12albert 965307c
Fix CI
mj12albert 877b952
polish
mj12albert e9dc37d
tweak docs and misc fixes
mj12albert 168c0a1
fix demo
mj12albert 0339459
clean up muiSkipListHighlight
mj12albert de95d6c
docs cleanup
mj12albert 15ee4dd
fix review comments
mj12albert 4ee41f4
align null checks
mj12albert 53d6ab0
improve readability
mj12albert beddbdb
fix disabled step button
mj12albert e6596db
update doc
mj12albert 90bd96e
comment
mj12albert d811b93
Merge branch 'master' into feat/roving-set-registry
Janpot d49aaff
fix visual highlight and add tests
mj12albert 92fe098
fix open interaction handling
mj12albert ec0ee8c
add select disablePortal test
mj12albert bbcab89
cleanup focusActiveItem
mj12albert 4623923
cleanup
mj12albert 634e655
comment
mj12albert be593f7
Merge branch 'master' into feat/roving-set-registry
mj12albert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,229 @@ | ||
| import * as React from 'react'; | ||
| import useEventCallback from '@mui/utils/useEventCallback'; | ||
| import Box from '@mui/material/Box'; | ||
| import Button from '@mui/material/Button'; | ||
| import Container from '@mui/material/Container'; | ||
| import Divider from '@mui/material/Divider'; | ||
| import Menu from '@mui/material/Menu'; | ||
| import MenuItem from '@mui/material/MenuItem'; | ||
| import Paper from '@mui/material/Paper'; | ||
| import Stack from '@mui/material/Stack'; | ||
| import Typography from '@mui/material/Typography'; | ||
| import Head from 'docs/src/modules/components/Head'; | ||
| import { Link } from '@mui/docs/Link'; | ||
|
|
||
| const MenuDivider = React.forwardRef<HTMLHRElement, React.ComponentPropsWithoutRef<typeof Divider>>( | ||
| function MenuDivider(props, ref) { | ||
| return <Divider ref={ref} {...props} />; | ||
| }, | ||
| ); | ||
|
|
||
| interface ExampleFrameProps { | ||
| children: React.ReactNode; | ||
| eyebrow: string; | ||
| title: string; | ||
| description: string; | ||
| instructions: string; | ||
| } | ||
|
|
||
| function ExampleFrame(props: ExampleFrameProps) { | ||
| const { children, eyebrow, title, description, instructions } = props; | ||
|
|
||
| return ( | ||
| <Paper component="section" variant="outlined" sx={{ p: 3 }}> | ||
| <Stack spacing={3}> | ||
| <div> | ||
| <Typography variant="overline" color="text.secondary"> | ||
| {eyebrow} | ||
| </Typography> | ||
| <Typography variant="h6" sx={{ mt: 0.5 }}> | ||
| {title} | ||
| </Typography> | ||
| <Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}> | ||
| {description} | ||
| </Typography> | ||
| <Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}> | ||
| {instructions} | ||
| </Typography> | ||
| </div> | ||
| {children} | ||
| </Stack> | ||
| </Paper> | ||
| ); | ||
| } | ||
|
|
||
| function FragmentAndDividerExample() { | ||
| const [open, setOpen] = React.useState(false); | ||
| const buttonRef = React.useRef<HTMLButtonElement | null>(null); | ||
| const handleClose = useEventCallback(() => { | ||
| setOpen(false); | ||
| }); | ||
|
|
||
| return ( | ||
| <ExampleFrame | ||
| eyebrow="Fragments" | ||
| title="Fragment-wrapped items and wrapped dividers" | ||
| description="This menu mixes MenuItems inside React.Fragment with a Divider wrapper that used to accidentally join the tab sequence." | ||
| instructions='Open the menu and use the arrow keys. The selected item should land on "Pin to right", both fragment groups should participate, and the divider wrapper should be skipped entirely.' | ||
| > | ||
| <Button ref={buttonRef} variant="contained" onClick={() => setOpen(true)}> | ||
| Open fragment menu | ||
| </Button> | ||
| <Menu anchorEl={buttonRef.current} open={open} onClose={() => setOpen(false)}> | ||
| <React.Fragment> | ||
| <MenuItem onClick={handleClose}>Sort ascending</MenuItem> | ||
| <MenuItem onClick={handleClose}>Sort descending</MenuItem> | ||
| </React.Fragment> | ||
| <MenuDivider /> | ||
| <React.Fragment> | ||
| {null} | ||
| <MenuItem onClick={handleClose}>Pin to left</MenuItem> | ||
| <MenuItem selected onClick={handleClose}> | ||
| Pin to right | ||
| </MenuItem> | ||
| </React.Fragment> | ||
| <MenuDivider /> | ||
| <React.Fragment> | ||
| <MenuItem onClick={handleClose}>Filter</MenuItem> | ||
| <MenuItem onClick={handleClose}>Manage columns</MenuItem> | ||
| </React.Fragment> | ||
| </Menu> | ||
| </ExampleFrame> | ||
| ); | ||
| } | ||
|
|
||
| function ConditionalInsertExample() { | ||
| const [open, setOpen] = React.useState(false); | ||
| const [showPinnedActions, setShowPinnedActions] = React.useState(false); | ||
| const buttonRef = React.useRef<HTMLButtonElement | null>(null); | ||
| const handleClose = useEventCallback(() => { | ||
| setOpen(false); | ||
| }); | ||
|
|
||
| return ( | ||
| <ExampleFrame | ||
| eyebrow="Conditional Rendering" | ||
| title="Inserting items ahead of the active MenuItem" | ||
| description="This example inserts a fragment before the selected item while the menu is already open." | ||
| instructions='Open the menu, then toggle the extra block. Focus should stay anchored to "Reports" instead of jumping back to the start.' | ||
| > | ||
| <Stack direction="row" spacing={1.5} useFlexGap sx={{ flexWrap: 'wrap' }}> | ||
| <Button ref={buttonRef} variant="contained" onClick={() => setOpen(true)}> | ||
| Open conditional menu | ||
| </Button> | ||
| <Button variant="outlined" onClick={() => setShowPinnedActions((previous) => !previous)}> | ||
| {showPinnedActions ? 'Hide pinned actions' : 'Show pinned actions'} | ||
| </Button> | ||
| </Stack> | ||
| <Menu anchorEl={buttonRef.current} open={open} onClose={() => setOpen(false)}> | ||
| {showPinnedActions ? ( | ||
| <React.Fragment> | ||
| <MenuItem onClick={handleClose}>Pin to dashboard</MenuItem> | ||
| <MenuItem onClick={handleClose}>Send to favorites</MenuItem> | ||
| <MenuDivider /> | ||
| </React.Fragment> | ||
| ) : null} | ||
| <MenuItem onClick={handleClose}>Overview</MenuItem> | ||
| <MenuItem selected onClick={handleClose}> | ||
| Reports | ||
| </MenuItem> | ||
| <MenuItem onClick={handleClose}>Notifications</MenuItem> | ||
| <MenuItem onClick={handleClose}>History</MenuItem> | ||
| </Menu> | ||
| </ExampleFrame> | ||
| ); | ||
| } | ||
|
|
||
| function ReorderingExample() { | ||
| const [open, setOpen] = React.useState(false); | ||
| const [priorityFirst, setPriorityFirst] = React.useState(true); | ||
| const buttonRef = React.useRef<HTMLButtonElement | null>(null); | ||
| const handleClose = useEventCallback(() => { | ||
| setOpen(false); | ||
| }); | ||
|
|
||
| const priorityGroup = ( | ||
| <React.Fragment key="priority-group"> | ||
| <MenuItem onClick={handleClose}>Pin to left</MenuItem> | ||
| <MenuItem onClick={handleClose}>Pin to right</MenuItem> | ||
| </React.Fragment> | ||
| ); | ||
|
|
||
| const primaryGroup = ( | ||
| <React.Fragment key="primary-group"> | ||
| <MenuItem onClick={handleClose}>Rename</MenuItem> | ||
| <MenuItem selected onClick={handleClose}> | ||
| Duplicate | ||
| </MenuItem> | ||
| <MenuItem onClick={handleClose}>Archive</MenuItem> | ||
| </React.Fragment> | ||
| ); | ||
|
|
||
| const orderedGroups = priorityFirst | ||
| ? [priorityGroup, <MenuDivider key="boundary-divider" />, primaryGroup] | ||
| : [primaryGroup, <MenuDivider key="boundary-divider" />, priorityGroup]; | ||
|
|
||
| return ( | ||
| <ExampleFrame | ||
| eyebrow="Internal Reordering" | ||
| title="Moving a whole fragment block to a different position" | ||
| description="This example moves an entire keyed fragment from the top of the menu to the bottom while the menu is already open." | ||
| instructions='Open the menu and move the priority fragment. Focus should stay on "Duplicate" even as the block moves around it.' | ||
| > | ||
| <Stack direction="row" spacing={1.5} useFlexGap sx={{ flexWrap: 'wrap' }}> | ||
| <Button ref={buttonRef} variant="contained" onClick={() => setOpen(true)}> | ||
| Open reordering menu | ||
| </Button> | ||
| <Button variant="outlined" onClick={() => setPriorityFirst((previous) => !previous)}> | ||
| {priorityFirst ? 'Move priority actions below' : 'Move priority actions above'} | ||
| </Button> | ||
| </Stack> | ||
| <Menu anchorEl={buttonRef.current} open={open} onClose={() => setOpen(false)}> | ||
| {orderedGroups} | ||
| </Menu> | ||
| </ExampleFrame> | ||
| ); | ||
| } | ||
|
|
||
| export default function RovingFocusExperiment() { | ||
| return ( | ||
| <React.Fragment> | ||
| <Head title="Menu Roving Focus Experiments" description="" /> | ||
| <Box sx={{ py: { xs: 4, md: 6 } }}> | ||
| <Container maxWidth="md"> | ||
| <Stack spacing={4}> | ||
| <Stack spacing={2}> | ||
| <Typography variant="overline" color="text.secondary"> | ||
| Experiments | ||
| </Typography> | ||
| <Typography variant="h3"> | ||
| Menu roving focus after registration-based item tracking | ||
| </Typography> | ||
| <Typography variant="body1" color="text.secondary"> | ||
| These demos focus on the cases that were brittle before the refactor: MenuItems | ||
| inside fragments, wrapped dividers, and conditional child trees that reorder after | ||
| the menu has already resolved its active item. | ||
| </Typography> | ||
| <Box sx={{ display: 'flex', gap: 2, flexWrap: 'wrap' }}> | ||
| <Button component={Link} href="/experiments" noLinkStyle variant="outlined"> | ||
| Back to experiments | ||
| </Button> | ||
| <Button | ||
| component={Link} | ||
| href="https://github.com/mui/material-ui/tree/master/docs/pages/experiments" | ||
| noLinkStyle | ||
| variant="text" | ||
| > | ||
| Open experiments source | ||
| </Button> | ||
| </Box> | ||
| </Stack> | ||
| <FragmentAndDividerExample /> | ||
| <ConditionalInsertExample /> | ||
| <ReorderingExample /> | ||
| </Stack> | ||
| </Container> | ||
| </Box> | ||
| </React.Fragment> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.