diff --git a/chrome/test/data/webui/cr_elements/cr_checkbox_test.js b/chrome/test/data/webui/cr_elements/cr_checkbox_test.js index d81c0e7b9b811d..2d8d9827d5905b 100644 --- a/chrome/test/data/webui/cr_elements/cr_checkbox_test.js +++ b/chrome/test/data/webui/cr_elements/cr_checkbox_test.js @@ -8,14 +8,14 @@ suite('cr-checkbox', function() { setup(function() { PolymerTest.clearBody(); document.body.innerHTML = ` - -
label - link + +
label + link
`; - 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 = ` + + `; + + 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 = ` + + `; + + checkbox = document.querySelector('cr-checkbox'); + + // Initializing with disabled should make tabindex="-1". + assertEquals(-1, checkbox.tabIndex); + }); }); diff --git a/ui/webui/resources/cr_elements/cr_checkbox/cr_checkbox.js b/ui/webui/resources/cr_elements/cr_checkbox/cr_checkbox.js index 349c3e772fe28d..772bc6db084a7e 100644 --- a/ui/webui/resources/cr_elements/cr_checkbox/cr_checkbox.js +++ b/ui/webui/resources/cr_elements/cr_checkbox/cr_checkbox.js @@ -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'); },