-
-
Notifications
You must be signed in to change notification settings - Fork 413
[TwigComponent] Reconsider behaviour for (bool) false value for ARIA attributes #3261
Description
#1805 removed the ability to render ARIA attributes with a (string) false value by passing a (bool) false value to the attributes helper.
Example:
{# templates/components/Button.html.twig #}
<button {{ attributes }}>Toggle Foo</button>
{# render component #}
<twig:Button aria-expanded="{{ user.alwaysShowFoo }}" />
{# renders as: #}
user.alwaysShowFoo
? <button aria-expanded="true">Toggle Foo</button>
: <button>Toggle Foo</button>
{# desired output: #}
user.alwaysShowFoo
? <button aria-expanded="true">Toggle Foo</button>
: <button aria-expanded="false">Toggle Foo</button>
The reason given in #1797 (comment) is a prior decision to use (bool) false to signal that an attribute should be omitted.
This decision is generally fine for HTML attributes.
I would have preferred to finetune the behaviour for ARIA attributes in a slightly more nuanced way than is already the case. As was suggested in #1797 (comment), there would be a viable alternative to use null to not render an ARIA attribute and have (bool) false cast to a string value of "false". It feels off to have special behaviour for ARIA attributes for (bool) true only.
I would like to submit that the discussion is reopened.