Combobox
<quiet-combobox>
Allows users to select from a list of options with type-ahead search.
Comboboxes implement the ARIA APG combobox pattern for roles and keyboard navigation, with enhanced screen reader announcements via ARIA live regions for improved context while navigating options.
<quiet-combobox label="Select a cat breed" description="Type to search or select from the list" placeholder="Search breeds" with-clear > <quiet-combobox-item value="persian">Persian</quiet-combobox-item> <quiet-combobox-item value="siamese">Siamese</quiet-combobox-item> <quiet-combobox-item value="tabby">Tabby</quiet-combobox-item> <quiet-combobox-item value="ragdoll">Ragdoll</quiet-combobox-item> <quiet-combobox-item value="bengal">Bengal</quiet-combobox-item> <quiet-combobox-item value="sphynx">Sphynx</quiet-combobox-item> <quiet-combobox-item value="calico">Calico</quiet-combobox-item> <quiet-combobox-item value="russian">Russian Blue</quiet-combobox-item> </quiet-combobox>
Examples Jump to heading
Labels and descriptions Jump to heading
You can use the label
and description
attributes to provide plain text labels and
descriptions for the combobox. If you want to provide HTML, use the label
and
description
slots instead.
<quiet-combobox placeholder="Type to search"> <span slot="label">Choose your <strong>purrfect</strong> companion</span> <span slot="description"> Browse our available cats or <a href="https://example.com/" target="_blank">schedule a visit</a>. </span> <quiet-combobox-item value="luna">Luna (Tabby, 2 years)</quiet-combobox-item> <quiet-combobox-item value="milo">Milo (Orange, 1 year)</quiet-combobox-item> <quiet-combobox-item value="bella">Bella (Calico, 3 years)</quiet-combobox-item> </quiet-combobox>
Providing options Jump to heading
Create combobox options by adding <quiet-combobox-item>
elements inside the combobox.
Each item should have a value
attribute that will be submitted with the form. If no value is
provided, the text content is used.
<quiet-combobox label="Cat personalities" placeholder="Search personalities"> <quiet-combobox-item value="playful">Playful and Energetic</quiet-combobox-item> <quiet-combobox-item value="cuddly">Cuddly Lap Cat</quiet-combobox-item> <quiet-combobox-item value="independent">Independent Spirit</quiet-combobox-item> <quiet-combobox-item value="social">Social Butterfly</quiet-combobox-item> <quiet-combobox-item value="curious">Curious Explorer</quiet-combobox-item> </quiet-combobox>
Combobox items can have structured content with icons and details.
<quiet-combobox label="Adoption status" placeholder="Filter by status" id="combobox__structured"> <quiet-combobox-item value="available"> <quiet-icon slot="icon" name="circle-check" variant="constructive"></quiet-icon> <span>Available Now</span> <span slot="details">Ready for adoption</span> </quiet-combobox-item> <quiet-combobox-item value="pending"> <quiet-icon slot="icon" name="clock" variant="informative"></quiet-icon> <span>Adoption Pending</span> <span slot="details">Application in review</span> </quiet-combobox-item> <quiet-combobox-item value="medical"> <quiet-icon slot="icon" name="heart" variant="critical"></quiet-icon> <span>Medical Hold</span> <span slot="details">Recovering from treatment</span> </quiet-combobox-item> <quiet-combobox-item value="foster"> <quiet-icon slot="icon" name="home" variant="primary"></quiet-icon> <span>Foster Only</span> <span slot="details">Temporary care needed</span> </quiet-combobox-item> </quiet-combobox> <style> #combobox__structured { quiet-combobox-item { padding-block: 0.75rem; } } </style>
Avoid placing interactive elements such as buttons and links inside the combobox item, as this will hinder accessibility and can lead to unexpected behaviors.
Providing an initial value Jump to heading
Add the selected
attribute to the combobox item you want to select initially. When using
multiple
, you can apply selected
to more than one option.
<quiet-combobox label="Preferred feeding time" placeholder="Select a time"> <quiet-combobox-item value="morning">Morning (6-9 AM)</quiet-combobox-item> <quiet-combobox-item value="noon" selected>Noon (11 AM-1 PM)</quiet-combobox-item> <quiet-combobox-item value="evening">Evening (5-7 PM)</quiet-combobox-item> <quiet-combobox-item value="night">Night (8-10 PM)</quiet-combobox-item> </quiet-combobox>
Getting and setting the value Jump to heading
The combobox's value can be accessed and modified through JavaScript. For single selection, use the
value
property. For multiple selection, value
will be an array.
// Single selection const combobox = document.querySelector('quiet-combobox'); console.log(combobox.value); // "persian" combobox.value = 'siamese'; // Multiple selection const multiCombobox = document.querySelector('quiet-combobox[multiple]'); console.log(multiCombobox.value); // ["persian", "siamese"] multiCombobox.value = ['bengal', 'ragdoll'];
Multiple selection Jump to heading
Use the multiple
attribute to enable multi-selection mode. Selected items appear as tags in the
input area. Users can remove tags by clicking the × button or pressing Backspace.
<quiet-combobox label="Cat behaviors" description="Select all behaviors your cat exhibits" placeholder="Search behaviors" multiple with-clear > <quiet-combobox-item value="purring" selected>Purring</quiet-combobox-item> <quiet-combobox-item value="kneading">Kneading (Making Biscuits)</quiet-combobox-item> <quiet-combobox-item value="chirping" selected>Chirping at Birds</quiet-combobox-item> <quiet-combobox-item value="head-bunting">Head Bunting</quiet-combobox-item> <quiet-combobox-item value="slow-blinking">Slow Blinking</quiet-combobox-item> <quiet-combobox-item value="zoomies">Midnight Zoomies</quiet-combobox-item> <quiet-combobox-item value="bringing-gifts">Bringing "Gifts"</quiet-combobox-item> <quiet-combobox-item value="chattering">Teeth Chattering</quiet-combobox-item> </quiet-combobox>
In multiple mode, the dropdown stays open after selecting an item, allowing users to quickly select multiple options. Press Escape or click outside to close the dropdown.
Adding a clear button Jump to heading
Add the with-clear
attribute to show a clear button when the combobox has a value. This allows
users to quickly clear their selection.
<quiet-combobox label="With clear button" placeholder="Select and then clear" with-clear > <quiet-combobox-item value="yes" selected>Yes, I want treats!</quiet-combobox-item> <quiet-combobox-item value="no">No treats needed</quiet-combobox-item> <quiet-combobox-item value="maybe">Maybe later</quiet-combobox-item> </quiet-combobox>
Start and end content Jump to heading
Use the start
and end
slots to add presentational icons or text. Avoid interactive
elements such as buttons, links, etc. Works well with
<quiet-icon>
and <svg>
elements.
<quiet-combobox name="breed" label="Cat breed" with-clear> <quiet-icon slot="start" name="cat"></quiet-icon> <quiet-combobox-item value="persian">Persian</quiet-combobox-item> <quiet-combobox-item value="siamese">Siamese</quiet-combobox-item> <quiet-combobox-item value="tabby">Tabby</quiet-combobox-item> <quiet-combobox-item value="ragdoll">Ragdoll</quiet-combobox-item> </quiet-combobox> <br> <quiet-combobox name="toy" label="Cat toy" placeholder="Choose a toy" with-clear> <quiet-icon slot="end" name="gift"></quiet-icon> <quiet-combobox-item value="feather-wand">Feather Wand</quiet-combobox-item> <quiet-combobox-item value="laser-pointer">Laser Pointer</quiet-combobox-item> <quiet-combobox-item value="catnip-mouse">Catnip Mouse</quiet-combobox-item> <quiet-combobox-item value="puzzle-feeder">Puzzle Feeder</quiet-combobox-item> </quiet-combobox> <br> <quiet-combobox name="vet-visit" label="Visit type" multiple with-clear> <quiet-icon slot="start" name="cat"></quiet-icon> <quiet-icon slot="end" name="clipboard-heart"></quiet-icon> <quiet-combobox-item value="checkup">Annual Checkup</quiet-combobox-item> <quiet-combobox-item value="vaccination">Vaccination</quiet-combobox-item> <quiet-combobox-item value="dental">Dental Cleaning</quiet-combobox-item> <quiet-combobox-item value="grooming">Grooming</quiet-combobox-item> </quiet-combobox>
Filled and unstyled comboboxes Jump to heading
Use the appearance
attribute to change the visual style of the combobox. Options are
normal
(default), filled
, and unstyled
.
<quiet-combobox label="Normal appearance" appearance="normal" placeholder="Select one" > <quiet-combobox-item value="1">Fluffy</quiet-combobox-item> <quiet-combobox-item value="2">Sleek</quiet-combobox-item> <quiet-combobox-item value="3">Short-haired</quiet-combobox-item> </quiet-combobox> <br> <quiet-combobox label="Filled appearance" appearance="filled" placeholder="Select one" > <quiet-combobox-item value="1">Fluffy</quiet-combobox-item> <quiet-combobox-item value="2">Sleek</quiet-combobox-item> <quiet-combobox-item value="3">Short-haired</quiet-combobox-item> </quiet-combobox> <br> <quiet-combobox label="Unstyled appearance" appearance="unstyled" placeholder="Select one" > <quiet-combobox-item value="1">Fluffy</quiet-combobox-item> <quiet-combobox-item value="2">Sleek</quiet-combobox-item> <quiet-combobox-item value="3">Short-haired</quiet-combobox-item> </quiet-combobox>
Pill-shaped comboboxes Jump to heading
Add the pill
attribute to give the combobox rounded edges.
<quiet-combobox label="Cat's favorite treat" placeholder="Choose a treat" pill with-clear > <quiet-combobox-item value="salmon">Salmon Bites</quiet-combobox-item> <quiet-combobox-item value="chicken">Chicken Strips</quiet-combobox-item> <quiet-combobox-item value="tuna">Tuna Flakes</quiet-combobox-item> <quiet-combobox-item value="catnip">Catnip Cookies</quiet-combobox-item> <quiet-combobox-item value="cheese">Cheese Cubes</quiet-combobox-item> </quiet-combobox>
When using multiple
, tags become pill-shaped and the combobox will curve to wrap around them.
<quiet-combobox label="Cat's daily activities" description="Select all that apply" placeholder="What does your cat enjoy?" pill multiple with-clear > <quiet-combobox-item value="window-watching" selected>Bird Watching</quiet-combobox-item> <quiet-combobox-item value="sunbathing" selected>Sunbathing</quiet-combobox-item> <quiet-combobox-item value="toy-hunting" selected>Toy Hunting</quiet-combobox-item> <quiet-combobox-item value="box-sitting" selected>Box Sitting</quiet-combobox-item> <quiet-combobox-item value="treat-begging" selected>Treat Begging</quiet-combobox-item> <quiet-combobox-item value="midnight-racing" selected>Midnight Racing</quiet-combobox-item> <quiet-combobox-item value="lap-napping" selected>Lap Napping</quiet-combobox-item> </quiet-combobox>
Changing the size Jump to heading
Use the size
attribute to change the combobox's size. Available sizes are xs
,
sm
, md
(default), lg
, and xl
.
<quiet-select label="Select a size" value="xs" style="max-width: 18rem; margin-block-end: 2rem;"> <option value="xs">Extra small</option> <option value="sm">Small</option> <option value="md">Medium</option> <option value="lg">Large</option> <option value="xl">Extra large</option> </quiet-select> <quiet-combobox size="xs" label="Cat coat pattern" description="Size changes dynamically based on selection above" placeholder="Search patterns" id="combobox__size" with-clear > <quiet-combobox-item value="solid">Solid Color</quiet-combobox-item> <quiet-combobox-item value="tabby">Tabby Stripes</quiet-combobox-item> <quiet-combobox-item value="calico">Calico</quiet-combobox-item> <quiet-combobox-item value="tortoiseshell">Tortoiseshell</quiet-combobox-item> <quiet-combobox-item value="tuxedo">Tuxedo</quiet-combobox-item> <quiet-combobox-item value="pointed">Pointed (Siamese)</quiet-combobox-item> </quiet-combobox> <script> const combobox = document.getElementById('combobox__size'); const select = combobox.previousElementSibling; select.addEventListener('quiet-change', () => { combobox.size = select.value; }); </script>
Disabling the combobox Jump to heading
Add the disabled
attribute to disable the entire combobox.
<quiet-combobox label="Grooming services" description="Currently unavailable" placeholder="Service selection disabled" disabled > <quiet-combobox-item value="bath">Bath & Blow-dry</quiet-combobox-item> <quiet-combobox-item value="trim" selected>Nail Trim</quiet-combobox-item> <quiet-combobox-item value="full">Full Grooming</quiet-combobox-item> </quiet-combobox>
Disabling items Jump to heading
Add the disabled
attribute to individual combobox items to make them non-selectable. Disabled
items will still appear in search results but cannot be selected.
<quiet-combobox label="Veterinary services" placeholder="Select service"> <quiet-combobox-item value="checkup">Annual Checkup</quiet-combobox-item> <quiet-combobox-item value="vaccination">Vaccination</quiet-combobox-item> <quiet-combobox-item value="spay-neuter" disabled>Spay/Neuter (Fully booked)</quiet-combobox-item> <quiet-combobox-item value="dental">Dental Cleaning</quiet-combobox-item> <quiet-combobox-item value="emergency" disabled>Emergency Care (Call first)</quiet-combobox-item> </quiet-combobox>
Showing labels on the side Jump to heading
With the
quiet-side-label
utility, you can
show labels on the side instead of on top of the combobox. You can control the width of the label by setting
the --label-width
custom property.
<quiet-combobox class="quiet-side-label" style="--label-width: 12ch;" name="age" label="Cat's age" description="How old is your cat?" placeholder="Select age range" > <quiet-combobox-item value="kitten">Kitten (0-1 year)</quiet-combobox-item> <quiet-combobox-item value="young">Young (1-3 years)</quiet-combobox-item> <quiet-combobox-item value="adult">Adult (3-7 years)</quiet-combobox-item> <quiet-combobox-item value="senior">Senior (7+ years)</quiet-combobox-item> </quiet-combobox> <br> <quiet-combobox class="quiet-side-label" style="--label-width: 12ch;" name="activity" label="Activity level" description="How active is your cat?" placeholder="Select activity" > <quiet-combobox-item value="low">Couch Potato</quiet-combobox-item> <quiet-combobox-item value="moderate">Moderately Active</quiet-combobox-item> <quiet-combobox-item value="high">Very Energetic</quiet-combobox-item> </quiet-combobox>
Validation Jump to heading
The required
attribute can be used to enable validation using the
Constraint Validation API.
<form action="about:blank" method="get" target="_blank"> <quiet-combobox name="emergency-contact" label="Emergency vet contact" placeholder="Select a veterinarian" required > <quiet-combobox-item value="dr-smith">Dr. Smith - City Animal Hospital</quiet-combobox-item> <quiet-combobox-item value="dr-jones">Dr. Jones - Pet Emergency Center</quiet-combobox-item> <quiet-combobox-item value="dr-brown">Dr. Brown - 24/7 Pet Care</quiet-combobox-item> </quiet-combobox> <br> <quiet-button type="submit" variant="primary">Submit</quiet-button> <quiet-button type="reset">Reset</quiet-button> </form>
Using custom validation Jump to heading
Use the setCustomValidity()
method to make the combobox invalid and show a custom error message
on submit. This will override all other validation parameters. To clear the error, call the method with an
empty string.
<form action="about:blank" method="get" target="_blank" id="combobox__custom-validation"> <quiet-combobox name="special-diet" label="Special dietary needs" description="This field demonstrates custom validation" placeholder="Select diet" > <quiet-combobox-item value="regular">Regular Diet</quiet-combobox-item> <quiet-combobox-item value="grain-free">Grain-Free</quiet-combobox-item> <quiet-combobox-item value="prescription">Prescription Diet</quiet-combobox-item> </quiet-combobox> <br> <quiet-button type="submit" variant="primary">Submit</quiet-button> </form> <script type="module"> import { allDefined } from '/dist/quiet.js'; await allDefined(); const form = document.getElementById('combobox__custom-validation'); const combobox = form.querySelector('quiet-combobox'); combobox.setCustomValidity('Please consult with your vet first!'); // Clear validation after user selects an option combobox.addEventListener('quiet-change', () => { combobox.setCustomValidity(''); }); </script>
Styling validation Jump to heading
You can style valid and invalid comboboxes using the :valid
and :invalid
pseudo
classes.
<form action="about:blank" method="get" target="_blank" class="combobox__validation-pseudo"> <quiet-combobox name="chip-id" label="Microchip ID" description="Required for registration" placeholder="Enter or select chip ID" required > <quiet-combobox-item value="chip-12345">CHIP-12345</quiet-combobox-item> <quiet-combobox-item value="chip-67890">CHIP-67890</quiet-combobox-item> <quiet-combobox-item value="chip-24680">CHIP-24680</quiet-combobox-item> </quiet-combobox> <br> <quiet-button type="submit" variant="primary">Submit</quiet-button> <quiet-button type="reset">Reset</quiet-button> </form> <style> .combobox__validation-pseudo { quiet-combobox:valid { outline: solid 2px var(--quiet-constructive-stroke-mid); outline-offset: .5rem; } quiet-combobox:invalid { outline: solid 2px var(--quiet-destructive-stroke-mid); outline-offset: .5rem; } } </style>
However, these selectors will match even before the user has had a chance to interact with the form. More
often than not, you'll want to use the user-valid
and user-invalid
custom states
instead. This way, validation styles are only shown after the user interacts with the form control
or when the form is submitted.
<form action="about:blank" method="get" target="_blank" class="combobox__validation-custom"> <quiet-combobox name="insurance" label="Pet insurance provider" description="Select your insurance company" placeholder="Search providers" required > <quiet-combobox-item value="pawguard-plus">PawGuard Plus</quiet-combobox-item> <quiet-combobox-item value="furry-shield">Furry Shield</quiet-combobox-item> <quiet-combobox-item value="petcare-prime">PetCare Prime</quiet-combobox-item> <quiet-combobox-item value="whiskers-wellness">Whiskers Wellness</quiet-combobox-item> </quiet-combobox> <br> <quiet-button type="submit" variant="primary">Submit</quiet-button> <quiet-button type="reset">Reset</quiet-button> </form> <style> .combobox__validation-custom { quiet-combobox:state(user-valid) { outline: solid 2px var(--quiet-constructive-stroke-mid); outline-offset: .5rem; } quiet-combobox:state(user-invalid) { outline: solid 2px var(--quiet-destructive-stroke-mid); outline-offset: .5rem; } } </style>
API Jump to heading
Importing Jump to heading
The autoloader is the recommended way to import components but, if you prefer to do it manually, the following code snippets will be helpful.
To manually import <quiet-combobox>
from the CDN, use the following code.
import 'https://cdn.jsdelivr.net/npm/@quietui/quiet-browser@1.0.0/dist/components/combobox/combobox.js';
To manually import <quiet-combobox>
from npm, use the following code.
import '@quietui/quiet/dist/components/combobox/combobox.js';
Slots Jump to heading
Combobox supports the following slots. Learn more about using slots
Name | Description |
---|---|
(default) |
One or more <quiet-combobox-item> elements to show as options.
|
label
|
The combobox's label. For plain-text labels, use the label attribute instead.
|
description
|
The combobox's description. For plain-text descriptions, use the description attribute
instead.
|
start
|
An icon or similar element to place before the input. Works great with
<quiet-icon> .
|
end
|
An icon or similar element to place after the input. Works great with
<quiet-icon> .
|
Properties Jump to heading
Combobox has the following properties that can be set with corresponding attributes. In many cases, the attribute's name is the same as the property's name. If an attribute is different, it will be displayed after the property. Learn more about attributes and properties
Property / Attribute | Description | Reflects | Type | Default |
---|---|---|---|---|
label
|
The combobox's label. |
|
string
|
|
description
|
The combobox's description. |
|
string
|
|
name
|
The name of the combobox for form submission. |
|
string
|
|
value
|
The combobox's value(s). |
|
string
|
''
|
placeholder
|
Placeholder text for the input. |
|
string
|
|
disabled
|
Disables the combobox. |
|
boolean
|
false
|
required
|
Makes the combobox required. |
|
boolean
|
false
|
multiple
|
Enables multiple selection. |
|
boolean
|
false
|
withClear
with-clear
|
Adds a clear button when not blank. |
|
boolean
|
false
|
appearance
|
The visual appearance of the combobox. |
|
'normal'
|
'normal'
|
size
|
The size of the combobox. |
|
'xs'
|
'md'
|
pill
|
Draws the combobox in a pill shape. |
|
boolean
|
false
|
placement
|
The dropdown's placement relative to the input. |
|
'top'
|
'bottom-start'
|
distance
|
The distance of the dropdown from the input. |
|
number
|
0
|
offset
|
The offset of the dropdown along the input. |
|
number
|
0
|
form
|
The form to associate with. |
|
string
|
Methods Jump to heading
Combobox supports the following methods. You can obtain a reference to the element and call them like functions in JavaScript. Learn more about methods
Name | Description | Arguments |
---|---|---|
getTagContent() |
A custom function for rendering tag content. By default, this function returns the item's full
textContent . You can override it to customize the content that gets rendered in tags in
multiple mode.
|
item: QuietComboboxItem
|
focus() |
Sets focus to the combobox. | |
blur() |
Removes focus from the combobox. | |
checkValidity() |
Checks if the form control has any restraints and whether it satisfies them. If invalid,
false will be returned and the invalid event will be dispatched. If valid,
true will be returned.
|
|
reportValidity() |
Checks if the form control has any restraints and whether it satisfies them. If invalid,
false will be returned and the invalid event will be dispatched. In
addition, the problem will be reported to the user. If valid, true will be returned.
|
|
setCustomValidity() |
Sets a custom validation message for the form control. If this message is not an empty string, then the form control is considered invalid and the specified message will be displayed to the user when reporting validity. Setting an empty string clears the custom validity state. | message: string |
Events Jump to heading
Combobox dispatches the following custom events. You can listen to them the same way was native events. Learn more about custom events
Name | Description |
---|---|
quiet-blur |
Emitted when the combobox loses focus. |
quiet-change |
Emitted when the user commits changes to the combobox's value. |
quiet-focus |
Emitted when the combobox receives focus. |
quiet-input |
Emitted when the combobox receives input. |
quiet-before-open |
Emitted when the dropdown is instructed to open but before it is shown. |
quiet-open |
Emitted when the dropdown opens. |
quiet-before-close |
Emitted when the dropdown is instructed to close but before it is hidden. |
quiet-close |
Emitted when the dropdown closes. |
CSS custom properties Jump to heading
Combobox supports the following CSS custom properties. You can style them like any other CSS property. Learn more about CSS custom properties
Name | Description | Default |
---|---|---|
--text-box-min-width |
The minimum width of the input field when shown next to tags. Only available in
multiple mode.
|
12ch
|
--show-duration |
The duration of the show/hide animation for the dropdown. |
50ms
|
CSS parts Jump to heading
Combobox exposes internal elements that can be styled with CSS using the selectors shown below. Learn more about CSS parts
Name | Description | CSS selector |
---|---|---|
label |
The element that contains the combobox's label. |
::part(label)
|
description |
The element that contains the combobox's description. |
::part(description)
|
visual-box |
The element that wraps the internal text box. |
::part(visual-box)
|
input-area |
The wrapper surrounding tags and the internal text box. |
::part(input-area)
|
tag |
Individual tag elements. |
::part(tag)
|
tag-remove |
The remove button for tags. |
::part(tag-remove)
|
text-box |
The internal text box, an <input> element. |
::part(text-box)
|
chevron |
The chevron icon, a <quiet-icon> element. |
::part(chevron)
|
chevron__svg |
The chevron icon's <svg> part. |
::part(chevron__svg)
|
clear-button |
The clear button. |
::part(clear-button)
|
dropdown |
The dropdown container. |
::part(dropdown)
|
Custom States Jump to heading
Combobox has the following custom states. You can target them with CSS using the selectors shown below. Learn more about custom states
Name | Description | CSS selector |
---|---|---|
open |
Applied when the dropdown is open. |
:state(open)
|
disabled |
Applied when the combobox is disabled. |
:state(disabled)
|
focused |
Applied when the combobox has focus. |
:state(focused)
|
blank |
Applied when the combobox has no value. |
:state(blank)
|
user-valid |
Applied when valid after user interaction. |
:state(user-valid)
|
user-invalid |
Applied when invalid after user interaction. |
:state(user-invalid)
|
Dependencies Jump to heading
Combobox automatically imports the following elements. Sub-dependencies are also included in this list.