Skip to content

Commit

Permalink
Use more safe check for 'isDisabled' helper (#33385)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Mar 17, 2021
1 parent c198eb6 commit c5083d5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .bundlewatch.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
{
"path": "./dist/js/bootstrap.min.js",
"maxSize": "16.25 kB"
"maxSize": "16.5 kB"
}
],
"ci": {
Expand Down
2 changes: 1 addition & 1 deletion js/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
5 changes: 4 additions & 1 deletion js/tests/unit/util/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
'<div>',
' <div id="element" disabled="false"></div>',
' <div id="element1" ></div>',
'</div>'
].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 ', () => {
Expand Down

0 comments on commit c5083d5

Please sign in to comment.