Skip to content

Commit

Permalink
feat: add i18n API for clear button accessible label
Browse files Browse the repository at this point in the history
Fixes #348
  • Loading branch information
platosha committed Apr 2, 2019
1 parent 8722e4b commit aa0a3e1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/vaadin-text-area.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<textarea part="value"></textarea>
</slot>

<div part="clear-button" id="clearButton" role="button" aria-label="Clear"></div>
<div part="clear-button" id="clearButton" role="button" aria-label$="[[i18n.clear]]"></div>
<slot name="suffix"></slot>

</div>
Expand Down
20 changes: 20 additions & 0 deletions src/vaadin-text-field-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,26 @@
value: ''
},

/**
* Object with translated strings used for localization. Has
* the following structure and default values:
*
* ```
* {
* // Translation of the clear icon button accessible label
* clear: 'Clear'
* }
* ```
*/
i18n: {
type: Object,
value: () => {
return {
clear: 'Clear'
};
}
},

/**
* String used for the label element.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/vaadin-text-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<input part="value">
</slot>

<div part="clear-button" id="clearButton" role="button" aria-label="Clear"></div>
<div part="clear-button" id="clearButton" role="button" aria-label$="[[i18n.clear]]"></div>
<slot name="suffix"></slot>

</div>
Expand Down
18 changes: 18 additions & 0 deletions test/accessibility.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@
expect(input.hasAttribute('aria-readonly')).to.be.true;
});

describe('clear icon button', function() {

it('should have default accessible label', function() {
expect(tf.$.clearButton.getAttribute('aria-label')).to.equal('Clear');
});

it('should translate accesible label with new i18n object', function() {
tf.i18n = {clear: 'tyhjennä'};
expect(tf.$.clearButton.getAttribute('aria-label')).to.equal('tyhjennä');
});

it('should translate accesible label with set API', function() {
tf.set('i18n.clear', 'tyhjennä');
expect(tf.$.clearButton.getAttribute('aria-label')).to.equal('tyhjennä');
});

});

});

describe(`error ${condition}`, function() {
Expand Down

0 comments on commit aa0a3e1

Please sign in to comment.