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

feat: make Select receive custom options #514

Merged
merged 2 commits into from
Jan 8, 2023

Conversation

RyanZhiNie
Copy link
Contributor

πŸ“‘ Description

In the current version, items prop's value can only be an array of {name, value} and then the array is transformed into options. But these options cannot be customized, e.g., selected or disabled.
I make "slot" be the alternative value, so users can pass their desired option elements into this component.

βœ… Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • I have checked the page with https://validator.unl.edu/
  • All the tests have passed
  • My pull request is based on the latest commit (not the npm version).

@vercel
Copy link

vercel bot commented Jan 4, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated
flowbite-svelte βœ… Ready (Inspect) Visit Preview πŸ’¬ Add your feedback Jan 8, 2023 at 0:34AM (UTC)
flowbite-svelte-update βœ… Ready (Inspect) Visit Preview πŸ’¬ Add your feedback Jan 8, 2023 at 0:34AM (UTC)

@vercel
Copy link

vercel bot commented Jan 4, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated
flowbite-svelte-update πŸ”„ Building (Inspect) Jan 4, 2023 at 10:17AM (UTC)

@jjagielka
Copy link
Contributor

That request make sense. Couple of suggestions though:

  1. export let items: SelectOptionType[] | 'slot' = [];
    This is completely unneeded. Better approach is to use else in the each loop that will trigger when items are empty.
  {#each items as { value, name }}
    <option {value}>{name}</option>
  {:else}
    <slot />
  {/each}
  1. placeholder should be independent from items. If we want to make it optional then:
  {#if placeholder}
    <option disabled selected value="">{placeholder}</option>
  {/if}

This will force to change your example in docs to:

<Select id="countries" class="mt-2" bind:value={selected} placeholder="">
  1. Why did you change the lines 60-61? It's not connected with what you want to achieve.

@RyanZhiNie
Copy link
Contributor Author

RyanZhiNie commented Jan 8, 2023

Nice suggestions. I've updated my changes. Thx.

Why did you change the lines 60-61? It's not connected with what you want to achieve.

I changed these two lines because the html code they generated were inconsistent with the code shown in flowbite website, but you're right, they are not connected with my PR, maybe I will make another PR to fix them.

@jjagielka
Copy link
Contributor

@shinokada - I'm OK with that PR

@shinokada shinokada merged commit a58b410 into themesberg:main Jan 8, 2023
@RyanZhiNie RyanZhiNie deleted the select-custom-options branch January 12, 2023 07:41
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.

None yet

3 participants