Commit 6b97a312 authored by Scott Chen's avatar Scott Chen Committed by Commit Bot

WebUI[MD-refresh]: on init, cr-checkbox should not alter tabindex if not disabled.

When initializing, cr-checkbox unnecessarily set tabindex to 0 even if it
was set to something else. This CL fixes it

Bug: 839277
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I73d6e97ad7b6be8b7cd18759f1677f65acf96947
Reviewed-on: https://chromium-review.googlesource.com/1042864
Commit-Queue: Scott Chen <scottchen@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556293}
parent c5f1009c
......@@ -8,14 +8,14 @@ suite('cr-checkbox', function() {
setup(function() {
PolymerTest.clearBody();
document.body.innerHTML = `
<cr-checkbox id="checkbox">
<div id="label">label
<a id="link">link</a>
<cr-checkbox>
<div>label
<a>link</a>
</div>
</cr-checkbox>
`;
checkbox = document.getElementById('checkbox');
checkbox = document.querySelector('cr-checkbox');
assertNotChecked();
});
......@@ -143,7 +143,7 @@ suite('cr-checkbox', function() {
});
assertNotChecked();
link = document.getElementById('link');
link = document.querySelector('a');
link.click();
assertNotChecked();
......@@ -153,4 +153,29 @@ suite('cr-checkbox', function() {
// Wait 1 cycle to make sure change-event was not fired.
setTimeout(done);
});
test('InitializingWithTabindex', function() {
PolymerTest.clearBody();
document.body.innerHTML = `
<cr-checkbox id="checkbox" tabindex="-1"></cr-checkbox>
`;
checkbox = document.querySelector('cr-checkbox');
// Should not override tabindex if it is initialized.
assertEquals(-1, checkbox.tabIndex);
});
test('InitializingWithDisabled', function() {
PolymerTest.clearBody();
document.body.innerHTML = `
<cr-checkbox id="checkbox" disabled></cr-checkbox>
`;
checkbox = document.querySelector('cr-checkbox');
// Initializing with disabled should make tabindex="-1".
assertEquals(-1, checkbox.tabIndex);
});
});
......@@ -55,8 +55,15 @@ Polymer({
this.setAttribute('aria-checked', this.checked ? 'true' : 'false');
},
/** @private */
disabledChanged_: function() {
/**
* @param {boolean} current
* @param {boolean} previous
* @private
*/
disabledChanged_: function(current, previous) {
if (previous === undefined && !this.disabled)
return;
this.setAttribute('tabindex', this.disabled ? -1 : 0);
this.setAttribute('aria-disabled', this.disabled ? 'true' : 'false');
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment