combobox

Autocomplete input and command palette with a list of suggestions.

PreviousNext
import { Component } from '@angular/core';

import { ZardComboboxComponent, type ZardComboboxOption } from '../combobox.component';

@Component({
  selector: 'zard-demo-combobox-default',
  imports: [ZardComboboxComponent],
  standalone: true,
  template: `
    <z-combobox
      [options]="frameworks"
      placeholder="Select framework..."
      searchPlaceholder="Search framework..."
      emptyText="No framework found."
      (zComboSelected)="onSelect($event)"
    />
  `,
})
export class ZardDemoComboboxDefaultComponent {
  frameworks: ZardComboboxOption[] = [
    { value: 'angular', label: 'Angular' },
    { value: 'react', label: 'React' },
    { value: 'vue', label: 'Vue.js' },
    { value: 'svelte', label: 'Svelte' },
    { value: 'ember', label: 'Ember.js' },
    { value: 'nextjs', label: 'Next.js' },
  ];

  onSelect(option: ZardComboboxOption) {
    console.log('Selected:', option);
  }
}

Installation

Copy
npx zard-cli@latest add combobox

Usage

import { ZardComboboxComponent } from '@/shared/components/combobox/combobox.component';
Copy
<z-combobox [options]="options" placeholder="Select framework..."></z-combobox>
Copy

Examples

default

import { Component } from '@angular/core';

import { ZardComboboxComponent, type ZardComboboxOption } from '../combobox.component';

@Component({
  selector: 'zard-demo-combobox-default',
  imports: [ZardComboboxComponent],
  standalone: true,
  template: `
    <z-combobox
      [options]="frameworks"
      placeholder="Select framework..."
      searchPlaceholder="Search framework..."
      emptyText="No framework found."
      (zComboSelected)="onSelect($event)"
    />
  `,
})
export class ZardDemoComboboxDefaultComponent {
  frameworks: ZardComboboxOption[] = [
    { value: 'angular', label: 'Angular' },
    { value: 'react', label: 'React' },
    { value: 'vue', label: 'Vue.js' },
    { value: 'svelte', label: 'Svelte' },
    { value: 'ember', label: 'Ember.js' },
    { value: 'nextjs', label: 'Next.js' },
  ];

  onSelect(option: ZardComboboxOption) {
    console.log('Selected:', option);
  }
}

grouped

import { Component } from '@angular/core';

import { ZardComboboxComponent, type ZardComboboxGroup, type ZardComboboxOption } from '../combobox.component';

@Component({
  selector: 'zard-demo-combobox-grouped',
  imports: [ZardComboboxComponent],
  standalone: true,
  template: `
    <z-combobox
      [groups]="techGroups"
      placeholder="Select technology..."
      searchPlaceholder="Search technology..."
      emptyText="No technology found."
      (zComboSelected)="onSelect($event)"
    />
  `,
})
export class ZardDemoComboboxGroupedComponent {
  techGroups: ZardComboboxGroup[] = [
    {
      label: 'Frontend Frameworks',
      options: [
        { value: 'angular', label: 'Angular' },
        { value: 'react', label: 'React' },
        { value: 'vue', label: 'Vue.js' },
        { value: 'svelte', label: 'Svelte' },
      ],
    },
    {
      label: 'Backend Frameworks',
      options: [
        { value: 'nestjs', label: 'NestJS' },
        { value: 'express', label: 'Express' },
        { value: 'fastify', label: 'Fastify' },
        { value: 'koa', label: 'Koa' },
      ],
    },
    {
      label: 'Full-Stack Frameworks',
      options: [
        { value: 'nextjs', label: 'Next.js' },
        { value: 'nuxtjs', label: 'Nuxt.js' },
        { value: 'remix', label: 'Remix' },
        { value: 'sveltekit', label: 'SvelteKit' },
      ],
    },
  ];

  onSelect(option: ZardComboboxOption) {
    console.log('Selected:', option);
  }
}

disabled

import { Component } from '@angular/core';

import { ZardComboboxComponent, type ZardComboboxOption } from '../combobox.component';

