Forms & Inputs
Select
A <nana-select> element.
Preview
Section titled “Preview”<nana-select label="Country" style="min-width: 16rem">
<nana-option value="ke">Kenya</nana-option>
<nana-option value="ug">Uganda</nana-option>
</nana-select> <script lang="ts">
import { NanaSelect } from '$lib/components/ui/select';
let country = $state('');
</script>
<div class="w-72">
<NanaSelect
label="Country"
placeholder="Pick one"
bind:value={country}
options={[
{ value: 'ke', label: 'Kenya' },
{ value: 'ug', label: 'Uganda' },
{ value: 'tz', label: 'Tanzania', disabled: true },
]}
/>
</div> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add select --framework web-componentsnpx @nana-tec/ui add select --framework svelteLands in src/lib/components/ui/select/ as NanaSelect.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/select";
Copied in with npx @nana-tec/ui add select? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<nana-select label="Country" style="min-width:16rem"> <nana-option value="ke">Kenya</nana-option> <nana-option value="ug">Uganda</nana-option></nana-select><script lang="ts"> import { NanaSelect } from '$lib/components/ui/select';
let country = $state('');</script>
<NanaSelect label="Country" placeholder="Pick one" bind:value={country} options={[ { value: 'ke', label: 'Kenya' }, { value: 'ug', label: 'Uganda' }, { value: 'tz', label: 'Tanzania', disabled: true }, ]}/>The Svelte NanaSelect wraps a native <select>, so the browser supplies its
keyboard and screen-reader behaviour. Pass options, or supply <option>
children directly. It has no search; for that, use Combobox. The web
component nana-select is different: it draws its own listbox panel, which is
what lets it search and hold several values.
Searchable
Section titled “Searchable”Add searchable to filter options; clearable adds a reset button.
<nana-select
label="Country"
placeholder="Search…"
searchable
clearable
style="min-width: 16rem"
>
<nana-option value="us">United States</nana-option>
<nana-option value="ca">Canada</nana-option>
<nana-option value="mx">Mexico</nana-option>
</nana-select> Multi-select
Section titled “Multi-select”Set multiple — selected values render as removable chips.
<nana-select
label="Countries"
placeholder="Select…"
multiple
clearable
style="min-width: 16rem"
>
<nana-option value="us">United States</nana-option>
<nana-option value="ca">Canada</nana-option>
<nana-option value="mx">Mexico</nana-option>
</nana-select> Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
ariaLabel | aria-label | string | null | null | Accessible name when there is no visible label. |
clearable | clearable | boolean | false | Shows a button that clears the value. |
disabled | disabled | boolean | false | Blocks interaction and leaves the value out of form submission. |
errorMessage | error-message | string | '' | Error under the field while it is invalid, in the error part with role="alert". |
helperText | helper-text | string | '' | Text under the field, in the help part. |
inputId | — | — | — | Id of the inner control. Generated when not set. |
invalid | invalid | boolean | false | Marks the field invalid and shows error-message in place of the helper text. |
label | label | string | '' | Visible label for the field. |
multiple | multiple | boolean | false | Lets more than one option be selected. |
name | name | string | '' | Name the value is submitted under in a form. |
open | open | boolean | false | Whether the panel is open. Set it to open or close the panel yourself. |
placeholder | placeholder | string | '' | Hint text shown while the field is empty. |
required | required | boolean | false | The form will not submit while this has no value. |
searchable | searchable | boolean | false | Adds a search field that filters the options. |
size | size | SelectSize | 'md' | Size preset. |
value | value | string | '' | The current value. |
Methods
| Method | Description |
|---|---|
clear(): void | Clear the selection, emit nana-clear and return focus to the trigger |
focus(options?: FocusOptions): void | Focus the trigger |
Events
| Event | Description |
|---|---|
nana-change | Fired when selection changes (detail.value — string for single, string[] for multiple) |
nana-clear | Fired when the selection is cleared |
nana-search | Fired on each keystroke in the search field (detail.value) |
nana-focus | Fired on focus |
nana-blur | Fired on blur |
Slots
| Slot | Description |
|---|---|
(default) | nana-option children |
empty | Message shown in the panel when no option is left to show (e.g. a nana-empty-state). Defaults to "No results found", or "No options" when there are none to filter. |
CSS parts
| Part | Description |
|---|---|
::part(trigger) | The trigger element; carries trigger-multiple |
::part(panel) | The floating listbox panel |
::part(chip) | A selected-value chip (multi-select only) |
::part(search) | The search input (searchable only) |
::part(empty) | The empty-message region inside the panel; carries is-custom |
::part(field) | The field |
::part(required-mark) | The required mark |
::part(trigger-value) | The trigger value; carries trigger-placeholder |
::part(controls) | The controls |
::part(clear-btn) | The clear button |
::part(caret) | The caret |
::part(error) | The error |
::part(help) | The helper text |
::part(helper) | Deprecated: use help |
::part(label) | The label |
CSS custom properties
| Property | Description |
|---|---|
--nana-select-max-height | Panel max height before scrolling |
--nana-dropdown-z | Stacking order for the floating panel, shared by the overlay controls |
--nana-input-bg | Field background, shared with the other form controls |
--nana-input-color | Field text colour, shared with the other form controls |
--nana-input-height | Field height, shared with the other form controls |
--nana-select-height | Trigger height; falls back to the shared field height |
--nana-select-panel-radius | Listbox panel corner radius |
--nana-select-radius | Trigger corner radius |
--nana-select-z | Stacking order for the listbox panel |
NanaSelect
| Prop | Type | Default |
|---|---|---|
size | SelectSize | 'md' |
valuebind: | string | '' |
label | string | |
helperText | string | |
errorMessage | string | |
invalid | boolean | false |
placeholder | string | |
options | SelectOption[] | |
onValueChange | (value: string) => void | |
children | Snippet |
Also accepts Omit<HTMLSelectAttributes, 'class' | 'size' | 'value'>.