Skip to content

Commit fc43f00

Browse files
committed
Only use aria-owns when the dropdown is open
This fixes part of select2#3144.
1 parent 7e4e8bc commit fc43f00

5 files changed

Lines changed: 10 additions & 8 deletions

File tree

dist/js/select2.full.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,6 @@ S2.define('select2/selection/base',[
12931293

12941294
this.container = container;
12951295

1296-
this.$selection.attr('aria-owns', resultsId);
1297-
12981296
this.$selection.on('focus', function (evt) {
12991297
self.trigger('focus', evt);
13001298
});
@@ -1322,6 +1320,7 @@ S2.define('select2/selection/base',[
13221320
container.on('open', function () {
13231321
// When the dropdown is open, aria-expanded="true"
13241322
self.$selection.attr('aria-expanded', 'true');
1323+
self.$selection.attr('aria-owns', resultsId);
13251324

13261325
self._attachCloseHandler(container);
13271326
});
@@ -1330,6 +1329,7 @@ S2.define('select2/selection/base',[
13301329
// When the dropdown is closed, aria-expanded="false"
13311330
self.$selection.attr('aria-expanded', 'false');
13321331
self.$selection.removeAttr('aria-activedescendant');
1332+
self.$selection.removeAttr('aria-owns');
13331333

13341334
self.$selection.focus();
13351335

@@ -4201,6 +4201,7 @@ S2.define('select2/i18n/en',[],function () {
42014201
S2.define('select2/defaults',[
42024202
'jquery',
42034203
'require',
4204+
42044205
'./results',
42054206

42064207
'./selection/single',

dist/js/select2.full.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,6 @@ S2.define('select2/selection/base',[
12931293

12941294
this.container = container;
12951295

1296-
this.$selection.attr('aria-owns', resultsId);
1297-
12981296
this.$selection.on('focus', function (evt) {
12991297
self.trigger('focus', evt);
13001298
});
@@ -1322,6 +1320,7 @@ S2.define('select2/selection/base',[
13221320
container.on('open', function () {
13231321
// When the dropdown is open, aria-expanded="true"
13241322
self.$selection.attr('aria-expanded', 'true');
1323+
self.$selection.attr('aria-owns', resultsId);
13251324

13261325
self._attachCloseHandler(container);
13271326
});
@@ -1330,6 +1329,7 @@ S2.define('select2/selection/base',[
13301329
// When the dropdown is closed, aria-expanded="false"
13311330
self.$selection.attr('aria-expanded', 'false');
13321331
self.$selection.removeAttr('aria-activedescendant');
1332+
self.$selection.removeAttr('aria-owns');
13331333

13341334
self.$selection.focus();
13351335

@@ -4201,6 +4201,7 @@ S2.define('select2/i18n/en',[],function () {
42014201
S2.define('select2/defaults',[
42024202
'jquery',
42034203
'require',
4204+
42044205
'./results',
42054206

42064207
'./selection/single',

dist/js/select2.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/select2/selection/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ define([
4343

4444
this.container = container;
4545

46-
this.$selection.attr('aria-owns', resultsId);
47-
4846
this.$selection.on('focus', function (evt) {
4947
self.trigger('focus', evt);
5048
});
@@ -72,6 +70,7 @@ define([
7270
container.on('open', function () {
7371
// When the dropdown is open, aria-expanded="true"
7472
self.$selection.attr('aria-expanded', 'true');
73+
self.$selection.attr('aria-owns', resultsId);
7574

7675
self._attachCloseHandler(container);
7776
});
@@ -80,6 +79,7 @@ define([
8079
// When the dropdown is closed, aria-expanded="false"
8180
self.$selection.attr('aria-expanded', 'false');
8281
self.$selection.removeAttr('aria-activedescendant');
82+
self.$selection.removeAttr('aria-owns');
8383

8484
self.$selection.focus();
8585

0 commit comments

Comments
 (0)