@@ -31,7 +31,14 @@ function BitmapImage({ alt, bitmap, classes, scale = 1.0 }: BitmapImageProps) {
31
31
width = { bitmap . width }
32
32
height = { bitmap . height }
33
33
role = "img"
34
+ // The `alt` attribute on an `<img>` maps to aria-label. We might want to
35
+ // split this into a separate concise label and longer description in
36
+ // future.
34
37
aria-label = { alt }
38
+ // Set the title attribute to make it easy to inspect the alt text on
39
+ // desktop. Screen readers will only read `aria-label` since it has the
40
+ // same value.
41
+ title = { alt }
35
42
className = { classes }
36
43
style = { {
37
44
width : `${ bitmap . width / scale } px` ,
@@ -44,9 +51,17 @@ function BitmapImage({ alt, bitmap, classes, scale = 1.0 }: BitmapImageProps) {
44
51
export type AnnotationThumbnailProps = {
45
52
tag : string ;
46
53
thumbnailService : ThumbnailService ;
54
+
55
+ /**
56
+ * Text contained in the thumbnail.
57
+ *
58
+ * This is used when generating alt text for the thumbnail.
59
+ */
60
+ textInImage ?: string ;
47
61
} ;
48
62
49
63
function AnnotationThumbnail ( {
64
+ textInImage,
50
65
tag,
51
66
thumbnailService,
52
67
} : AnnotationThumbnailProps ) {
@@ -69,14 +84,21 @@ function AnnotationThumbnail({
69
84
}
70
85
} , [ error , devicePixelRatio , tag , thumbnail , thumbnailService ] ) ;
71
86
87
+ let altText ;
88
+ if ( textInImage ) {
89
+ altText = `Thumbnail. Contains text: ${ textInImage } ` ;
90
+ } else {
91
+ altText = 'Thumbnail' ;
92
+ }
93
+
72
94
return (
73
95
< div
74
96
className = "flex flex-row justify-center"
75
97
data-testid = "thumbnail-container"
76
98
>
77
99
{ thumbnail && (
78
100
< BitmapImage
79
- alt = "annotated content thumbnail"
101
+ alt = { altText }
80
102
bitmap = { thumbnail }
81
103
classes = "border rounded-md"
82
104
scale = { devicePixelRatio }
0 commit comments