framework icon indicating copy to clipboard operation
framework copied to clipboard

[13.x] Improved empty and whitespace-only string handling in Blade component attributes

Open NickSdot opened this issue 1 month ago • 3 comments

Closes #57463 Related #31994

 @php($foo = "")
 <x-link :title="$foo">Blub</x-link>
<a {{ $attributes }}>Blub</a>

renders as

<a title>Blub</a>

which is wrong. Title isn't a boolean attribute. It should be

<a>Blub</a>

We only ever want to have empty strings or whitespace-only strings in these situations:

  • alt
  • value
  • data-*

Never for title, rel, placeholder, class etc.

Everything in our #57235 supi dupi mega thread points to that we want Laravel data attributes to be somewhat aligned with what Vue does (cc @timacdonald). So, if we want that, we should start here. Though, Vue doesn't allow :title="item.value" so the exceptions I added only make sense but Vue doesn't have them. That said, given how Blade component attributes work, I believe we surely don't want to introduce a whole new defaults-concept in #57235, but mirror what we already have in Blade component attributes. Not sure if Tim agrees, but I believe consistency within the framework is more important than what Vue does (this is mainly about boolean behaviour) . So, if this is merged we have one thing less to worry about in the other PR.

NickSdot avatar Oct 21 '25 06:10 NickSdot