Skip to main content

Listbox

Renders a list of options in an accessible way. A Listbox widget presents a list of options and allows a user to select one of them.

installversionusagestyle
yarn add @ciceksepeti/cui-listbox0.0.13import {Listbox, ListboxItem } from '@ciceksepeti/cui-listbox'import '@ciceksepeti/cui-listbox/style.css'

Content​

Renders list of elements. Listbox is a polymorphic component. That's why can be rendered as any valid HTML tag

Examples​

Default​

Prefix​

Example of a Listbox component with prefix. Renders as 'button' by default.

import React from 'react';
import { Listbox, ListboxItem } from '@ciceksepeti/cui-listbox';
import '@ciceksepeti/cui-listbox/styles.css';

export function Example() {
return (
<Listbox
name="listbox1"
prefix={<span style={{ marginRight: 5 }}>#</span>}
style={{
width: 200,
}}
as="button"
aria-labelledby="listbox2"
>
<ListboxItem value="item1">item 1</ListboxItem>
<ListboxItem value="item2">item 2</ListboxItem>
<ListboxItem value="item3">item 3</ListboxItem>
<ListboxItem value="item4">item 4</ListboxItem>
</Listbox>
);
}
PREVIEW
Listbox with Prefix

Example of a searchable Listbox component. Renders as 'button' by default.

import React, { useState } from 'react';
import { Listbox, ListboxItem } from '@ciceksepeti/cui-listbox';
import '@ciceksepeti/cui-listbox/styles.css';

export function Example() {
return (
<Listbox
as="button"
aria-labelledby="listbox3"
name="listbox3"
style={{
width: 200,
}}
>
<input
onChange={(e) => {
setSearch(e.target.value);
}}
placeholder="Search"
style={{
margin: '10px 0 10px 10px',
}}
type="text"
value={search}
/>
{items
.filter(({ label }) => label.includes(search))
.map(({ value, label }) => (
<ListboxItem key={value} value={value}>
{label}
</ListboxItem>
))}
</Listbox>
);
}
PREVIEW
Listbox with Search Input

Compound​

Listbox is a compound component. CactusUI provides ListboxButton, ListboxInput and ListboxPopover to user create own Listbox. Props and their required and default values of these subcomponents are described props section of the page.

Props​

Listbox Props​

Listbox Events​

Listbox Accessibility​

ListboxItem Props​

ListboxItem Events​

ListboxButton Props​

ListboxButton Events​

ListboxPopover Props​

Playground​

/img/codesandbox-icon

Styling​

Element Selectors​

Default Selector Values​