Skip to content
Nana UI

Forms & Inputs

Select

A <nana-select> element.

View .md Download
Kenya Uganda

Install the package for a versioned dependency:

npm install @nana-tec/ui-components

Or copy the source in and own it:

npx @nana-tec/ui add select --framework web-components
npx @nana-tec/ui add select --framework svelte

Lands 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.

Add searchable to filter options; clearable adds a reset button.

United States Canada Mexico

Set multiple — selected values render as removable chips.

United States Canada Mexico

Properties

PropertyAttributeTypeDefaultDescription
ariaLabelaria-labelstring | nullnullAccessible name when there is no visible label.
clearableclearablebooleanfalseShows a button that clears the value.
disableddisabledbooleanfalseBlocks interaction and leaves the value out of form submission.
errorMessageerror-messagestring''Error under the field while it is invalid, in the error part with role="alert".
helperTexthelper-textstring''Text under the field, in the help part.
inputId———Id of the inner control. Generated when not set.
invalidinvalidbooleanfalseMarks the field invalid and shows error-message in place of the helper text.
labellabelstring''Visible label for the field.
multiplemultiplebooleanfalseLets more than one option be selected.
namenamestring''Name the value is submitted under in a form.
openopenbooleanfalseWhether the panel is open. Set it to open or close the panel yourself.
placeholderplaceholderstring''Hint text shown while the field is empty.
requiredrequiredbooleanfalseThe form will not submit while this has no value.
searchablesearchablebooleanfalseAdds a search field that filters the options.
sizesizeSelectSize'md'Size preset.
valuevaluestring''The current value.

Methods

MethodDescription
clear(): voidClear the selection, emit nana-clear and return focus to the trigger
focus(options?: FocusOptions): voidFocus the trigger

Events

EventDescription
nana-changeFired when selection changes (detail.value — string for single, string[] for multiple)
nana-clearFired when the selection is cleared
nana-searchFired on each keystroke in the search field (detail.value)
nana-focusFired on focus
nana-blurFired on blur

Slots

SlotDescription
(default)nana-option children
emptyMessage 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

PartDescription
::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

PropertyDescription
--nana-select-max-heightPanel max height before scrolling
--nana-dropdown-zStacking order for the floating panel, shared by the overlay controls
--nana-input-bgField background, shared with the other form controls
--nana-input-colorField text colour, shared with the other form controls
--nana-input-heightField height, shared with the other form controls
--nana-select-heightTrigger height; falls back to the shared field height
--nana-select-panel-radiusListbox panel corner radius
--nana-select-radiusTrigger corner radius
--nana-select-zStacking order for the listbox panel

NanaSelect

PropTypeDefault
sizeSelectSize'md'
valuebind:string''
labelstring
helperTextstring
errorMessagestring
invalidbooleanfalse
placeholderstring
optionsSelectOption[]
onValueChange(value: string) => void
childrenSnippet

Also accepts Omit<HTMLSelectAttributes, 'class' | 'size' | 'value'>.