@Component({
  selector: 'zard-demo-combobox-disabled',
  imports: [ZardComboboxComponent],
  standalone: true,
  template: `
    <div class="flex gap-4">
      <z-combobox [options]="frameworks" placeholder="Disabled combobox" [zDisabled]="true" />

      <z-combobox
        [options]="frameworksWithDisabled"
        placeholder="Select framework..."
        searchPlaceholder="Search framework..."
        emptyText="No framework found."
      />
    </div>
  `,
})
export class ZardDemoComboboxDisabledComponent {
  frameworks: ZardComboboxOption[] = [
    { value: 'angular', label: 'Angular' },
    { value: 'react', label: 'React' },
    { value: 'vue', label: 'Vue.js' },
  ];

  frameworksWithDisabled: ZardComboboxOption[] = [
    { value: 'angular', label: 'Angular' },
    { value: 'react', label: 'React', disabled: true },
    { value: 'vue', label: 'Vue.js' },
    { value: 'svelte', label: 'Svelte', disabled: true },
    { value: 'ember', label: 'Ember.js' },
  ];
}

form

Current value: None
import { Component } from '@angular/core';
import { FormControl, ReactiveFormsModule } from '@angular/forms';

import { ZardButtonComponent } from '../../button/button.component';
import { ZardComboboxComponent, type ZardComboboxOption } from '../combobox.component';

@Component({
  selector: 'zard-demo-combobox-form',
  imports: [ReactiveFormsModule, ZardComboboxComponent, ZardButtonComponent],
  standalone: true,
  template: `
    <div class="flex flex-col gap-4">
      <z-combobox
        [options]="frameworks"
        placeholder="Select framework..."
        searchPlaceholder="Search framework..."
        emptyText="No framework found."
        [formControl]="frameworkControl"
      />

      <div class="flex gap-2">
        <button z-button variant="outline" (click)="setValue()">Set to Vue.js</button>
        <button z-button variant="outline" (click)="clearValue()">Clear</button>
        <button z-button variant="outline" (click)="logValue()">Log Value</button>
      </div>

      <div class="text-muted-foreground text-sm">Current value: {{ frameworkControl.value ?? 'None' }}</div>
    </div>
  `,
})
export class ZardDemoComboboxFormComponent {
  frameworkControl = new FormControl<string | null>(null);

  frameworks: ZardComboboxOption[] = [
    { value: 'angular', label: 'Angular' },
    { value: 'react', label: 'React' },
    { value: 'vue', label: 'Vue.js' },
    { value: 'svelte', label: 'Svelte' },
    { value: 'ember', label: 'Ember.js' },
  ];

  setValue() {
    this.frameworkControl.setValue('vue');
  }

  clearValue() {
    this.frameworkControl.setValue(null);
  }

  logValue() {
    console.log('Form Control Value:', this.frameworkControl.value);
  }
}

API Reference

z-comboboxComponent

Autocomplete input and command palette with a list of suggestions.

PropertyDescriptionTypeDefault
class Additional CSS classes ClassValue ''
buttonVariant Button variant style 'default' | 'outline' | 'secondary' | 'ghost' 'outline'
zWidth Width of the combobox 'default' | 'sm' | 'md' | 'lg' | 'full' 'default'
placeholder Placeholder text when no value is selected string 'Select...'
searchPlaceholder Placeholder for the search input string 'Search...'
emptyText Text shown when no options match the search string 'No results found.'
zDisabled Whether the combobox is disabled boolean false
searchable Whether to show the search input boolean true
value The selected value string | null null
options Array of options (for flat list) ZardComboboxOption[] []
groups Array of grouped options ZardComboboxGroup[] []
ariaLabel ARIA label for accessibility string ''
ariaDescribedBy ARIA described-by for accessibility string ''
(zValueChange) Emitted when the value changes output<string | null> -
(zComboSelected) Emitted when an option is selected output<ZardComboboxOption> -
github iconwhatsapp icondiscord iconX icon

Made with in Brazil. Open source and available on GitHub .