Select Option Groups #354
Replies: 8 comments 3 replies
-
|
I think you can use any HTML tags inside Example:<flux:select
class="!font-sans !w-auto !border-transparent"
data-tippy-content="Select A Book"
data-tippy-placement="top"
wire:model="selectedBook"
>
@foreach ($bookOptions as $label => $options)
<div class=“font-semibold uppercase border-b pb-1” >{{ $label }}</div>
@foreach ($options as $option)
<flux:option
wire:key="{{ $option }}"
value="{{ $option }}"
>
{{ $option }}
</flux:option>
@endforeach
</optgroup>
@endforeach
</flux:select> |
Beta Was this translation helpful? Give feedback.
-
That doesn't work on searchable selects right? I tried @iliyto's suggestion with div (minus the hanging optgroup) and it shows up, but also stays when you search. How have other people solved this for searchable selects? |
Beta Was this translation helpful? Give feedback.
-
|
You can make use of "flux:seperator" inside "flux:select" as a work around to emulate the optgroup behavior. |
Beta Was this translation helpful? Give feedback.
-
|
You could use some css for this: <optgroup class="hidden has-[option]:block">
//...
</optgroup>ie: @php
$bookOptions = [
'Fiction' => ['The Great Gatsby', 'To Kill a Mockingbird'],
'Non-Fiction' => ['Sapiens', 'Educated'],
'Science Fiction' => [],
'Fantasy' => ['The Hobbit', 'Harry Potter'],
'Mystery' => [],
'Romance' => [],
];
$selectedBook = null;
@endphp
<flux:select
class="!font-sans !w-auto !border-transparent"
wire:model="selectedBook"
>
@foreach ($bookOptions as $label => $options)
<optgroup
class="hidden has-[option]:block"
label="{{ $label }}"
>
@foreach ($options as $option)
<flux:select.option
wire:key="{{ $option }}"
value="{{ $option }}"
>
{{ $option }}
</flux:select.option>
@endforeach
</optgroup>
@endforeach
</flux:select> |
Beta Was this translation helpful? Give feedback.
-
|
It's hard to believe some basic stuff like A form component should be the priority #1 for mass adoption... |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
+1 |
Beta Was this translation helpful? Give feedback.
-
|
I keep coming back to this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I couldn't find documentation or code that supported select option groups. Did I miss something? I am using the following work-around:
If this is the expected implementation, is this something that would be useful to document? Or is this a feature that could be added?
Beta Was this translation helpful? Give feedback.
All reactions