OverviewInstallationMigrating to 1.0Themes and layersKanok designCustomizingIconsForms and validationFrameworksUsing with AIButtonText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderModalSide panelTearsheetNotificationToastTooltipDefinition tooltipPopoverToggletipMenuData tableStructured listPaginationContained listTree viewTabsBreadcrumbLinkPagination navContent switcherAccordionProgress indicatorUI shellTagTileCardProduct cardCode snippetCopy buttonUser avatarTruncated textListLoadingInline loadingProgress barSkeletonBadge indicatorStatus indicatorGridHeadingLayerAction setPage headerBig numberEdit in placeIntroductionText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderTabsPagination navContent switcherTooltipDefinition tooltipPopoverMenuAccordionProgress indicatorUI shellModalSide panelTearsheetNotificationToastData tableStructured listPaginationTree viewCode snippetCopy buttonTruncated textLoadingTagCardProduct cardEdit in place
Dropdown
A dropdown picks one option from a list that looks the same in every browser. Options can have a second line and sit in labelled groups.
HTMLReactReact + Tailwind<ui-dropdownlabel="Contract type"name="type"placeholder="Choose a type">
<optionvalue="sale"data-description="The buyer owns the property">Sale</option>
<optionvalue="lease"data-description="Monthly rent, fixed term">Lease</option>
<optionvalue="mortgage"data-description="Property as security for a loan">Mortgage</option>
</ui-dropdown><UiDropdownlabel="Contract type"name="type"placeholder="Choose a type">
<optionvalue="sale"data-description="The buyer owns the property">Sale</option>
<optionvalue="lease"data-description="Monthly rent, fixed term">Lease</option>
<optionvalue="mortgage"data-description="Property as security for a loan">Mortgage</option>
</UiDropdown>const types = [
{ value:'sale', label:'Sale', description:'The buyer owns the property' },
{ value:'lease', label:'Lease', description:'Monthly rent, fixed term' },
{ value:'mortgage', label:'Mortgage', description:'Property as security for a loan' },
];
<Dropdownlabel="Contract type"name="type"placeholder="Choose a type"items={types} />
Installation
npmshadcn · Web componentshadcn · React + TailwindManualnpminstall@purpurabog/uinpxshadcn@4add@kanok-ui/dropdownnpxshadcn@4add@kanok-ui/tw-dropdown# Web component# 1. Install the dependenciesnpminstalllit@^3.3.0# 2. Copy each file's "content" from# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/dropdown.json# to its target:# components/ui/primitives/dropdown/dropdown-skeleton.ts# components/ui/primitives/dropdown/dropdown.styles.ts# components/ui/primitives/dropdown/dropdown.ts# 3. Do the same for the items it needs (registry/<name>.json):# core-dropdown, core-listbox, core-popup, core-typeahead, shared-element, shared-events, shared-field, shared-form-control, shared-listbox, shared-localize, shared-position, shared-quiet-focus, shared-skeleton, shared-slots, tokens# React + Tailwind# 1. Install the dependenciesnpminstall@purpurabog/ui@^2.3.0# 2. Copy each file's "content" from# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-dropdown.json# to its target:# components/ui/react-tw/dropdown.tsx# 3. Do the same for the items it needs (registry/<name>.json):# core-field, tw-field, tw-i18n, tw-list, tw-skeleton, tw-theme, tw-utils
npm gives you every component from the package. shadcn copies the source into your app instead: a copy pinned to this version that you can change. The shadcn commands need the @kanok-ui registry in your components.json once, see Installation.
placeholder is the text in the field while nothing is chosen (Carbon calls it label). The starting choice is value, else the <option selected>. Reset goes back to it. change fires when the user picks a different option.
React + Tailwind also takes defaultValue when you don't need to hold the value yourself.
Sizes and direction
size: sm 32px, md 40px (the default), lg 48px. The list opens below the field. direction="top" prefers above; either way it flips when there is no room.
An inline dropdown shows its error or warning beside the field, in the same row, so a toolbar keeps its height.
HTMLReactReact + Tailwind<ui-dropdowninlinelabel="Status"placeholder="Choose"invalidinvalid-text="Choose a status">
<optionvalue="draft">Draft</option>
<optionvalue="signed">Signed</option>
</ui-dropdown>
<ui-dropdowninlinelabel="Owner"value="ananya"warnwarn-text="Owner is on leave">
<optionvalue="ananya">Ananya</option>
<optionvalue="boonsri">Boonsri</option>
</ui-dropdown><UiDropdowninlinelabel="Status"placeholder="Choose"invalidinvalidText="Choose a status">…</UiDropdown>
<UiDropdowninlinelabel="Owner"value="ananya"warnwarnText="Owner is on leave">…</UiDropdown><Dropdowninlinelabel="Status"items={statuses} placeholder="Choose"invalidinvalidText="Choose a status" />
<Dropdowninlinelabel="Owner"items={owners} defaultValue="ananya"warnwarnText="Owner is on leave" />
Fluid
fluid puts the label inside a 64px box (Carbon's FluidDropdown); the open list keeps the usual row height. A fluid form around the field does the same for every field in it; see fluid forms.
HTMLReactReact + Tailwind<ui-dropdownfluidlabel="Contract type"name="type"placeholder="Choose a type">
<optionvalue="sale">Sale</option>
<optionvalue="lease">Lease</option>
<optionvalue="mortgage">Mortgage</option>
</ui-dropdown><UiDropdownfluidlabel="Contract type"name="type"placeholder="Choose a type">
<optionvalue="sale">Sale</option>
<optionvalue="lease">Lease</option>
<optionvalue="mortgage">Mortgage</option>
</UiDropdown><Dropdownfluidlabel="Contract type"name="type"placeholder="Choose a type"items={types} />
Outlined (Kanok design)
In the Kanok design, fields are filled by default: a soft grey fill, no edge. Put data-field-variant="outlined" on an element around the field (a <form>, or <html> for the whole app) for a 1px edge on no fill; focus is still the soft blue halo. The attribute does nothing in the Carbon design, so the example below sits inside data-design="kanok". See Kanok design for the details.
HTMLReactReact + Tailwind<divdata-design="kanok"data-theme="paper"data-field-variant="outlined">
<ui-dropdownlabel="Contract type"name="type"placeholder="Choose a type">
<optionvalue="sale"data-description="The buyer owns the property">Sale</option>
<optionvalue="lease"data-description="Monthly rent, fixed term">Lease</option>
<optionvalue="mortgage"data-description="Property as security for a loan">Mortgage</option>
</ui-dropdown>
</div><divdata-field-variant="outlined">
<UiDropdownlabel="Contract type"name="type"placeholder="Choose a type">
<optionvalue="sale"data-description="The buyer owns the property">Sale</option>
<optionvalue="lease"data-description="Monthly rent, fixed term">Lease</option>
<optionvalue="mortgage"data-description="Property as security for a loan">Mortgage</option>
</UiDropdown>
</div>const types = [
{ value:'sale', label:'Sale', description:'The buyer owns the property' },
{ value:'lease', label:'Lease', description:'Monthly rent, fixed term' },
{ value:'mortgage', label:'Mortgage', description:'Property as security for a loan' },
];
<divdata-field-variant="outlined">
<Dropdownlabel="Contract type"name="type"placeholder="Choose a type"items={types} />
</div>
Helper text, warnings and errors
One line shows under the field at a time: an error beats a warning, and a warning beats the helper text. warn doesn't block the form; invalid forces the error.
HTMLReactReact + Tailwind<ui-dropdownlabel="Template"name="template"placeholder="Choose a template"helper-text="Templates approved by the legal team">
<optionvalue="lease-2026">Lease 2026</option>
<optionvalue="lease-2019">Lease 2019</option>
</ui-dropdown>
<ui-dropdownlabel="Template"name="template2"value="lease-2019"warnwarn-text="This template is from 2019. Check the clauses before you send it.">
<optionvalue="lease-2026">Lease 2026</option>
<optionvalue="lease-2019">Lease 2019</option>
</ui-dropdown>
<ui-dropdownlabel="Template"name="template3"value="lease-2026"invalidinvalid-text="This template doesn't fit a sale">
<optionvalue="lease-2026">Lease 2026</option>
<optionvalue="lease-2019">Lease 2019</option>
</ui-dropdown><UiDropdownlabel="Template"name="template"placeholder="Choose a template"helperText="Templates approved by the legal team">…</UiDropdown>
<UiDropdownlabel="Template"name="template2"value="lease-2019"warnwarnText="This template is from 2019. Check the clauses before you send it.">…</UiDropdown>
<UiDropdownlabel="Template"name="template3"value="lease-2026"invalidinvalidText="This template doesn't fit a sale">…</UiDropdown><Dropdownlabel="Template"name="template"items={templates} placeholder="Choose a template"helperText="Templates approved by the legal team" />
<Dropdownlabel="Template"name="template2"items={templates} defaultValue="lease-2019"warnwarnText="This template is from 2019. Check the clauses before you send it." />
<Dropdownlabel="Template"name="template3"items={templates} defaultValue="lease-2026"invalidinvalidText="This template doesn't fit a sale" />
Load the options when the list opens
loading shows one "Loading…" row instead of the options, and the keys pick nothing. Together with the event that fires after the list opens or closes, you can fetch the options the first time someone opens the list. Open the list below: the names arrive after a second.
HTMLReactReact + Tailwind<ui-dropdownid="dropdown-owner"label="Contract owner"name="owner"placeholder="Choose an owner"helper-text="The names load the first time the list opens"loading></ui-dropdown>
<scripttype="module">
// stands in for fetch('/api/owners').then((response) => response.json())constloadOwners= () =>new Promise((resolve) =>setTimeout(() =>resolve([
{ value:'anong', label:'Anong P.' },
{ value:'boonmee', label:'Boonmee S.' },
{ value:'chaiya', label:'Chaiya R.' },
]), 1000),
);
const owner = document.getElementById('dropdown-owner');
owner.addEventListener('ui-toggle', async (event) => {
if (!event.detail.open ||!owner.loading) return;
const owners =awaitloadOwners();
owner.replaceChildren(...owners.map((o) =>newOption(o.label, o.value)));
owner.loading =false;
});
</script>const [owners, setOwners] =useState<{ value:string; label:string }[]>();
constload=async (open:boolean) => {
if (open &&!owners) setOwners(awaitloadOwners());
};
<UiDropdownlabel="Contract owner"name="owner"placeholder="Choose an owner"helperText="The names load the first time the list opens"loading={!owners} onUiToggle={(e) =>load(e.detail.open)}>
{owners?.map((o) => <optionkey={o.value} value={o.value}>{o.label}</option>)}
</UiDropdown><Dropdownlabel="Contract owner"name="owner"placeholder="Choose an owner"helperText="The names load the first time the list opens"items={owners ?? []} loading={!owners} onMenuChange={load} />
loadOwners, load and owners are the same in every React version.
Read-only and disabled
readonly (readOnly in React + Tailwind) shows the value and submits it, but the list doesn't open.
disabled greys the field out. It isn't submitted.
HTMLReactReact + Tailwind<ui-dropdownlabel="Contract type"value="lease"readonly>
<optionvalue="sale">Sale</option>
<optionvalue="lease">Lease</option>
</ui-dropdown>
<ui-dropdownlabel="Contract type"placeholder="Choose a type"disabled>
<optionvalue="sale">Sale</option>
<optionvalue="lease">Lease</option>
</ui-dropdown><UiDropdownlabel="Contract type"value="lease"readonly>…</UiDropdown>
<UiDropdownlabel="Contract type"placeholder="Choose a type"disabled>…</UiDropdown><Dropdownlabel="Contract type"items={types} defaultValue="lease"readOnly />
<Dropdownlabel="Contract type"items={types} placeholder="Choose a type"disabled />
Required in a form
An empty required dropdown blocks the form and has a built-in message in Thai and English; invalid-text replaces it. The error waits until the user leaves the field or submits. Press Submit without a choice to see it.
Submitted:
HTMLReactReact + Tailwind<formid="dropdown-form"style="display: grid; gap: 16px">
<ui-dropdownlabel="Signing method"name="method"placeholder="Choose a method"required>
<optionvalue="esign"data-description="Sign online in minutes">E-signature</option>
<optionvalue="paper"data-description="Print, sign and scan">Paper</option>
</ui-dropdown>
<div><ui-buttontype="submit">Submit</ui-button></div>
</form>
<p>Submitted: <outputid="dropdown-form-out"></output></p>
<scripttype="module">
const form = document.getElementById('dropdown-form');
const out = document.getElementById('dropdown-form-out');
form.addEventListener('submit', (event) => {
event.preventDefault();
out.value = [...newFormData(form)].map(([key, value]) =>`${key}=${value}`).join(', ');
});
</script><formonSubmit={submit}>
<UiDropdownlabel="Signing method"name="method"placeholder="Choose a method"required>
<optionvalue="esign"data-description="Sign online in minutes">E-signature</option>
<optionvalue="paper"data-description="Print, sign and scan">Paper</option>
</UiDropdown>
<UiButtontype="submit">Submit</UiButton>
</form>
<p>Submitted: <output>{sent}</output></p>// validation is your app's: `tried` is set on the first submit
<formonSubmit={submit}>
<Dropdownlabel="Signing method"name="method"placeholder="Choose a method"items={methods} value={method} onChange={setMethod} requiredinvalid={tried &&!method} invalidText="Choose a signing method" />
<Buttontype="submit">Submit</Button>
</form>
<p>Submitted: <output>{sent}</output></p>
submit prevents the navigation and puts new FormData(form) into sent, as in the HTML. More on errors and when they show: Forms and validation.
Skeleton
While the options load, show ui-dropdown-skeleton in the field's place: a label bar and a field bar at the same size. It is hidden from screen readers, so say "loading" on the container (for example aria-busy).
On the web component, import it from @purpurabog/ui/dropdown-skeleton.
Keyboard
Key
List closed
List open
↓, Enter, Space
↓ / Enter / Space open the list on the chosen option (else the first)
↓ moves down; Enter and Space pick the highlighted option and close
↑
Does nothing
Moves up (no wrap)
Home / End
Opens on the first / last option
First / last option
Page Up / Page Down
Moves by 10
Letters
Opens on the next option that starts with them
Jumps to the next option that starts with them
Alt+↑
Picks the highlighted option and closes
Esc
Closes without a change
Tab
Moves on
Closes without a change and moves on
Accessibility
It follows the WAI-ARIA select-only combobox pattern: the field is a button with role="combobox", the list a listbox. Focus stays on the field and the highlighted option is announced through aria-activedescendant.
The field is a Tab stop in every browser, Safari included.
loading marks the list busy and announces "Loading…".
Use hide-label only when the context already names the field. The label then stays for screen readers.