Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Allow @class() for component tags #43140

Merged
merged 3 commits into from Aug 4, 2022

Conversation

aguingand
Copy link
Contributor

@aguingand aguingand commented Jul 12, 2022

Closes #42977. Example of use:

<x-icon @class(['lg' => $large]) />

Description

My attempt to allow @class() directive alongside component tag attributes. I've adapted the regex used for statements in the blade compiler.

I have made 2 choices in this PR:

  • The regex only match the statement class with an expression. Because it's the only one allowed here, it's seems more comprehensible instead of compiling the component and ignoring not handled directives.
  • Double quotes are naively converted to single quotes inside the directive expression. Since we compile to :class="...", double quotes would break the compiled code.

@aguingand aguingand changed the title Allow @class() for component tags [9.x] Allow @class() for component tags Jul 12, 2022
@taylorotwell
Copy link
Member

Do we convert double quotes to single quotes in other places in this way?

@aguingand
Copy link
Contributor Author

@taylorotwell I don't think so. The same problem exists for {{ $attributes }} parsing, e.g.

<x-icon {{ $attributes->class("test") }} /> {{-- double quotes breaks compiled code --}}

return preg_replace($pattern, ' :attributes="$1"', $attributeString);

I have no opinion here, it looks like a bug but maybe a warning in the docs is enough.

@taylorotwell taylorotwell merged commit fd4451e into laravel:9.x Aug 4, 2022
@taylorotwell
Copy link
Member

Thanks!

Ken-vdE pushed a commit to Ken-vdE/framework that referenced this pull request Aug 9, 2022
* Allow class directive inside tag components

* formatting

Co-authored-by: Taylor Otwell <taylor@laravel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't use @class on nested anonymous component
3 participants