Skip to content

Commit b345524

Browse files
authored
fix: always set aria-controls attribute on popover target (#11999)
1 parent 1db50ae commit b345524

2 files changed

Lines changed: 5 additions & 10 deletions

File tree

‎packages/popover/src/vaadin-popover.js‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,8 @@ class Popover extends PopoverPositionMixin(
697697

698698
effectiveTarget.setAttribute('aria-expanded', opened ? 'true' : 'false');
699699

700-
if (opened) {
701-
effectiveTarget.setAttribute('aria-controls', this.id);
702-
} else {
703-
effectiveTarget.removeAttribute('aria-controls');
704-
}
700+
// Always set aria-controls to make VoiceOver + Chrome announce it.
701+
effectiveTarget.setAttribute('aria-controls', this.id);
705702

706703
this.__oldTarget = target;
707704
}

‎packages/popover/test/a11y.test.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,17 @@ describe('a11y', () => {
130130
expect(element.getAttribute('aria-expanded')).to.equal('true');
131131
});
132132

133-
it(`should set aria-controls attribute on the ${prop} when opened`, async () => {
134-
popover.opened = true;
135-
await oneEvent(overlay, 'vaadin-overlay-open');
133+
it(`should set aria-controls attribute on the ${prop} by default`, () => {
136134
expect(element.getAttribute('aria-controls')).to.equal(popover.id);
137135
});
138136

139-
it(`should remove aria-controls attribute from the ${prop} when closed`, async () => {
137+
it(`should keep aria-controls attribute on the ${prop} when closed`, async () => {
140138
popover.opened = true;
141139
await oneEvent(overlay, 'vaadin-overlay-open');
142140

143141
popover.opened = false;
144142
await nextUpdate(popover);
145-
expect(element.hasAttribute('aria-controls')).to.be.false;
143+
expect(element.getAttribute('aria-controls')).to.equal(popover.id);
146144
});
147145

148146
it(`should remove aria-haspopup attribute from ${prop} when target is cleared`, async () => {

0 commit comments

Comments
 (0)