@@ -27,6 +27,30 @@ export type InfoTipProps = TipBaseProps & {
2727 onClick ?: ( arg0 : { isTipHidden : boolean } ) => void ;
2828} ;
2929
30+ // Helper function to recursively extract text content from React elements
31+ // Converts everything to plain text for screenreader announcements
32+ const extractTextContent = ( children : React . ReactNode ) : string => {
33+ if ( typeof children === 'string' || typeof children === 'number' ) {
34+ return String ( children ) ;
35+ }
36+
37+ return Children . toArray ( children )
38+ . map ( ( child ) => {
39+ if ( typeof child === 'string' || typeof child === 'number' ) {
40+ return String ( child ) ;
41+ }
42+ if ( typeof child === 'boolean' || child == null ) {
43+ return '' ;
44+ }
45+ if ( isValidElement ( child ) ) {
46+ return extractTextContent ( child . props . children ) ;
47+ }
48+ return '' ;
49+ } )
50+ . filter ( Boolean )
51+ . join ( ' ' ) ;
52+ } ;
53+
3054export const InfoTip : React . FC < InfoTipProps > = ( {
3155 alignment = 'top-right' ,
3256 emphasis = 'low' ,
@@ -183,28 +207,6 @@ export const InfoTip: React.FC<InfoTipProps> = ({
183207 ...rest ,
184208 } ;
185209
186- const extractTextContent = ( children : React . ReactNode ) : string => {
187- if ( typeof children === 'string' || typeof children === 'number' ) {
188- return String ( children ) ;
189- }
190-
191- return Children . toArray ( children )
192- . map ( ( child ) => {
193- if ( typeof child === 'string' || typeof child === 'number' ) {
194- return String ( child ) ;
195- }
196- if ( typeof child === 'boolean' || child == null ) {
197- return '' ;
198- }
199- if ( isValidElement ( child ) ) {
200- return extractTextContent ( child . props . children ) ;
201- }
202- return '' ;
203- } )
204- . filter ( Boolean )
205- . join ( ' ' ) ;
206- } ;
207-
208210 const extractedTextContent = useMemo ( ( ) => extractTextContent ( info ) , [ info ] ) ;
209211
210212 const screenreaderInfo =
0 commit comments