fix(mobile-menu): focus the sheet panel instead of the Home link so its text stops rolling on open

This commit is contained in:
dong.nguyen committed 2026-10-17 15:11:21 +07:00
1 parent 6cd665960a
commit 75ebf65e92
5 files changed
+28 -20

No files matched your search

+7
View File
@@ -155,6 +155,13 @@
overscroll-behavior: contain;
}
/* The sheet itself is the focus target on open (`tabIndex={-1}` on the panel in
`MobileMenu.tsx`). A ring here would frame the whole viewport, and every control inside
already carries its own `:focus-visible` rule. */
.mobile-menu:focus {
outline: none;
}
.mobile-menu-inner {
max-width: var(--max-content);
margin: 0 auto;
+4 -3
View File
@@ -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}
+1 -3
View File
@@ -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}