@@ -135,6 +135,9 @@ const TabList = ({
135135 ...props
136136} : React . HTMLAttributes < HTMLDivElement > & { isVisible ?: boolean } ) => (
137137 < div
138+ role = "menu"
139+ aria-label = "Examples navigation"
140+ aria-hidden = { ! isVisible }
138141 { ...props }
139142 className = { css `
140143 background-color : # 222 ;
@@ -143,11 +146,14 @@ const TabList = ({
143146 overflow : auto;
144147 padding-top : 0.2em ;
145148 position : absolute;
146- transition : width 0.2s ;
149+ transition :
150+ width 0.2s ,
151+ visibility 0.2s ;
147152 width : ${ isVisible ? '200px' : '0' } ;
148153 white-space : nowrap;
149154 max-height : 70vh ;
150155 z-index : 3 ; /* To appear above the underlay */
156+ visibility : ${ isVisible ? 'visible' : 'hidden' } ;
151157 ` }
152158 />
153159)
@@ -171,10 +177,16 @@ const TabListUnderlay = ({
171177)
172178
173179const TabButton = ( props : React . HTMLAttributes < HTMLSpanElement > ) => (
174- < span
180+ < button
175181 { ...props }
182+ aria-label = "Toggle examples menu"
183+ aria-haspopup = "menu"
176184 className = { css `
177185 margin-left : 0.8em ;
186+ background : none;
187+ border : none;
188+ cursor : pointer;
189+ padding : 0 ;
178190
179191 & : hover {
180192 cursor : pointer;
@@ -204,6 +216,8 @@ const Tab = React.forwardRef(
204216 < a
205217 ref = { ref }
206218 href = { href }
219+ role = "menuitem"
220+ aria-current = { active ? 'page' : undefined }
207221 { ...props }
208222 className = { css `
209223 display : inline-block;
@@ -342,6 +356,12 @@ const ExamplePage = ({ example }: { example: string }) => {
342356 e . stopPropagation ( )
343357 setShowTabs ( ! showTabs )
344358 } }
359+ onKeyDown = { ( e : React . KeyboardEvent ) => {
360+ if ( e . key === 'Escape' ) {
361+ setShowTabs ( false )
362+ }
363+ } }
364+ aria-expanded = { showTabs }
345365 >
346366 < Icon > menu</ Icon >
347367 </ TabButton >
@@ -368,7 +388,17 @@ const ExamplePage = ({ example }: { example: string }) => {
368388 legacyBehavior
369389 passHref
370390 >
371- < Tab onClick = { ( ) => setShowTabs ( false ) } > { n } </ Tab >
391+ < Tab
392+ onClick = { ( ) => setShowTabs ( false ) }
393+ active = { p === path }
394+ onKeyDown = { ( e : React . KeyboardEvent ) => {
395+ if ( e . key === 'Escape' ) {
396+ setShowTabs ( false )
397+ }
398+ } }
399+ >
400+ { n }
401+ </ Tab >
372402 </ Link >
373403 ) ) }
374404 </ TabList >
@@ -393,6 +423,11 @@ const ExamplePage = ({ example }: { example: string }) => {
393423 < TabListUnderlay
394424 isVisible = { showTabs }
395425 onClick = { ( ) => setShowTabs ( false ) }
426+ onKeyDown = { ( e : React . KeyboardEvent ) => {
427+ if ( e . key === 'Escape' ) {
428+ setShowTabs ( false )
429+ }
430+ } }
396431 />
397432 </ div >
398433 </ ErrorBoundary >
0 commit comments