From 081816fb32701915aa20645a07c02f3a0fd3d315 Mon Sep 17 00:00:00 2001 From: Eric Kwoka <43540491+ekwoka@users.noreply.github.com> Date: Tue, 30 Jul 2024 00:38:18 +0400 Subject: [PATCH] :construction: Updates List of boolean attributes to follow spec (#4325) * :construction: Updates List of boolean attributes to follow spec * :white_check_mark: Updates Test for new attributes --- packages/alpinejs/src/utils/bind.js | 43 ++++++++++++++----- .../integration/directives/x-bind.spec.js | 15 +++++-- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/packages/alpinejs/src/utils/bind.js b/packages/alpinejs/src/utils/bind.js index 302071475..1e3720b93 100644 --- a/packages/alpinejs/src/utils/bind.js +++ b/packages/alpinejs/src/utils/bind.js @@ -146,18 +146,39 @@ export function safeParseBoolean(rawValue) { return rawValue ? Boolean(rawValue) : null } +// As per HTML spec table https://html.spec.whatwg.org/multipage/indices.html#attributes-3:boolean-attribute +const booleanAttributes = new Set([ + 'allowfullscreen', + 'async', + 'autofocus', + 'autoplay', + 'checked', + 'controls', + 'default', + 'defer', + 'disabled', + 'formnovalidate', + 'inert', + 'ismap', + 'itemscope', + 'loop', + 'multiple', + 'muted', + 'nomodule', + 'novalidate', + 'open', + 'playsinline', + 'readonly', + 'required', + 'reversed', + 'selected', + 'shadowrootclonable', + 'shadowrootdelegatesfocus', + 'shadowrootserializable', +]) + function isBooleanAttr(attrName) { - // As per HTML spec table https://html.spec.whatwg.org/multipage/indices.html#attributes-3:boolean-attribute - // Array roughly ordered by estimated usage - const booleanAttributes = [ - 'disabled','checked','required','readonly','open', 'selected', - 'autofocus', 'itemscope', 'multiple', 'novalidate','allowfullscreen', - 'allowpaymentrequest', 'formnovalidate', 'autoplay', 'controls', 'loop', - 'muted', 'playsinline', 'default', 'ismap', 'reversed', 'async', 'defer', - 'nomodule' - ] - - return booleanAttributes.includes(attrName) + return booleanAttributes.has(attrName) } function attributeShouldntBePreservedIfFalsy(name) { diff --git a/tests/cypress/integration/directives/x-bind.spec.js b/tests/cypress/integration/directives/x-bind.spec.js index 8deac5ce9..ccbd61aa1 100644 --- a/tests/cypress/integration/directives/x-bind.spec.js +++ b/tests/cypress/integration/directives/x-bind.spec.js @@ -105,10 +105,12 @@ test('boolean attribute values are set to their attribute name if true and remov
-
+