Skip to content

Commit

Permalink
fix(a11y): Add meaningful alt text to image viewer (#1349)
Browse files Browse the repository at this point in the history
  • Loading branch information
tille committed Apr 7, 2021
1 parent c40435e commit fc9c662
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib/viewers/image/ImageViewer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import getProp from 'lodash/get';
import AnnotationControlsFSM, { AnnotationInput, AnnotationMode, AnnotationState } from '../../AnnotationControlsFSM';
import ImageBaseViewer from './ImageBaseViewer';
import ImageControls from './ImageControls';
Expand Down Expand Up @@ -81,6 +82,9 @@ class ImageViewer extends ImageBaseViewer {

this.currentRotationAngle = 0;

const fileName = getProp(this.options, 'file.name');
this.imageEl.setAttribute('alt', fileName);

if (this.options.enableAnnotationsImageDiscoverability) {
this.addListener('zoom', this.handleZoomEvent);
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/viewers/image/__tests__/ImageViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('lib/viewers/image/ImageViewer', () => {
container: containerEl,
file: {
id: '1',
name: 'tales.png',
file_version: {
id: '1',
},
Expand Down Expand Up @@ -88,6 +89,7 @@ describe('lib/viewers/image/ImageViewer', () => {
test('should set up layout', () => {
expect(image.wrapperEl).toHaveClass('bp-image');
expect(image.imageEl).toHaveClass('bp-is-invisible');
expect(image.imageEl).toHaveAttribute('alt', 'tales.png');
});

test.each`
Expand Down

0 comments on commit fc9c662

Please sign in to comment.