combo-box
A combobox: type to filter, arrow keys to move, Enter to pick, Escape to close. A form control. items is [{ value, label }]; value is two-way.
Try it: events appear here (valuechange).
Source: combo-box.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/combo-box.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/combo-box.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/combo-box.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/combo-box.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/combo-box.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/combo-box.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/combo-box.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/combo-box.json
The compiled install writes src/components/zubra/combo-box.js and the theme, and adds @zubra/runtime to your dependencies, with @zag-js/vanilla and @zag-js/combobox (Zag.js runs its keyboard and focus behaviour).
Usage
<combo-box label="Country" placeholder="Start typing…" name="country"></combo-box>
<script type="module">
import './components/zubra/combo-box.js';
const element = document.querySelector('combo-box');
element.items = [
{ value: 'ar', label: 'Argentina' },
{ value: 'au', label: 'Australia' },
{ value: 'br', label: 'Brazil' },
{ value: 'ca', label: 'Canada' },
{ value: 'de', label: 'Germany' },
{ value: 'in', label: 'India' },
{ value: 'jp', label: 'Japan' },
{ value: 'ke', label: 'Kenya' },
{ value: 'mx', label: 'Mexico' },
{ value: 'nz', label: 'New Zealand' },
{ value: 'pt', label: 'Portugal' },
{ value: 'us', label: 'United States' },
];
element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
</script>import './components/zubra/combo-box.js';
const items = [
{ value: 'ar', label: 'Argentina' },
{ value: 'au', label: 'Australia' },
{ value: 'br', label: 'Brazil' },
{ value: 'ca', label: 'Canada' },
{ value: 'de', label: 'Germany' },
{ value: 'in', label: 'India' },
{ value: 'jp', label: 'Japan' },
{ value: 'ke', label: 'Kenya' },
{ value: 'mx', label: 'Mexico' },
{ value: 'nz', label: 'New Zealand' },
{ value: 'pt', label: 'Portugal' },
{ value: 'us', label: 'United States' },
];
export function ComboBoxExample() {
return (
<combo-box
label="Country"
placeholder="Start typing…"
name="country"
items={items}
onvaluechange={(event) => console.log('valuechange', event.detail)}
></combo-box>
);
}<script setup>
import './components/zubra/combo-box.js';
const items = [
{ value: 'ar', label: 'Argentina' },
{ value: 'au', label: 'Australia' },
{ value: 'br', label: 'Brazil' },
{ value: 'ca', label: 'Canada' },
{ value: 'de', label: 'Germany' },
{ value: 'in', label: 'India' },
{ value: 'jp', label: 'Japan' },
{ value: 'ke', label: 'Kenya' },
{ value: 'mx', label: 'Mexico' },
{ value: 'nz', label: 'New Zealand' },
{ value: 'pt', label: 'Portugal' },
{ value: 'us', label: 'United States' },
];
const onValuechange = (event) => console.log('valuechange', event.detail);
</script>
<template>
<combo-box
label="Country"
placeholder="Start typing…"
name="country"
:items.prop="items"
@valuechange="onValuechange"
></combo-box>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/combo-box.js';
const items = [
{ value: 'ar', label: 'Argentina' },
{ value: 'au', label: 'Australia' },
{ value: 'br', label: 'Brazil' },
{ value: 'ca', label: 'Canada' },
{ value: 'de', label: 'Germany' },
{ value: 'in', label: 'India' },
{ value: 'jp', label: 'Japan' },
{ value: 'ke', label: 'Kenya' },
{ value: 'mx', label: 'Mexico' },
{ value: 'nz', label: 'New Zealand' },
{ value: 'pt', label: 'Portugal' },
{ value: 'us', label: 'United States' },
];
</script>
<combo-box
label="Country"
placeholder="Start typing…"
name="country"
{items}
onvaluechange={(event) => console.log('valuechange', event.detail)}
></combo-box>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/combo-box.js';
@Component({
selector: 'app-combo-box-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<combo-box
label="Country"
placeholder="Start typing…"
name="country"
[items]="items"
(valuechange)="onValuechange($event)"
></combo-box>
`,
})
export class ComboBoxExample {
items = [
{ value: 'ar', label: 'Argentina' },
{ value: 'au', label: 'Australia' },
{ value: 'br', label: 'Brazil' },
{ value: 'ca', label: 'Canada' },
{ value: 'de', label: 'Germany' },
{ value: 'in', label: 'India' },
{ value: 'jp', label: 'Japan' },
{ value: 'ke', label: 'Kenya' },
{ value: 'mx', label: 'Mexico' },
{ value: 'nz', label: 'New Zealand' },
{ value: 'pt', label: 'Portugal' },
{ value: 'us', label: 'United States' },
];
onValuechange(event: Event) {
console.log('valuechange', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
value | string | "" |
label | string | "" |
placeholder | string | "" |
itemsproperty only | { value, label }[] | [] |
disabled | boolean | false |
| Event | When |
|---|---|
valuechange | An item was picked; detail is its value. |
Size
1.4 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 19.5 KB, plus @zag-js/vanilla and @zag-js/combobox.