From c5083d5fc372b750ceea35d72cafa26562762b0c Mon Sep 17 00:00:00 2001 From: GeoSot Date: Wed, 17 Mar 2021 07:44:15 +0200 Subject: [PATCH] Use more safe check for 'isDisabled' helper (#33385) --- .bundlewatch.config.json | 2 +- js/src/util/index.js | 2 +- js/tests/unit/util/index.spec.js | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.bundlewatch.config.json b/.bundlewatch.config.json index 4a28264b3a..27b998c620 100644 --- a/.bundlewatch.config.json +++ b/.bundlewatch.config.json @@ -54,7 +54,7 @@ }, { "path": "./dist/js/bootstrap.min.js", - "maxSize": "16.25 kB" + "maxSize": "16.5 kB" } ], "ci": { diff --git a/js/src/util/index.js b/js/src/util/index.js index e268b07287..e9950c9e38 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -166,7 +166,7 @@ const isDisabled = element => { return element.disabled } - return element.getAttribute('disabled') !== 'false' + return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false' } const findShadowRoot = element => { diff --git a/js/tests/unit/util/index.spec.js b/js/tests/unit/util/index.spec.js index 24921d730e..41c1ce2b80 100644 --- a/js/tests/unit/util/index.spec.js +++ b/js/tests/unit/util/index.spec.js @@ -347,16 +347,19 @@ describe('Util', () => { expect(Util.isDisabled(div2)).toEqual(true) }) - it('should return false if the element has disabled attribute with "false" value', () => { + it('should return false if the element has disabled attribute with "false" value, or doesn\'t have attribute', () => { fixtureEl.innerHTML = [ '
', '
', + '
', '
' ].join('') const div = fixtureEl.querySelector('#element') + const div1 = fixtureEl.querySelector('#element1') expect(Util.isDisabled(div)).toEqual(false) + expect(Util.isDisabled(div1)).toEqual(false) }) it('should return false if the element is not disabled ', () => {