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

Fix select option variant not found #1213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joshhanley
Copy link
Member

@joshhanley joshhanley commented Feb 28, 2025

The scenario

If you use a default select inside a component that has a variant defined, like a modal, then the select options aren't showing up.

image
<?php

use Livewire\Volt\Component;

new class extends Component {
    //
}; ?>

<div>
    <flux:modal.trigger name="edit-profile">
        <flux:button>Edit profile</flux:button>
    </flux:modal.trigger>

    <flux:modal variant="flyout" name="edit-profile" class="md:w-96">
        <flux:select placeholder="Choose industry...">
            <flux:select.option>Photography</flux:select.option>
            <flux:select.option>Design services</flux:select.option>
            <flux:select.option>Web development</flux:select.option>
            <flux:select.option>Accounting</flux:select.option>
            <flux:select.option>Legal services</flux:select.option>
            <flux:select.option>Consulting</flux:select.option>
            <flux:select.option>Other</flux:select.option>
        </flux:select>
    </flux:modal>
</div>

The problem

The issue is that we recently split the select components, so some are free and some are pro, which required the option component to be split into multiple variants, but I didn't add the check back in to make sure that the variant for the option is coming from a select component and not any other components.

@php
// If the variant is coming from the parent component and is not default, we need to use the custom variant...
$variant = $variant === 'default' ? 'default' : 'custom';
@endphp

The solution

The solution is to update the variant check to include a check to make sure the select variant exists first. Now everything works happily.

@php
// This prevents variants picked up by `@aware()` from other wrapping components like flux::modal from being used here...
$variant = $variant !== 'default' && Flux::componentExists('select.variants.' . $variant)
    ? 'custom'
    : 'default';
@endphp
image

Fixes #1209

@Fludem
Copy link
Contributor

Fludem commented Feb 28, 2025

Will you write my PRs descriptions for me

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.

Missing options in <flux:select> when “variant” is not specified
2 participants