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

Commit

Permalink
Make sure an explicitly set aria-label attribute is not overwritten b…
Browse files Browse the repository at this point in the history
…y the heading property
  • Loading branch information
whenlit committed Sep 7, 2016
1 parent e0c01ae commit a27c7ea
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
8 changes: 6 additions & 2 deletions paper-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,12 @@
},

_headingChanged: function(heading) {
var label = this.getAttribute('aria-label');
this.setAttribute('aria-label', heading);
var currentHeading = this.getAttribute('heading'),
currentLabel = this.getAttribute('aria-label');

if (typeof currentLabel !== 'string' || currentLabel === currentHeading) {
this.setAttribute('aria-label', heading);
}
},

_computeHeadingClass: function(image) {
Expand Down
66 changes: 58 additions & 8 deletions test/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,71 @@
</template>
</test-fixture>

<test-fixture id="with-aria-label">
<template>
<paper-card heading="header" aria-label="the-aria-label">
<div class="card-content"><p>Sample content</p></div>
</paper-card>
</template>
</test-fixture>

<test-fixture id="with-empty-aria-label">
<template>
<paper-card heading="header" aria-label="">
<div class="card-content"><p>Sample content</p></div>
</paper-card>
</template>
</test-fixture>

<script>
suite('a11y', function() {
var f;
setup(function () {
f = fixture('basic');
suite('without aria-label', function() {
setup(function () {
f = fixture('basic');
});

test('aria-label set on card', function() {
assert.strictEqual(f.getAttribute('aria-label'), f.heading);
});

test('aria-label can be updated by heading', function() {
assert.strictEqual(f.getAttribute('aria-label'), f.heading);
f.heading = 'batman';
assert.strictEqual(f.getAttribute('aria-label'), 'batman');
});
});

test('aria-label set on card', function() {
assert.strictEqual(f.getAttribute('aria-label'), f.heading);
suite('with aria-label', function() {
setup(function () {
f = fixture('with-aria-label');
});

test('defined aria-label is not overwritten by initial heading', function() {
assert.strictEqual(f.getAttribute('aria-label'), 'the-aria-label');
});

test('defined aria-label is not overwritten by heading update', function() {
assert.strictEqual(f.getAttribute('aria-label'), 'the-aria-label');
f.heading = 'batman';
assert.strictEqual(f.getAttribute('aria-label'), 'the-aria-label');
});
});

test('aria-label can be updated', function() {
assert.strictEqual(f.getAttribute('aria-label'), f.heading);
f.heading = 'batman';
assert.strictEqual(f.getAttribute('aria-label'), 'batman');
suite('with empty aria-label', function() {
setup(function () {
f = fixture('with-empty-aria-label');
});

test('empty aria-label is not overwritten by initial heading', function() {
assert.strictEqual(f.getAttribute('aria-label'), '');
});

test('empty aria-label is not overwritten by heading update', function() {
assert.strictEqual(f.getAttribute('aria-label'), '');
f.heading = 'batman';
assert.strictEqual(f.getAttribute('aria-label'), '');
});
});
});
suite('header image', function() {
Expand Down

0 comments on commit a27c7ea

Please sign in to comment.