Skip to content

Wrapped listbox in custom component inherits option label #2300

@ju5t

Description

@ju5t

Flux version

v2.10.2

Livewire version

v3.7.3

Tailwind version

v4

Browser and Operating System

Chrome on MacOS

What is the problem?

We have a custom component that wraps a flux:select. It uses the listbox variant.

This component has a label property that somehow gets inherited by the flux:select.option component. As a result, even though we set the $slot, the label gets preference over it.

<flux:select.option value="{{ $option['id'] }}" wire:key="{{ $option['id'] }}">
    <div class="flex items-center gap-2">
        {{ $option['name'] }}
    </div>
</flux:select.option>

I did some digging and found that even though we don't specify any variant on the select option, it doesn't use the default variant, but switches to the custom one.

The custom variant has:

{{ $label ?? $slot }}

Which results in the label of the parent component being used for each option instead of what we pass in its slot.

See also:
#1847

Code snippets to replicate the problem

php artisan make:view custom-component

And paste this in the blade file:

@props([
    'for',
    'label',
    'options' => [],
])

@php
    $listbox = collect($options)
        ->values()
        ->toArray();
@endphp

<flux:select {{ $attributes->whereDoesntStartWith('class') }} size="sm" variant="listbox">
    @foreach ($listbox as $option)
        <flux:select.option value="{{ $option['id'] }}" wire:key="{{ $option['id'] }}">
            <div class="flex items-center gap-2">
                {{ $option['name'] }}
            </div>
        </flux:select.option>
    @endforeach
</flux:select>

Example usage:

@php
$options = [
    ['id' => 'foo', 'name' => 'bar',],
];
@endphp

<x-custom-component :options="$options" />

Screenshots/ screen recordings of the problem

n/a

How do you expect it to work?

I would expect the slot to work and that it would not inherit the label from the parent component.

Please confirm (incomplete submissions will not be addressed)

  • I have provided easy and step-by-step instructions to reproduce the bug.
  • I have provided code samples as text and NOT images.
  • I understand my bug report will be closed if I haven't met the criteria above.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions