Zubra UI
Code for
GitHub

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

Compiled (any project)
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
.zb source (to edit it with Zubra)
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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valuestring""
labelstring""
placeholderstring""
items
property only
{ value, label }[][]
disabledbooleanfalse
Events
EventWhen
valuechangeAn 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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour