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
Select
A select picks one option from a list. It wraps the browser's own <select>, so phones open their native picker and screen readers know it well.
HTMLReactReact + Tailwind<ui-selectlabel="Department"name="department"placeholder="Choose a department"helper-text="Where the contract is filed">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</ui-select><UiSelectlabel="Department"name="department"placeholder="Choose a department"helperText="Where the contract is filed">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</UiSelect><Selectlabel="Department"name="department"placeholder="Choose a department"helperText="Where the contract is filed">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</Select>
Installation
npmshadcn · Web componentshadcn · React + TailwindManualnpminstall@purpurabog/uinpxshadcn@4add@kanok-ui/selectnpxshadcn@4add@kanok-ui/tw-select# 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/select.json# to its target:# components/ui/primitives/select/select-skeleton.ts# components/ui/primitives/select/select.styles.ts# components/ui/primitives/select/select.ts# 3. Do the same for the items it needs (registry/<name>.json):# shared-element, shared-field, shared-form-control, shared-localize, 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-select.json# to its target:# components/ui/react-tw/select.tsx# 3. Do the same for the items it needs (registry/<name>.json):# core-field, tw-field, 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.
Use it
HTMLReactReact + Tailwind<scripttype="module">import'@purpurabog/ui/select';</script>
<ui-selectlabel="Department"name="department"placeholder="Choose a department">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
</ui-select>import { UiSelect } from'@purpurabog/ui/react';
<UiSelectlabel="Department"name="department"placeholder="Choose a department">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
</UiSelect>import { Select } from'@/components/ui/react-tw/select';
<Selectlabel="Department"name="department"placeholder="Choose a department">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
</Select>
A plain form field. The browser draws the list: the native picker on phones, the most familiar control for screen readers. Options are one line of text.
For two to five options that should all stay visible, use a radio group (one choice) or checkboxes (several).
Placeholder and starting value
placeholder adds an empty first choice in a muted colour. With required, the user has to pick something else before the form submits.
Without a placeholder, the select starts on value, else on the <option selected>, else on the first option, as a native select does. Reset goes back to that starting value. change fires when the user picks an option.
React + Tailwind renders a native <select>, so its onChange is React's own and it also takes defaultValue.
Groups and disabled options
Put options in <optgroup label> to group them. disabled on an option or an <optgroup> shows it but blocks it. The web component watches its children, so you can add or remove <option>s at any time.
An address form fills the district list from the chosen province. Replace the options when the first select changes: the web component picks up the new children by itself. Keep the second select disabled until there is something to choose.
inline puts the label beside a compact, borderless select. Use it in toolbars and above tables, not in forms.
HTMLReactReact + Tailwind<ui-selectinlinelabel="Items per page"value="25">
<optionvalue="10">10</option>
<optionvalue="25">25</option>
<optionvalue="50">50</option>
</ui-select><UiSelectinlinelabel="Items per page"value="25">
<optionvalue="10">10</option>
<optionvalue="25">25</option>
<optionvalue="50">50</option>
</UiSelect><Selectinlinelabel="Items per page"defaultValue="25">
<optionvalue="10">10</option>
<optionvalue="25">25</option>
<optionvalue="50">50</option>
</Select>
Fluid
fluid puts the label inside a 64px box (Carbon's FluidSelect). A fluid form around the field does the same for every field in it; see fluid forms. Fluid fields have no helper line.
HTMLReactReact + Tailwind<ui-selectfluidlabel="Department"name="department"placeholder="Choose a department">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</ui-select><UiSelectfluidlabel="Department"name="department"placeholder="Choose a department">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</UiSelect><Selectfluidlabel="Department"name="department"placeholder="Choose a department">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</Select>
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-selectlabel="Department"name="department"placeholder="Choose a department"helper-text="Where the contract is filed">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</ui-select>
</div><divdata-field-variant="outlined">
<UiSelectlabel="Department"name="department"placeholder="Choose a department"helperText="Where the contract is filed">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</UiSelect>
</div><divdata-field-variant="outlined">
<Selectlabel="Department"name="department"placeholder="Choose a department"helperText="Where the contract is filed">
<optionvalue="sales">Sales</option>
<optionvalue="legal">Legal</option>
<optionvalue="finance">Finance</option>
</Select>
</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 is a non-blocking warning; invalid forces the error, for example after the server rejected the value.
HTMLReactReact + Tailwind<ui-selectlabel="Approver"name="approver"helper-text="The approver gets the contract next">
<optionvalue="somchai">Somchai K.</option>
<optionvalue="malee">Malee S.</option>
</ui-select>
<ui-selectlabel="Approver"name="approver2"value="malee"warnwarn-text="Malee is on leave until 20 October">
<optionvalue="somchai">Somchai K.</option>
<optionvalue="malee">Malee S.</option>
</ui-select>
<ui-selectlabel="Approver"name="approver3"value="somchai"invalidinvalid-text="Somchai drafted this contract and can't approve it">
<optionvalue="somchai">Somchai K.</option>
<optionvalue="malee">Malee S.</option>
</ui-select><UiSelectlabel="Approver"name="approver"helperText="The approver gets the contract next">…</UiSelect>
<UiSelectlabel="Approver"name="approver2"value="malee"warnwarnText="Malee is on leave until 20 October">…</UiSelect>
<UiSelectlabel="Approver"name="approver3"value="somchai"invalidinvalidText="Somchai drafted this contract and can't approve it">…</UiSelect><Selectlabel="Approver"name="approver"helperText="The approver gets the contract next">…</Select>
<Selectlabel="Approver"name="approver2"defaultValue="malee"warnwarnText="Malee is on leave until 20 October">…</Select>
<Selectlabel="Approver"name="approver3"defaultValue="somchai"invalidinvalidText="Somchai drafted this contract and can't approve it">…</Select>
A link in the helper text
The helper-text, warn-text and invalid-text attributes are plain text. For a link or bold text, put the markup in the slot of the same name. In React + Tailwind, pass the markup to helperText, warnText or invalidText.
With required and a placeholder, the form won't submit until the user picks an option. Press Submit without a choice to see the error. Without invalid-text, the built-in "Please select an option." shows, in the page's language.
Submitted:
HTMLReactReact + Tailwind<formid="select-form"style="display: grid; gap: 16px">
<ui-selectlabel="Contract type"name="type"placeholder="Choose a type"requiredinvalid-text="Choose the contract type">
<optionvalue="sale">Sale</option>
<optionvalue="lease">Lease</option>
<optionvalue="service">Service</option>
</ui-select>
<div><ui-buttontype="submit">Submit</ui-button></div>
</form>
<p>Submitted: <outputid="select-form-out"></output></p>
<scripttype="module">
const form = document.getElementById('select-form');
const out = document.getElementById('select-form-out');
form.addEventListener('submit', (event) => {
event.preventDefault();
out.value = [...newFormData(form)].map(([key, value]) =>`${key}=${value}`).join(', ');
});
</script>const [sent, setSent] =useState('');
constsubmit= (event:FormEvent<HTMLFormElement>) => {
event.preventDefault();
setSent([...newFormData(event.currentTarget)].map(([key, value]) =>`${key}=${value}`).join(', '));
};
<formonSubmit={submit}>
<UiSelectlabel="Contract type"name="type"placeholder="Choose a type"requiredinvalidText="Choose the contract type">
<optionvalue="sale">Sale</option>
<optionvalue="lease">Lease</option>
<optionvalue="service">Service</option>
</UiSelect>
<UiButtontype="submit">Submit</UiButton>
</form>
<p>Submitted: <output>{sent}</output></p>// validation is your app's: `type` is the field's value, `tried` is set on the first submit
<formonSubmit={submit}>
<Selectlabel="Contract type"name="type"placeholder="Choose a type"value={type} onChange={(e) =>setType(e.target.value)} invalid={tried &&!type} invalidText="Choose the contract type">
<optionvalue="sale">Sale</option>
<optionvalue="lease">Lease</option>
<optionvalue="service">Service</option>
</Select>
<Buttontype="submit">Submit</Button>
</form>
<p>Submitted: <output>{sent}</output></p>
The React + Tailwind select shows what you pass in invalid and invalidText; checking the value is your app's, as in Carbon React. More in Forms and validation.
Skeleton
While the options load, show ui-select-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/select-skeleton.
Accessibility
The control is a native <select>: the browser's own keys open and change it, and phones show the system picker.
label is tied to the select. Use hide-label to keep it for screen readers only when the context already names the field.
Helper, warning and error text are the select's description, so they are read when it gets focus.
Options can't hold markup or a second line. If you need that, use a Dropdown.
Unstyled React parts with the same behaviour: Headless Select.
API
Generated from the package. In React, pass a property as a prop of the same name; events are props too (the React column).
<ui-select> · React UiSelect
Attributes
Attribute
Property
Type
Default
Description
label
label
string
''
Visible label text; the label slot replaces it when markup is needed.
hide-label
hideLabel
boolean
false
Keep the label for screen readers but don't show it.
helper-text
helperText
string
''
Helper text under the field, shown while there is no error or warning.
invalid-text
invalidText
string
''
Error text shown while invalid or while the field fails validation.
invalid
invalid
boolean
false
Forces the error state, e.g. after server-side validation.
warn
warn
boolean
false
Non-blocking warning; shown when there is no error.
warn-text
warnText
string
''
Text of the warning shown while warn.
placeholder
placeholder
string
''
Shown as an empty first choice; with required the user must pick something else.
value
value
string
''
name
name
string
''
Reflected: form-associated elements submit under the name attribute.
size
size
'sm' | 'md' | 'lg'
'md'
Field height: sm 32px, md 40px, lg 48px (tokens --ui-field-height-*).
disabled
disabled
boolean
false
Disables the control; a disabled <fieldset> ancestor does the same.
required
required
boolean
false
Blocks form submission while the field is empty.
readonly
readonly
boolean
false
Shows and submits the value but blocks changes.
fluid
fluid
boolean
false
Carbon FluidSelect: the label inside a 64px box, an error / warning inside it. <ui-fluid-form> sets it for every field inside.
inline
inline
boolean
false
Label beside a compact, borderless select.
Properties
Property
Type
Description
willValidate
(read-only) Whether the field takes part in constraint validation (not while disabled), as natively.
labels
(read-only) The <label>s that point at this field.
Methods
Method
Description
setCustomValidity(message)
Like <input>.setCustomValidity(): a non-empty message makes the field invalid (and is shown as its error once touched) until cleared with ''.
Events
Event
React
Description
change
none (use a ref)
When the user picks an option
Slots
Slot
Description
label
Label content with markup; the label attribute is the plain-text fallback
helper-text
Helper text with markup (links, bold); overrides helper-text
warn-text
Warning text shown while warn; overrides warn-text
invalid-text
Error text shown while invalid; overrides invalid-text
CSS parts
Part
Description
base
The field box
label
The label
input
The native select
chevron
The arrow icon
status-icon
The error / warning icon
helper-text
The helper line
warning-text
The warning line
warn-text
Same line as warning-text (named after the warn-text attribute / slot)
error-text
The error line
invalid-text
Same line as error-text (named after the invalid-text attribute / slot)
CSS custom properties
Custom property
Default
Description
--ui-field-border
Border on every side of the box (default none: Carbon's underline only; Kanok: a 1px outline)
--ui-field-disabled-border-color
Border colour when disabled (default: the underline transparent)
--ui-field-readonly-border-color
Border colour when read-only (default: a hairline underline)
--ui-field-inline-border-color
Border colour of the inline variant (default: no underline)
--ui-field-radius
Corner radius of the box (default 0; Kanok: 6px)
--ui-select-appearance
base-select opens the list in the menu look of the dropdowns (--ui-menu-*) where the browser supports a customizable select (Chrome 135+); default none, the native list (Kanok: base-select)
--ui-field-background
Fill of the box (default --ui-surface-1; Kanok: transparent)
--ui-label-font
Font of the label (default --ui-font-caption; Kanok: 14px semibold)
--ui-label-color
Colour of the label (default --ui-ink-muted; Kanok: --ui-ink)
--ui-field-readonly-background
The box's fill when read-only (default transparent; Kanok: a faint ink tint, so read-only reads as set and never weaker than disabled)
--ui-fluid-background
/ --ui-fluid-gap - A fluid box's fill and the space under it (default the layer's fill, 0: boxes that touch; Kanok: transparent, 8px)