Skip to content

Commit 1c74e4f

Browse files
OwenEdwardsgkatsev
authored andcommitted
fix: Reduce the multiple-announcement by screen readers of the new name of a button when its text label changes. (videojs#5158)
Move the aria-live attribute to the control text element within buttons, rather than on the whole button, so it is not affected by the change of the title attribute, only by the change of the control text. It seems like having aria-live on the button itself means that JAWS and NVDA announce the button both when the button text changes and when the title attribute changes. NVDA speaks the new label more times because it announces the button text as the label and the title as the description, so it says, for example, "pause button pause". JAWS doesn't appear to do this, so it doesn't repeat it as many times. Partially addresses videojs#5023
1 parent de9c4da commit 1c74e4f

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/js/button.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ class Button extends ClickableComponent {
4141
attributes = assign({
4242

4343
// Necessary since the default button type is "submit"
44-
'type': 'button',
45-
46-
// let the screen reader user know that the text of the button may change
47-
'aria-live': 'polite'
44+
type: 'button'
4845
}, attributes);
4946

5047
const el = Component.prototype.createEl.call(this, tag, props, attributes);

src/js/clickable-component.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ class ClickableComponent extends Component {
6262

6363
// Add ARIA attributes for clickable element which is not a native HTML button
6464
attributes = assign({
65-
'role': 'button',
66-
67-
// let the screen reader user know that the text of the element may change
68-
'aria-live': 'polite'
65+
role: 'button'
6966
}, attributes);
7067

7168
this.tabIndex_ = props.tabIndex;
@@ -96,6 +93,9 @@ class ClickableComponent extends Component {
9693
createControlTextEl(el) {
9794
this.controlTextEl_ = Dom.createEl('span', {
9895
className: 'vjs-control-text'
96+
}, {
97+
// let the screen reader user know that the text of the element may change
98+
'aria-live': 'polite'
9999
});
100100

101101
if (el) {

test/unit/button.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ QUnit.test('should localize its text', function(assert) {
2222
const el = testButton.createEl();
2323

2424
assert.ok(el.nodeName.toLowerCase().match('button'));
25-
assert.ok(el.innerHTML.match(/vjs-control-text"?>Juego/));
25+
assert.ok(el.innerHTML.match(/vjs-control-text"?[^<>]*>Juego/));
2626
assert.equal(el.getAttribute('title'), 'Juego');
2727

2828
testButton.dispose();

0 commit comments

Comments
 (0)