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

Passing $attributes to component slot does not work #52082

Closed
KhizarWahabKhan opened this issue Jul 10, 2024 · 4 comments
Closed

Passing $attributes to component slot does not work #52082

KhizarWahabKhan opened this issue Jul 10, 2024 · 4 comments

Comments

@KhizarWahabKhan
Copy link

KhizarWahabKhan commented Jul 10, 2024

Laravel Version

11

PHP Version

8.3.1

Database Driver & Version

Mysql

Description

Component slots can accept attributes but throws the following error when when passed all attributes through $attribute variable:
Illuminate\View\ComponentSlot::withAttributes(): Argument #1 ($attributes) must be of type array, null given,

Steps To Reproduce

This works when attributes are given manually the x-title:slot:

<x-alert {{ $attributes->twMerge('relative w-full rounded-lg border bg-white p-4 [&>svg]:absolute [&>svg]:text-foreground [&>svg]:left-4 [&>svg]:top-4 [&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11 text-neutral-900') }}>
    @if ($title && !$title->isEmpty())
        <x-slot:title class="mb-1 font-medium leading-none tracking-tight">{{ $title }}</x-slot:title>
    @endif
</x-alert>

But this does not work, here the attribute bag is passed to the x-slot:title with default classes. It works on the main component x-alert but does not work on the slot:

<x-alert {{ $attributes->twMerge('relative w-full rounded-lg border bg-white p-4 [&>svg]:absolute [&>svg]:text-foreground [&>svg]:left-4 [&>svg]:top-4 [&>svg+div]:translate-y-[-3px] [&:has(svg)]:pl-11 text-neutral-900') }}>
    @if ($title && !$title->isEmpty())
        <x-slot:title {{ $title->attributes->twMerge('mb-1 font-medium leading-none tracking-tight') }}>{{ $title }}</x-slot:title>
    @endif
</x-alert>
@lmottasin
Copy link
Contributor

Assalamu Alaikum Brother @KhizarWahabKhan,

I hope you're doing well. Could you please create a new Laravel project and reproduce the issue you're facing with some demo component slots? Once you have done this, kindly share the GitHub repository with us so we can focus on solving the error without needing to repeat these steps.

Thank you, and I look forward to your cooperation.

@lmottasin
Copy link
Contributor

@KhizarWahabKhan see this issue there is a solution and why is it like this answer is #34313 (comment)

@crynobone
Copy link
Member

Hey there,

While this may be a legitimate issue, can you first try posting your problem or question on one of the support channels below? If this issue can be definitively identified as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!

@KhizarWahabKhan
Copy link
Author

Ok i will check the links. Thanks @lmottasin and @crynobone.

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

No branches or pull requests

3 participants