[10.x] Attributes support on default component slot #48039
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This way we can use
$slot->attributes
and it's backwards compatible as the attributes are optional. Example usage; a checkbox component with a slot for the label:Usage:
But if we want to change the
bg-yellow
we could create props likelabelClass
but if we also want an ID we also getlabelId
etc. So better to use an attribute bag. We could do so by using an named slot like ($slot
=>$label
):This way we can do this:
But if we do not need any extra attributes we can't do this anymore:
As we don't do anything with the default slot. We could do this:
But now the
bg-yellow
isn't working anymore.With this pull request we can do this:
And now this works:
And also this:
Which is useful when we want some default styling on the label with the possibility to override/extend it without the need to check if the named slot is used or not within the component.