Skip to content

Commit 137f8bb

Browse files
authored
Remove hidden from booleanAttributes (#4099)
* Remove hidden from booleanAttributes * Add test for hidden attribute * Add to test for specific boolean attributes which are not removed when falsy
1 parent ebffaa7 commit 137f8bb

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

packages/alpinejs/src/utils/bind.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function isBooleanAttr(attrName) {
150150
// As per HTML spec table https://html.spec.whatwg.org/multipage/indices.html#attributes-3:boolean-attribute
151151
// Array roughly ordered by estimated usage
152152
const booleanAttributes = [
153-
'disabled','checked','required','readonly','hidden','open', 'selected',
153+
'disabled','checked','required','readonly','open', 'selected',
154154
'autofocus', 'itemscope', 'multiple', 'novalidate','allowfullscreen',
155155
'allowpaymentrequest', 'formnovalidate', 'autoplay', 'controls', 'loop',
156156
'muted', 'playsinline', 'default', 'ismap', 'reversed', 'async', 'defer',

tests/cypress/integration/directives/x-bind.spec.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,30 @@ test('style attribute bindings are added by string syntax',
2727
({ get }) => get('span').should(haveClasses(['foo']))
2828
)
2929

30-
test('aria-pressed/checked attribute boolean values are cast to a true/false string',
30+
test('aria-pressed/checked/expanded/selected attribute boolean values are cast to a true/false string',
3131
html`
3232
<div x-data="{ open: true }">
3333
<span x-bind:aria-pressed="open"></span>
34+
<span x-bind:aria-checked="open"></span>
35+
<span x-bind:aria-expanded="open"></span>
36+
<span x-bind:aria-selected="open"></span>
37+
38+
<span x-bind:aria-pressed="false"></span>
39+
<span x-bind:aria-checked="false"></span>
40+
<span x-bind:aria-expanded="false"></span>
41+
<span x-bind:aria-selected="false"></span>
3442
</div>
3543
`,
36-
({ get }) => get('span').should(haveAttribute('aria-pressed', 'true'))
44+
({ get }) => {
45+
get('span:nth-of-type(1)').should(haveAttribute('aria-pressed', 'true'))
46+
get('span:nth-of-type(2)').should(haveAttribute('aria-checked', 'true'))
47+
get('span:nth-of-type(3)').should(haveAttribute('aria-expanded', 'true'))
48+
get('span:nth-of-type(4)').should(haveAttribute('aria-selected', 'true'))
49+
get('span:nth-of-type(5)').should(haveAttribute('aria-pressed', 'false'))
50+
get('span:nth-of-type(6)').should(haveAttribute('aria-checked', 'false'))
51+
get('span:nth-of-type(7)').should(haveAttribute('aria-expanded', 'false'))
52+
get('span:nth-of-type(8)').should(haveAttribute('aria-selected', 'false'))
53+
}
3754
)
3855

3956
test('non-boolean attributes set to null/undefined/false are removed from the element',
@@ -46,6 +63,10 @@ test('non-boolean attributes set to null/undefined/false are removed from the el
4663
<span visible="true" x-bind:visible="null">null</span>
4764
<span visible="true" x-bind:visible="false">false</span>
4865
<span visible="true" x-bind:visible="undefined">undefined</span>
66+
67+
<span hidden="true" x-bind:hidden="null">null</span>
68+
<span hidden="true" x-bind:hidden="false">false</span>
69+
<span hidden="true" x-bind:hidden="undefined">undefined</span>
4970
</div>
5071
`,
5172
({ get }) => {
@@ -55,6 +76,9 @@ test('non-boolean attributes set to null/undefined/false are removed from the el
5576
get('span:nth-of-type(1)').should(notHaveAttribute('visible'))
5677
get('span:nth-of-type(2)').should(notHaveAttribute('visible'))
5778
get('span:nth-of-type(3)').should(notHaveAttribute('visible'))
79+
get('span:nth-of-type(4)').should(notHaveAttribute('hidden'))
80+
get('span:nth-of-type(5)').should(notHaveAttribute('hidden'))
81+
get('span:nth-of-type(6)').should(notHaveAttribute('hidden'))
5882
}
5983
)
6084

0 commit comments

Comments
 (0)