Skip to content

Commit

Permalink
WebUI[MD-refresh]: on init, cr-checkbox should not alter tabindex if …
Browse files Browse the repository at this point in the history
…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: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556293}
  • Loading branch information
Scott Chen authored and Commit Bot committed May 5, 2018
1 parent c5f1009 commit 6b97a31
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
35 changes: 30 additions & 5 deletions chrome/test/data/webui/cr_elements/cr_checkbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down Expand Up @@ -143,7 +143,7 @@ suite('cr-checkbox', function() {
});

assertNotChecked();
link = document.getElementById('link');
link = document.querySelector('a');
link.click();
assertNotChecked();

Expand All @@ -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);
});
});
11 changes: 9 additions & 2 deletions ui/webui/resources/cr_elements/cr_checkbox/cr_checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
},
Expand Down

0 comments on commit 6b97a31

Please sign in to comment.