Browse Source

Merge pull request #11 from tlgreg/add-hidden-boolean-attr

Add hidden to boolean attributes
Caleb Porzio 5 years ago
parent
commit
91e2adb854
2 changed files with 3 additions and 1 deletions
  1. 1 1
      src/component.js
  2. 2 0
      test/bind.spec.js

+ 1 - 1
src/component.js

@@ -273,7 +273,7 @@ export default class Component {
                     }
                 })
             }
-        } else if (['disabled', 'readonly', 'required', 'checked'].includes(attrName)) {
+        } else if (['disabled', 'readonly', 'required', 'checked', 'hidden'].includes(attrName)) {
             // Boolean attributes have to be explicitly added and removed, not just set.
             if (!! value) {
                 el.setAttribute(attrName, '')

+ 2 - 0
test/bind.spec.js

@@ -71,6 +71,7 @@ test('boolean attributes set to false are removed from element', async () => {
             <input x-bind:checked="isSet"></input>
             <input x-bind:required="isSet"></input>
             <input x-bind:readonly="isSet"></input>
+            <input x-bind:hidden="isSet"></input>
         </div>
     `
 
@@ -80,6 +81,7 @@ test('boolean attributes set to false are removed from element', async () => {
     expect(document.querySelectorAll('input')[1].checked).toBeFalsy()
     expect(document.querySelectorAll('input')[2].required).toBeFalsy()
     expect(document.querySelectorAll('input')[3].readOnly).toBeFalsy()
+    expect(document.querySelectorAll('input')[4].hidden).toBeFalsy()
 })
 
 test('boolean attributes set to true are added to element', async () => {