@@ -207,14 +207,6 @@ function isDescendantOfNativeHostLanguageTextAlternativeElement(
207
207
return false ;
208
208
}
209
209
210
- /**
211
- * TODO https://github.com/eps1lon/dom-accessibility-api/issues/101
212
- */
213
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- not implemented yet
214
- function computeTooltipAttributeValue ( node : Node ) : string | null {
215
- return null ;
216
- }
217
-
218
210
function getValueOfTextbox ( element : Element ) : string {
219
211
if ( isHTMLInputElement ( element ) || isHTMLTextAreaElement ( element ) ) {
220
212
return element . value ;
@@ -401,30 +393,38 @@ export function computeTextAlternative(
401
393
return accumulatedText . trim ( ) ;
402
394
}
403
395
404
- function computeElementTextAlternative ( node : Node ) : string | null {
396
+ /**
397
+ *
398
+ * @param element
399
+ * @param attributeName
400
+ * @returns A string non-empty string or `null`
401
+ */
402
+ function useAttribute (
403
+ element : Element ,
404
+ attributeName : string
405
+ ) : string | null {
406
+ const attribute = element . getAttributeNode ( attributeName ) ;
407
+ if (
408
+ attribute !== null &&
409
+ ! consultedNodes . has ( attribute ) &&
410
+ attribute . value . trim ( ) !== ""
411
+ ) {
412
+ consultedNodes . add ( attribute ) ;
413
+ return attribute . value ;
414
+ }
415
+ return null ;
416
+ }
417
+
418
+ function computeTooltipAttributeValue ( node : Node ) : string | null {
405
419
if ( ! isElement ( node ) ) {
406
420
return null ;
407
421
}
408
422
409
- /**
410
- *
411
- * @param element
412
- * @param attributeName
413
- * @returns A string non-empty string or `null`
414
- */
415
- function useAttribute (
416
- element : Element ,
417
- attributeName : string
418
- ) : string | null {
419
- const attribute = element . getAttributeNode ( attributeName ) ;
420
- if (
421
- attribute !== null &&
422
- ! consultedNodes . has ( attribute ) &&
423
- attribute . value . trim ( ) !== ""
424
- ) {
425
- consultedNodes . add ( attribute ) ;
426
- return attribute . value ;
427
- }
423
+ return useAttribute ( node , "title" ) ;
424
+ }
425
+
426
+ function computeElementTextAlternative ( node : Node ) : string | null {
427
+ if ( ! isElement ( node ) ) {
428
428
return null ;
429
429
}
430
430
@@ -547,10 +547,9 @@ export function computeTextAlternative(
547
547
if ( nameFromSubTree !== "" ) {
548
548
return nameFromSubTree ;
549
549
}
550
- return useAttribute ( node , "title" ) ;
551
550
}
552
551
553
- return useAttribute ( node , "title" ) ;
552
+ return null ;
554
553
}
555
554
556
555
function computeTextAlternative (
@@ -673,11 +672,14 @@ export function computeTextAlternative(
673
672
isNativeHostLanguageTextAlternativeElement ( current ) ||
674
673
isDescendantOfNativeHostLanguageTextAlternativeElement ( current )
675
674
) {
676
- consultedNodes . add ( current ) ;
677
- return computeMiscTextAlternative ( current , {
675
+ const accumulatedText2F = computeMiscTextAlternative ( current , {
678
676
isEmbeddedInLabel : context . isEmbeddedInLabel ,
679
677
isReferenced : false ,
680
678
} ) ;
679
+ if ( accumulatedText2F !== "" ) {
680
+ consultedNodes . add ( current ) ;
681
+ return accumulatedText2F ;
682
+ }
681
683
}
682
684
683
685
if ( current . nodeType === current . TEXT_NODE ) {
0 commit comments