import styles from './mobile-navigation.module.css' import { useEffect, useRef, useState } from 'react' import { useLocation } from 'react-router' import { ActionButton } from '@react-spectrum/s2/ActionButton' import CloseIcon from '@react-spectrum/s2/icons/Close' import ViewListIcon from '@react-spectrum/s2/icons/ViewList' import SidebarMenu from './sidebar-menu' function MobileNavigation() { const dialogRef = useRef(null) const [isOpen, setIsOpen] = useState(false) const { key } = useLocation() // Close after all route changes, including selecting the current page. useEffect(() => { dialogRef.current?.close() }, [key]) useEffect(() => { const media = window.matchMedia('(max-width: 640px)') const closeOnDesktop = () => { if (!media.matches) dialogRef.current?.close() } media.addEventListener('change', closeOnDesktop) return () => media.removeEventListener('change', closeOnDesktop) }, []) return (
{ dialogRef.current?.showModal() setIsOpen(true) }} > setIsOpen(false)} >
菜单 dialogRef.current?.close()}>
) } export default MobileNavigation