Run the CLI
Use the CLI to add the component to your project.
A combobox is an autocomplete input and command palette with a list of suggestions. The Combobox is built using a composition of the <Popover /> and the <Command /> components.
Use the CLI to add the component to your project.
Create the component directory structure and add the following files to your project.
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"
class="w-[200px]"
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);
}
}
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);
}
}
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" [disabled]="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' },
];
}