Skip to content

Commit

Permalink
Fix readonly state's a11y
Browse files Browse the repository at this point in the history
  • Loading branch information
samiheikki authored and web-padawan committed Feb 13, 2020
1 parent c4be7b3 commit ccbd03c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
28 changes: 22 additions & 6 deletions src/vaadin-combo-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@
*/
disabled: {
type: Boolean,
value: false
value: false,
observer: '_disabledChanged'
},

/**
Expand Down Expand Up @@ -330,7 +331,8 @@

readonly: {
type: Boolean,
value: false
value: false,
observer: '_readonlyChanged'
},

/**
Expand Down Expand Up @@ -381,9 +383,9 @@
}
}, true);

this._nativeInput.setAttribute('role', 'combobox');
this._nativeInput.setAttribute('aria-autocomplete', 'list');
this.setAttribute('role', 'combobox');
this._updateAriaExpanded();
this._updateNativeInputAriaAutoComplete();
}

connectedCallback() {
Expand All @@ -401,12 +403,26 @@
}

_updateAriaExpanded() {
this.setAttribute('aria-expanded', this.opened);
}

_updateNativeInputAriaAutoComplete() {
if (this._nativeInput) {
this._nativeInput.setAttribute('aria-expanded', this.opened);
this._toggleElement.setAttribute('aria-expanded', this.opened);
this.readonly || this.disabled ?
this._nativeInput.setAttribute('aria-autocomplete', 'none') :
this._nativeInput.setAttribute('aria-autocomplete', 'list');
}
}

_readonlyChanged() {
this._updateAriaExpanded();
this._updateNativeInputAriaAutoComplete();
}

_disabledChanged() {
this._updateNativeInputAriaAutoComplete();
}

get inputElement() {
return this.$.input;
}
Expand Down
28 changes: 21 additions & 7 deletions test/aria.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,28 @@
afterEach(() => comboBox.opened = false);

describe('when combo-box is attached', () => {
it('should contain appropriate aria attributes', () => {
expect(getNativeInput().getAttribute('role')).to.equal('combobox');
expect(getNativeInput().getAttribute('aria-autocomplete')).to.equal('list');
const assertAriaAttributes = () => {
expect(getNativeInput().hasAttribute('aria-labelledby')).to.be.true;
expect(getToggleIcon().getAttribute('role')).to.equal('button');
expect(getToggleIcon().getAttribute('aria-label')).to.equal('Toggle');
expect(comboBox.getAttribute('role')).to.equal('combobox');
};

it('should contain appropriate aria attributes', () => {
expect(getNativeInput().getAttribute('aria-autocomplete')).to.equal('list');
assertAriaAttributes();
});

it('should contain appropriate aria attributes for readonly input', () => {
comboBox.readonly = true;
expect(getNativeInput().getAttribute('aria-autocomplete')).to.equal('none');
assertAriaAttributes();
});

it('should contain appropriate aria attributes for disabled input', () => {
comboBox.disabled = true;
expect(getNativeInput().getAttribute('aria-autocomplete')).to.equal('none');
assertAriaAttributes();
});
});

Expand All @@ -72,15 +88,13 @@
});

it('should set aria-expanded attribute when opened', () => {
expect(getNativeInput().getAttribute('aria-expanded')).to.equal('true');
expect(getToggleIcon().getAttribute('aria-expanded')).to.equal('true');
expect(comboBox.getAttribute('aria-expanded')).to.equal('true');
});

it('should unset aria-expanded attribute when closed', () => {
esc();

expect(getNativeInput().getAttribute('aria-expanded')).to.equal('false');
expect(getToggleIcon().getAttribute('aria-expanded')).to.equal('false');
expect(comboBox.getAttribute('aria-expanded')).to.equal('false');
});
});

Expand Down

0 comments on commit ccbd03c

Please sign in to comment.