Components › Components
Demos show your theme.
Combobox
A text field that filters a list of options as you type.
- Apple
- Banana
- Cherry
- Grape
Picked:
Usage #
The parts come from @clarusjs/ui-primitives; the look is combobox.css, imported once.
tscl
@import './combobox.css'
@import uiCombobox from '@clarusjs/ui-primitives/combobox.tscl'
<script>
let fruit = state('')
const fruits = [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'cherry', label: 'Cherry' },
{ value: 'grape', label: 'Grape' },
]
</script>
<div class="demo">
<uiCombobox [id]="'demo-fruit'" [label]="'Fruit'" [options]="fruits" [(value)]="fruit" />
<p>
Picked: <span class="out">{{ fruit }}</span>
</p>
</div>
<style scoped>
:scope {
display: grid;
gap: 12px;
padding: 24px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-bg);
color: var(--ui-fg);
}
p {
margin: 0;
}
</style>Source #
Copy it next to your components as combobox.css. It's the same as @clarusjs/ui's rules for these parts, so using both looks the same.
css
/*
Combobox: the same rules as @clarusjs/ui's ui.css for combobox.tscl from @clarusjs/ui-primitives.
Copy it next to your components, @import it once, and change it to change the look.
*/
@layer theme, base, components, utilities;
@layer components {
/* Focus is always visible, on every part and what's inside it. */
:where([data-part]):focus-visible,
:where([data-part]) :focus-visible {
outline: 2px solid var(--ui-ring);
outline-offset: 2px;
}
/* Field and select: label, control, description, error. */
:where([data-part='field'], [data-part='select']) {
display: grid;
gap: 4px;
max-width: 360px;
font: var(--ui-font-size) var(--ui-font);
color: var(--ui-fg);
}
:where([data-part='label']) {
font-weight: 600;
font-size: calc(var(--ui-font-size) - 1px);
color: var(--ui-fg);
}
:where([data-part='control']) {
min-height: 34px;
padding: 4px 10px;
border: 1px solid var(--ui-input);
border-radius: var(--ui-radius);
background: var(--ui-bg);
color: var(--ui-fg);
font: var(--ui-font-size) var(--ui-font);
}
:where([data-part='control'])[aria-invalid='true'] {
border: 1px solid var(--ui-danger);
}
:where([data-part='description']) {
margin: 0;
color: var(--ui-muted);
font-size: calc(var(--ui-font-size) - 1px);
}
:where([data-part='error']) {
margin: 0;
color: var(--ui-danger);
font-size: calc(var(--ui-font-size) - 1px);
}
:where([data-part='option']) {
padding: 6px 10px;
border-radius: calc(var(--ui-radius) - 2px);
}
:where([data-part='select']) ::picker(select) {
padding: 4px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-popover);
color: var(--ui-popover-fg);
box-shadow: var(--ui-shadow);
}
/* Combobox: chips in the control, a list below. */
:where([data-part='combobox']) {
display: grid;
gap: 4px;
max-width: 360px;
font: var(--ui-font-size) var(--ui-font);
color: var(--ui-fg);
}
:where([data-part='combobox']) > :where([data-part='control']) {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px;
padding: 2px 6px;
}
:where([data-part='combobox']) > :where([data-part='control']):focus-within {
border-color: var(--ui-ring);
box-shadow: 0 0 0 3px var(--ui-accent-soft);
}
:where([data-part='input']) {
flex: 1;
min-width: 6ch;
min-height: 26px;
padding: 0 4px;
border: 0;
background: none;
color: var(--ui-fg);
font: inherit;
outline: none;
}
:where([data-part='chip']) {
display: inline-flex;
align-items: center;
gap: 2px;
padding: 0 2px 0 8px;
border-radius: 999px;
background: var(--ui-accent-soft);
font-size: calc(var(--ui-font-size) - 1px);
}
:where([data-part='chip']) button {
min-width: 24px;
min-height: 24px;
border: 0;
border-radius: 999px;
background: none;
color: var(--ui-muted);
cursor: pointer;
}
:where([data-part='listbox']) {
margin-top: 4px;
padding: 4px;
border: 1px solid var(--ui-border);
border-radius: var(--ui-radius);
background: var(--ui-popover);
color: var(--ui-popover-fg);
box-shadow: var(--ui-shadow);
}
:where([data-part='listbox']) > :where([data-part='option']) {
cursor: pointer;
}
:where([data-part='option'])[data-highlighted] {
background: var(--ui-accent-soft);
}
:where([data-part='option'])[aria-selected='true'] {
font-weight: 600;
}
:where([data-part='status']) {
margin: 0;
color: var(--ui-muted);
font-size: calc(var(--ui-font-size) - 1px);
}
:where([data-part='status']):empty {
display: none;
}
@media (prefers-reduced-motion: reduce) {
:where([data-part]),
:where([data-part]) * {
transition: none !important;
}
}
}Styling #
- On the parts:
class,style,id,aria-*anddata-*written on a part's tag (from@clarusjs/ui-primitives) land on its root element, merged with its own. - Selectors:
data-partnamesfield,select,label,control,description,error,option,combobox,input,chip,listbox,status. - Your rules win: every rule here has zero specificity (
:where()) and sits in@layer components, so your own CSS and Tailwind utilities override it.
Needs #
- theme.css, once per project
-
@clarusjs/ui-primitives≥ 0.1.0: combobox.tscl