Skip to content

Commit

Permalink
Merge eae5332 into a0705a6
Browse files Browse the repository at this point in the history
  • Loading branch information
samiheikki committed Mar 17, 2019
2 parents a0705a6 + eae5332 commit 52b367e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
27 changes: 23 additions & 4 deletions src/vaadin-combo-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@

readonly: {
type: Boolean,
value: false
value: false,
observer: '_readonlyChanged'
}
};
}
Expand Down Expand Up @@ -365,7 +366,7 @@
this._toggleElement = this.$.toggleButton;
this._clearElement = this.$.clearButton;

this._nativeInput.setAttribute('role', 'combobox');
this._updateNativeInputRole();
this._nativeInput.setAttribute('aria-autocomplete', 'list');
this._updateAriaExpanded();
}
Expand All @@ -380,17 +381,35 @@
this._restoreInputBlur();
}

_updateNativeInputRole() {
if (this._nativeInput) {
this.readonly ?
this._nativeInput.removeAttribute('role') :
this._nativeInput.setAttribute('role', 'combobox');
}
}

_getPositionTarget() {
return this.$.input;
}

_updateAriaExpanded() {
if (this._nativeInput) {
this._nativeInput.setAttribute('aria-expanded', this.opened);
this._toggleElement.setAttribute('aria-expanded', this.opened);
if (this.readonly) {
this._nativeInput.removeAttribute('aria-expanded');
this._toggleElement.removeAttribute('aria-expanded');
} else {
this._nativeInput.setAttribute('aria-expanded', this.opened);
this._toggleElement.setAttribute('aria-expanded', this.opened);
}
}
}

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

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

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

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

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

Expand Down

0 comments on commit 52b367e

Please sign in to comment.