From 06df9a5e436c2919f277fc60dcd0fc735f8ed5d7 Mon Sep 17 00:00:00 2001 From: anemirovsky Date: Thu, 27 May 2021 17:51:00 -0700 Subject: [PATCH] Add optional aria-label to search inputs. We had an accessibility auditor request that the input fields for search style dropdowns include an aria-label. I've reused the option from #43 to keep things consistent. --- src/js/select2/dropdown/search.js | 5 +++++ src/js/select2/selection/search.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/js/select2/dropdown/search.js b/src/js/select2/dropdown/search.js index 434fdede97..4db6125369 100644 --- a/src/js/select2/dropdown/search.js +++ b/src/js/select2/dropdown/search.js @@ -18,6 +18,11 @@ define([ this.$searchContainer = $search; this.$search = $search.find('input'); + var label = this.options.get( 'label' ); + if ( typeof( label ) === 'string' ) { + this.$search.attr( 'aria-label', label ); + } + $rendered.prepend($search); return $rendered; diff --git a/src/js/select2/selection/search.js b/src/js/select2/selection/search.js index 35df5aa375..b3217d59fa 100644 --- a/src/js/select2/selection/search.js +++ b/src/js/select2/selection/search.js @@ -19,6 +19,11 @@ define([ this.$searchContainer = $search; this.$search = $search.find('input'); + var label = this.options.get( 'label' ); + if ( typeof( label ) === 'string' ) { + this.$search.attr( 'aria-label', label ); + } + var $rendered = decorated.call(this); this._transferTabIndex();