@@ -16,11 +16,9 @@ import React, {
1616import { FocusableElement , tabbable } from 'tabbable' ;
1717import classNames from 'classnames' ;
1818
19- import { keys } from '../../../../services' ;
20- import { useGeneratedHtmlId } from '../../../../services/accessibility' ;
19+ import { keys , useGeneratedHtmlId } from '../../../../services' ;
2120import { isDOMNode } from '../../../../utils' ;
2221import { EuiFocusTrap } from '../../../focus_trap' ;
23- import { EuiScreenReaderOnly } from '../../../accessibility' ;
2422import { EuiI18n } from '../../../i18n' ;
2523
2624/**
@@ -92,14 +90,8 @@ export const FocusTrappedChildren: FunctionComponent<
9290 const [ isCellEntered , setIsCellEntered ] = useState ( false ) ;
9391 const [ isExited , setExited ] = useState ( false ) ;
9492
95- const keyboardHintAriaId = useGeneratedHtmlId ( {
96- prefix : 'euiDataGridCellHeader' ,
97- suffix : 'keyboardHint' ,
98- } ) ;
99-
100- const exitedHintAriaId = useGeneratedHtmlId ( {
101- prefix : 'euiDataGridCellHeader' ,
102- suffix : 'exited' ,
93+ const ariaDescribedById = useGeneratedHtmlId ( {
94+ suffix : 'focusTrapHint' ,
10395 } ) ;
10496
10597 // direct DOM manipulation as workaround to attach required hints
@@ -108,9 +100,17 @@ export const FocusTrappedChildren: FunctionComponent<
108100
109101 cellEl . setAttribute (
110102 'aria-describedby' ,
111- classNames ( currentAriaDescribedbyId , exitedHintAriaId , keyboardHintAriaId )
103+ classNames ( currentAriaDescribedbyId , ariaDescribedById )
112104 ) ;
113- } , [ cellEl , keyboardHintAriaId , exitedHintAriaId ] ) ;
105+
106+ return ( ) => {
107+ if ( currentAriaDescribedbyId ) {
108+ cellEl . setAttribute ( 'aria-descibedby' , currentAriaDescribedbyId ) ;
109+ } else {
110+ cellEl . removeAttribute ( 'aria-describedby' ) ;
111+ }
112+ } ;
113+ } , [ cellEl , ariaDescribedById ] ) ;
114114
115115 useEffect ( ( ) => {
116116 if ( isCellEntered ) {
@@ -173,37 +173,31 @@ export const FocusTrappedChildren: FunctionComponent<
173173 >
174174 { children }
175175
176- < EuiScreenReaderOnly >
177- { /**
178- * Hints use aria-hidden to prevent them from being read as regular content.
179- * They are still read in JAWS and NVDA via the linking with aria-describedby.
180- * VoiceOver does generally not read the column on re-focus after exiting a cell,
181- * which mean the exited hint is not read.
182- * VoiceOver does react to aria-live (without aria-hidden) but that would causes
183- * duplicate output in JAWS/NVDA (reading content & live announcement).
184- * Optimizing for Windows screen readers as they have a larger usages.
185- */ }
186- < p id = { exitedHintAriaId } aria-hidden = "true" >
187- { isExited && (
188- < EuiI18n
189- // eslint-disable-next-line local/i18n
190- token = "euiDataGridCell.focusTrapExitPrompt"
191- default = "Exited cell content."
192- />
193- ) }
194- </ p >
195- </ EuiScreenReaderOnly >
196- < EuiScreenReaderOnly >
197- < p id = { keyboardHintAriaId } aria-hidden = "true" >
198- { ! isCellEntered && (
199- < EuiI18n
200- // eslint-disable-next-line local/i18n
201- token = "euiDataGridCell.focusTrapEnterPrompt"
202- default = "Press the Enter key to interact with this cell's contents."
203- />
204- ) }
205- </ p >
206- </ EuiScreenReaderOnly >
176+ { /**
177+ * Hints use `hidden` to prevent them from being read by screen readers as regular content.
178+ * They are still read in JAWS and NVDA via the linking with aria-describedby.
179+ * VoiceOver does generally not read the column on re-focus after exiting a cell,
180+ * which mean the exited hint is not read.
181+ * VoiceOver does react to aria-live (without aria-hidden) but that would causes
182+ * duplicate output in JAWS/NVDA (reading content & live announcement).
183+ * Optimizing for Windows screen readers as they have a larger usages.
184+ */ }
185+ < p id = { ariaDescribedById } hidden >
186+ { isExited && (
187+ < EuiI18n
188+ // eslint-disable-next-line local/i18n
189+ token = "euiDataGridCell.focusTrapExitPrompt"
190+ default = "Exited cell content."
191+ />
192+ ) }
193+ { ! isCellEntered && (
194+ < EuiI18n
195+ // eslint-disable-next-line local/i18n
196+ token = "euiDataGridCell.focusTrapEnterPrompt"
197+ default = "Press the Enter key to interact with this cell's contents."
198+ />
199+ ) }
200+ </ p >
207201 </ EuiFocusTrap >
208202 ) ;
209203} ;
0 commit comments