mirror of
https://github.com/dong-nz/cv.git
synced 2026-11-22 16:10:40 +07:00
fix(mobile-menu): focus the sheet panel instead of the Home link so its text stops rolling on open
This commit is contained in:
1 parent
6cd665960a
commit
75ebf65e92
5 files changed
+28
-20
No files matched your search
@@ -19,22 +19,24 @@ export function MobileMenu({ open, onClose }: MobileMenuProps) {
|
||||
const { resolvedTheme, setTheme, palette, setPalette } = useTheme()
|
||||
const location = useLocation()
|
||||
const reduceMotion = useReducedMotion()
|
||||
const firstLinkRef = useRef<HTMLAnchorElement>(null)
|
||||
const sheetRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
return (
|
||||
<AnimatePresence>
|
||||
{open && (
|
||||
<motion.div
|
||||
ref={sheetRef}
|
||||
id="mobile-menu"
|
||||
className="mobile-menu"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
tabIndex={-1}
|
||||
aria-label={strings.nav.menuAria[lang]}
|
||||
initial={{ opacity: 0, y: -12 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: -12 }}
|
||||
transition={{ duration: 0.22, ease: [0.25, 0.1, 0.25, 1] }}
|
||||
onAnimationComplete={() => firstLinkRef.current?.focus()}
|
||||
onAnimationComplete={() => sheetRef.current?.focus()}
|
||||
>
|
||||
<div className="mobile-menu-inner">
|
||||
<nav className="mobile-menu-group" aria-label={strings.nav.groupMenu[lang]}>
|
||||
@@ -52,7 +54,6 @@ export function MobileMenu({ open, onClose }: MobileMenuProps) {
|
||||
>
|
||||
<RollingTextLink
|
||||
to={path}
|
||||
ref={index === 0 ? firstLinkRef : undefined}
|
||||
ariaCurrent={active ? 'page' : undefined}
|
||||
className={active ? 'mobile-menu-link active' : 'mobile-menu-link'}
|
||||
onClick={onClose}
|
||||
|
||||
@@ -22,11 +22,10 @@ interface RollingTextLinkProps {
|
||||
className?: string
|
||||
onClick?: () => void
|
||||
ariaCurrent?: 'page'
|
||||
ref?: React.Ref<HTMLAnchorElement>
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
export function RollingTextLink({ to, className, onClick, ariaCurrent, ref, children }: RollingTextLinkProps) {
|
||||
export function RollingTextLink({ to, className, onClick, ariaCurrent, children }: RollingTextLinkProps) {
|
||||
const reduceMotion = useReducedMotion()
|
||||
const [active, setActive] = useState(false)
|
||||
const activeRef = useRef(false)
|
||||
@@ -73,7 +72,6 @@ export function RollingTextLink({ to, className, onClick, ariaCurrent, ref, chil
|
||||
|
||||
return (
|
||||
<Link
|
||||
ref={ref}
|
||||
to={to}
|
||||
className={className}
|
||||
onClick={onClick}
|
||||
|
||||
Reference in new issue
Block a user