Skip to content

Commit d349a0c

Browse files
authored
fix: Improve representation of FlyoutButtons in screenreaders. (#9356)
* fix: Improve representation of `FlyoutButtons` in screenreaders. * fix: Remove aria-selected.
1 parent 41b7e93 commit d349a0c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

core/flyout_button.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,17 @@ export class FlyoutButton
114114
this.id = idGenerator.getNextUniqueId();
115115
this.svgGroup = dom.createSvgElement(
116116
Svg.G,
117-
{'id': this.id, 'class': cssClass},
117+
{'id': this.id, 'class': cssClass, 'tabindex': '-1'},
118118
this.workspace.getCanvas(),
119119
);
120120

121-
aria.setRole(this.svgGroup, aria.Role.BUTTON);
122-
aria.setState(this.svgGroup, aria.State.LABEL, 'Button');
121+
// Set the accessibility role. All child nodes will be set to `presentation`
122+
// to avoid extraneous "group" narration on VoiceOver.
123+
if (this.isFlyoutLabel) {
124+
aria.setRole(this.svgGroup, aria.Role.TREEITEM);
125+
} else {
126+
aria.setRole(this.svgGroup, aria.Role.BUTTON);
127+
}
123128

124129
let shadow;
125130
if (!this.isFlyoutLabel) {
@@ -135,6 +140,7 @@ export class FlyoutButton
135140
},
136141
this.svgGroup!,
137142
);
143+
aria.setRole(shadow, aria.Role.PRESENTATION);
138144
}
139145
// Background rectangle.
140146
const rect = dom.createSvgElement(
@@ -148,6 +154,7 @@ export class FlyoutButton
148154
},
149155
this.svgGroup!,
150156
);
157+
aria.setRole(rect, aria.Role.PRESENTATION);
151158

152159
const svgText = dom.createSvgElement(
153160
Svg.TEXT,
@@ -159,6 +166,9 @@ export class FlyoutButton
159166
},
160167
this.svgGroup!,
161168
);
169+
if (!this.isFlyoutLabel) {
170+
aria.setRole(svgText, aria.Role.PRESENTATION);
171+
}
162172
let text = parsing.replaceMessageReferences(this.text);
163173
if (this.workspace.RTL) {
164174
// Force text to be RTL by adding an RLM.

0 commit comments

Comments
 (0)