import * as React from 'react'; import { Popper } from '@mui/base/Popper'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import Box from '@mui/joy/Box'; import IconButton from '@mui/joy/IconButton'; import Chip from '@mui/joy/Chip'; import List from '@mui/joy/List'; import ListDivider from '@mui/joy/ListDivider'; import ListItem from '@mui/joy/ListItem'; import ListItemContent from '@mui/joy/ListItemContent'; import ListItemButton from '@mui/joy/ListItemButton'; import ListItemDecorator from '@mui/joy/ListItemDecorator'; import HomeRounded from '@mui/icons-material/HomeRounded'; import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown'; import Person from '@mui/icons-material/Person'; import Apps from '@mui/icons-material/Apps'; import FactCheck from '@mui/icons-material/FactCheck'; import BookmarkAdd from '@mui/icons-material/BookmarkAdd'; const useRovingIndex = (options) => { const { initialActiveIndex = 0, vertical = false, handlers = { onKeyDown: () => {}, }, } = options || {}; const [activeIndex, setActiveIndex] = React.useState(initialActiveIndex); const targetRefs = React.useRef([]); const targets = targetRefs.current; const focusNext = () => { let newIndex = activeIndex + 1; if (newIndex >= targets.length) { newIndex = 0; } targets[newIndex]?.focus(); setActiveIndex(newIndex); }; const focusPrevious = () => { let newIndex = activeIndex - 1; if (newIndex < 0) { newIndex = targets.length - 1; } targets[newIndex]?.focus(); setActiveIndex(newIndex); }; const getTargetProps = (index) => ({ ref: (ref) => { if (ref) { targets[index] = ref; } }, tabIndex: activeIndex === index ? 0 : -1, onKeyDown: (event) => { if (Number.isInteger(activeIndex)) { if (event.key === (vertical ? 'ArrowDown' : 'ArrowRight')) { focusNext(); } if (event.key === (vertical ? 'ArrowUp' : 'ArrowLeft')) { focusPrevious(); } handlers.onKeyDown?.(event, { setActiveIndex }); } }, onClick: () => { setActiveIndex(index); }, }); return { activeIndex, setActiveIndex, targets, getTargetProps, focusNext, focusPrevious, }; }; const AboutMenu = React.forwardRef(({ focusNext, focusPrevious, ...props }, ref) => { const [anchorEl, setAnchorEl] = React.useState(null); const { targets, setActiveIndex, getTargetProps } = useRovingIndex({ initialActiveIndex: null, vertical: true, handlers: { onKeyDown: (event, fns) => { if (event.key.match(/(ArrowDown|ArrowUp|ArrowLeft|ArrowRight)/)) { event.preventDefault(); } if (event.key === 'Tab') { setAnchorEl(null); fns.setActiveIndex(null); } if (event.key === 'ArrowLeft') { setAnchorEl(null); focusPrevious(); } if (event.key === 'ArrowRight') { setAnchorEl(null); focusNext(); } }, }, }); const open = Boolean(anchorEl); const id = open ? 'about-popper' : undefined; return ( setAnchorEl(null)}>
setAnchorEl(null)}> { props.onKeyDown?.(event); if (event.key.match(/(ArrowLeft|ArrowRight|Tab)/)) { setAnchorEl(null); } if (event.key === 'ArrowDown') { event.preventDefault(); targets[0]?.focus(); setActiveIndex(0); } }} onFocus={(event) => setAnchorEl(event.currentTarget)} onMouseEnter={(event) => { props.onMouseEnter?.(event); setAnchorEl(event.currentTarget); }} sx={[open && ((theme) => theme.variants.plainHover.neutral)]} > About Overview Administration Facts
); }); const AdmissionsMenu = React.forwardRef( ({ focusNext, focusPrevious, ...props }, ref) => { const [anchorEl, setAnchorEl] = React.useState(null); const { targets, setActiveIndex, getTargetProps } = useRovingIndex({ initialActiveIndex: null, vertical: true, handlers: { onKeyDown: (event, fns) => { if (event.key.match(/(ArrowDown|ArrowUp|ArrowLeft|ArrowRight)/)) { event.preventDefault(); } if (event.key === 'Tab') { setAnchorEl(null); fns.setActiveIndex(null); } if (event.key === 'ArrowLeft') { setAnchorEl(null); focusPrevious(); } if (event.key === 'ArrowRight') { setAnchorEl(null); focusNext(); } }, }, }); const open = Boolean(anchorEl); const id = open ? 'admissions-popper' : undefined; return ( setAnchorEl(null)}>
setAnchorEl(null)}> { props.onKeyDown?.(event); if (event.key.match(/(ArrowLeft|ArrowRight|Tab)/)) { setAnchorEl(null); } if (event.key === 'ArrowDown') { event.preventDefault(); targets[0]?.focus(); setActiveIndex(0); } }} onFocus={(event) => setAnchorEl(event.currentTarget)} onMouseEnter={(event) => { props.onMouseEnter?.(event); setAnchorEl(event.currentTarget); }} sx={[open && ((theme) => theme.variants.plainHover.neutral)]} > Admissions Apply Last 2 days! Visit } > Photo tour
); }, ); export default function ExampleNavigationMenu() { const { targets, getTargetProps, setActiveIndex, focusNext, focusPrevious } = useRovingIndex(); return ( Home { setActiveIndex(1); targets[1].focus(); }} focusNext={focusNext} focusPrevious={focusPrevious} {...getTargetProps(1)} /> { setActiveIndex(2); targets[2].focus(); }} focusNext={focusNext} focusPrevious={focusPrevious} {...getTargetProps(2)} /> ); }