From 59d21f5e19aec3d8f85106532075ad0ff806e382 Mon Sep 17 00:00:00 2001 From: Endi Date: Mon, 13 May 2019 20:15:38 +0700 Subject: [PATCH] fix: docsearch input should have aria-label (a11y) (#687) * fix: search input a11y issue * fix: docsearch input should have aria-label (a11y) * update test --- src/lib/DocSearch.js | 4 +++- src/lib/__tests__/DocSearch-test.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/DocSearch.js b/src/lib/DocSearch.js index 0bcd168d..d469f531 100644 --- a/src/lib/DocSearch.js +++ b/src/lib/DocSearch.js @@ -80,7 +80,9 @@ class DocSearch { this.autocompleteOptions.cssClasses || {}; this.autocompleteOptions.cssClasses.prefix = this.autocompleteOptions.cssClasses.prefix || 'ds'; - + const inputAriaLabel = this.input && typeof this.input.attr === 'function' && this.input.attr('aria-label'); + this.autocompleteOptions.ariaLabel = + this.autocompleteOptions.ariaLabel || inputAriaLabel || "search input"; this.isSimpleLayout = layout === 'simple'; diff --git a/src/lib/__tests__/DocSearch-test.js b/src/lib/__tests__/DocSearch-test.js index 541c9bbb..2fccb60f 100644 --- a/src/lib/__tests__/DocSearch-test.js +++ b/src/lib/__tests__/DocSearch-test.js @@ -175,6 +175,7 @@ describe('DocSearch', () => { debug: false, cssClasses: { prefix: 'ds' }, anOption: 44, + ariaLabel: 'search input', }); }); it('should instantiate algoliasearch with the correct values', () => { @@ -217,6 +218,7 @@ describe('DocSearch', () => { anOption: '44', cssClasses: { prefix: 'ds' }, debug: false, + ariaLabel: 'search input' }) ).toBe(true); });