@@ -3,6 +3,7 @@ import { parseWithZod } from '@conform-to/zod'
33import { invariantResponse } from '@epic-web/invariant'
44import { formatDistanceToNow } from 'date-fns'
55import { Img } from 'openimg/react'
6+ import { useRef , useEffect } from 'react'
67import { data , Form , Link } from 'react-router'
78import { z } from 'zod'
89import { GeneralErrorBoundary } from '#app/components/error-boundary.tsx'
@@ -99,9 +100,26 @@ export default function NoteRoute({
99100 )
100101 const displayBar = canDelete || isOwner
101102
103+ // Add ref for auto-focusing
104+ const sectionRef = useRef < HTMLElement > ( null )
105+
106+ // Focus the section when the note ID changes
107+ useEffect ( ( ) => {
108+ if ( sectionRef . current ) {
109+ sectionRef . current . focus ( )
110+ }
111+ } , [ loaderData . note . id ] )
112+
102113 return (
103- < div className = "absolute inset-0 flex flex-col px-10" >
104- < h2 className = "mb-2 pt-12 text-h2 lg:mb-6" > { loaderData . note . title } </ h2 >
114+ < section
115+ ref = { sectionRef }
116+ className = "absolute inset-0 flex flex-col px-10"
117+ aria-labelledby = "note-title"
118+ tabIndex = { - 1 } // Make the section focusable without keyboard navigation
119+ >
120+ < h2 id = "note-title" className = "mb-2 pt-12 text-h2 lg:mb-6" >
121+ { loaderData . note . title }
122+ </ h2 >
105123 < div className = { `${ displayBar ? 'pb-24' : 'pb-12' } overflow-y-auto` } >
106124 < ul className = "flex flex-wrap gap-5 py-5" >
107125 { loaderData . note . images . map ( ( image ) => (
@@ -146,7 +164,7 @@ export default function NoteRoute({
146164 </ div >
147165 </ div >
148166 ) : null }
149- </ div >
167+ </ section >
150168 )
151169}
152170
0 commit comments