Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Added aria label to element #97

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion iron-autogrow-textarea.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@

<!-- size the input/textarea with a div, because the textarea has intrinsic size in ff -->
<div class="textarea-container fit">
<label id$="textarea-aria-label-[[_ariaLabelId]]">[[label]]</label>
<textarea id="textarea"
aria-labelledby$="textarea-aria-label-[[_ariaLabelId]]"
name$="[[name]]"
autocomplete$="[[autocomplete]]"
autofocus$="[[autofocus]]"
Expand All @@ -121,6 +123,8 @@
</dom-module>

<script>
Polymer.IronAutogrowHelper = {};
Polymer.IronAutogrowHelper.NextLabelID = 1;

Polymer({

Expand Down Expand Up @@ -227,8 +231,22 @@
*/
maxlength: {
type: Number
}
},

/**
* Aria label to present to screen readers.
*/
label: {
type: String
},

/**
* Aria label id used to get a unique id for element
*/
_ariaLabelId: {
type: Number,
value: Polymer.IronAutogrowHelper.NextLabelID++
}
},

listeners: {
Expand Down
17 changes: 17 additions & 0 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
</template>
</test-fixture>

<test-fixture id="label">
<template>
<iron-autogrow-textarea label="foo"></iron-autogrow-textarea>
</template>
</test-fixture>

<script>

suite('basic', function() {
Expand Down Expand Up @@ -184,6 +190,17 @@
});
});


suite('a11y', function() {

test('has aria-labelledby', function() {
var autogrow = fixture('label');

assert.isTrue(autogrow.textarea.hasAttribute('aria-labelledby'))
assert.equal(autogrow.textarea.getAttribute('aria-labelledby'), Polymer.dom(autogrow.root).querySelector('label').id, 'aria-labelledby points to the label');
});
});

</script>

</body>
Expand Down