Skip to content

[TwigComponent] Reconsider behaviour for (bool) false value for ARIA attributes #3261

@polarbirke

Description

@polarbirke

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRFC = Request For Comments (proposals about features that you want to be discussed)TwigComponent

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions