Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 59d21f5

Browse files
endilieySylvain Pace
authored andcommitted
fix: docsearch input should have aria-label (a11y) (#687)
* fix: search input a11y issue * fix: docsearch input should have aria-label (a11y) * update test
1 parent c0e9e19 commit 59d21f5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/lib/DocSearch.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class DocSearch {
8080
this.autocompleteOptions.cssClasses || {};
8181
this.autocompleteOptions.cssClasses.prefix =
8282
this.autocompleteOptions.cssClasses.prefix || 'ds';
83-
83+
const inputAriaLabel = this.input && typeof this.input.attr === 'function' && this.input.attr('aria-label');
84+
this.autocompleteOptions.ariaLabel =
85+
this.autocompleteOptions.ariaLabel || inputAriaLabel || "search input";
8486

8587
this.isSimpleLayout = layout === 'simple';
8688

src/lib/__tests__/DocSearch-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ describe('DocSearch', () => {
175175
debug: false,
176176
cssClasses: { prefix: 'ds' },
177177
anOption: 44,
178+
ariaLabel: 'search input',
178179
});
179180
});
180181
it('should instantiate algoliasearch with the correct values', () => {
@@ -217,6 +218,7 @@ describe('DocSearch', () => {
217218
anOption: '44',
218219
cssClasses: { prefix: 'ds' },
219220
debug: false,
221+
ariaLabel: 'search input'
220222
})
221223
).toBe(true);
222224
});

0 commit comments

Comments
 (0)