From e0fba828c97bfc91b8f268f2047eff33fccc989a Mon Sep 17 00:00:00 2001 From: Matt Bargar Date: Thu, 9 Aug 2018 11:23:02 -0400 Subject: [PATCH] Make query bar autocomplete screen reader accessible (#20740) Fixes https://github.com/elastic/kibana/issues/20099 I made the changes described by Tim at https://github.com/elastic/kibana/issues/20099 and everything seems to be working. I tried to update the typeahead in such a way that it can be made accessible anywhere it is used, even if there are multiple typeahead instances on a single page. > (optional) an aria-label on the individual suggestions that should be read out to screen reader. By default the content will be used, and that should be fine (unless you figure out there is too much "noise" elements in it. I did not do this bit since the text that is read seems reasonable to me, but I'm open to changing it if others feel differently. --- src/ui/public/query_bar/directive/query_bar.html | 10 ++++++++++ src/ui/public/query_bar/directive/query_bar.js | 1 + src/ui/public/query_bar/directive/suggestion.html | 10 +++++----- src/ui/public/typeahead/typeahead.html | 8 ++++++++ src/ui/public/typeahead/typeahead.js | 8 +++++++- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/ui/public/query_bar/directive/query_bar.html b/src/ui/public/query_bar/directive/query_bar.html index bc99e881b5cc0..19615afe77192 100644 --- a/src/ui/public/query_bar/directive/query_bar.html +++ b/src/ui/public/query_bar/directive/query_bar.html @@ -6,7 +6,9 @@
@@ -51,6 +57,10 @@ class="kuiLocalSearchInput" ng-class="{'kuiLocalSearchInput-isInvalid': queryBarForm.$invalid}" data-test-subj="queryInput" + aria-autocomplete="list" + aria-controls="query-bar-suggestions-typeahead-items" + aria-activedescendant="{{queryBar.focusedTypeaheadItemID}}" + role="textbox" />
{ if (compact(this.indexPatterns).length) return Promise.resolve(this.indexPatterns); diff --git a/src/ui/public/query_bar/directive/suggestion.html b/src/ui/public/query_bar/directive/suggestion.html index 6dc47e86aff1c..a68ea51767b88 100644 --- a/src/ui/public/query_bar/directive/suggestion.html +++ b/src/ui/public/query_bar/directive/suggestion.html @@ -1,19 +1,19 @@
-
+
-
+
-
+
-
+
-
+
diff --git a/src/ui/public/typeahead/typeahead.html b/src/ui/public/typeahead/typeahead.html index c959342630c98..39b1fa2b802a5 100644 --- a/src/ui/public/typeahead/typeahead.html +++ b/src/ui/public/typeahead/typeahead.html @@ -2,6 +2,10 @@ class="typeahead" ng-keydown="typeahead.onKeyDown($event)" ng-keypress="typeahead.onKeyPress($event)" + role="combobox" + aria-haspopup="true" + aria-owns="{{typeahead.elementID}}-typeahead-items" + aria-expanded="{{typeahead.isVisible() ? true : false}}" >
{ const item = this.items[this.selectedIndex]; @@ -137,6 +139,10 @@ typeahead.directive('kbnTypeahead', function () { this.onMouseLeave = () => { this.isMousedOver = false; }; + + $scope.$watch('typeahead.selectedIndex', (newIndex) => { + this.onFocusChange({ $focusedItemID: newIndex !== null ? `${this.elementID}-typeahead-item-${newIndex}` : '' }); + }); } }; });