From 6b97a3124170826d6e6d5fe48df5cfbfa4cff1db Mon Sep 17 00:00:00 2001 From: Scott Chen Date: Sat, 5 May 2018 02:25:34 +0000 Subject: [PATCH] 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 Reviewed-by: Demetrios Papadopoulos Cr-Commit-Position: refs/heads/master@{#556293} --- .../webui/cr_elements/cr_checkbox_test.js | 35 ++++++++++++++++--- .../cr_elements/cr_checkbox/cr_checkbox.js | 11 ++++-- 2 files changed, 39 insertions(+), 7 deletions(-) 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'); },