5.1.0 • Published 10 months ago
@spark-web/combobox v5.1.0
title: Combobox storybookPath: forms-combobox--default
isExperimentalPackage: true
The Combobox allows the user to browse, search, and make a single selection
from a large list of values.
Usage
Controlled component
const [value, setValue] = React.useState(null);
return (
<Field label="Who's your favourite Adventure Time character?">
<Combobox
placeholder="Select a character"
items={[
{ label: 'Jake', value: 'jake' },
{ label: 'Finn', value: 'finn' },
{ label: 'BMO', value: 'bmo' },
]}
onChange={value => setValue(value)}
value={value}
/>
</Field>
);Uncontrolled component
<Field label="Who's your favourite Adventure Time character?">
<Combobox
placeholder="Select a character"
items={[
{ label: 'Jake', value: 'jake' },
{ label: 'Finn', value: 'finn' },
{ label: 'BMO', value: 'bmo' },
]}
/>
</Field>Async
const [items, setItems] = React.useState([]);
const [value, setValue] = React.useState(null);
const fetchItems = async input => {
if (!input) return [];
await new Promise(resolve => setTimeout(resolve, 1000));
return [{ label: input, value: input }];
};
return (
<Field label="Search the interwebs">
<Combobox
placeholder="Start typing..."
items={items}
onChange={value => setValue(value)}
onInputChange={input => setItems(fetchItems(input))}
value={value}
/>
</Field>
);Custom label and value
const [value, setValue] = React.useState(null);
return (
<Field
label="What's your favourite movie?"
message={JSON.stringify(value ?? {})}
>
<Combobox
placeholder="Select a movie"
items={[
{ title: 'The Shawshank Redemption', year: 1994 },
{ title: 'The Godfather', year: 1972 },
{ title: 'The Godfather: Part II', year: 1974 },
{ title: 'The Dark Knight', year: 2008 },
{ title: '12 Angry Men', year: 1957 },
{ title: "Schindler's List", year: 1993 },
]}
onChange={value => setValue(value)}
value={value}
getOptionLabel={option => option.title}
getOptionValue={option => `${option.year}`}
/>
</Field>
);Grouped
<Field label="Who's your favourite character?">
<Combobox
placeholder="Select a character"
items={[
{
label: 'Futurama',
options: [
{ label: 'Fry', value: 'fry' },
{ label: 'Leela', value: 'leela' },
{ label: 'Bender', value: 'bender' },
{ label: 'Zoidberg', value: 'zoidberg' },
],
},
{
label: 'South Park',
options: [
{ label: 'Stan', value: 'stan' },
{ label: 'Kyle', value: 'kyle' },
{ label: 'Cartman', value: 'cartman' },
{ label: 'Kenny', value: 'kenny' },
],
},
]}
/>
</Field>With Default Option
<Field label="Who's your favourite Adventure Time character?">
<Combobox
placeholder="Select a character"
items={[
{ label: 'Jake', value: 'jake' },
{ label: 'Finn', value: 'finn' },
{ label: 'BMO', value: 'bmo' },
]}
defaultOption={{
option: { label: 'The Ice King', value: 'ice king' },
position: 'start',
}}
/>
</Field>Appearance
Disabled
<Field label="Who's your favourite Adventure Time character?" disabled>
<Combobox
placeholder="Select a character"
items={[
{ label: 'Jake', value: 'jake' },
{ label: 'Finn', value: 'finn' },
{ label: 'BMO', value: 'bmo' },
]}
/>
</Field>Invalid
<Field
label="Who's your favourite Adventure Time character?"
tone="critical"
message="Required"
>
<Combobox
placeholder="Select a character"
items={[
{ label: 'Jake', value: 'jake' },
{ label: 'Finn', value: 'finn' },
{ label: 'BMO', value: 'bmo' },
]}
/>
</Field>Props
5.1.0
10 months ago
3.0.0-rc.20
1 year ago
3.0.0-rc.21
1 year ago
5.0.6
12 months ago
5.0.5
1 year ago
5.0.4
1 year ago
5.0.3
1 year ago
5.0.2
1 year ago
5.0.1
1 year ago
5.0.0
1 year ago
6.0.0
1 year ago
5.0.0-rc.24
1 year ago
5.0.0-rc.25
1 year ago
5.0.0-rc.26
1 year ago
5.0.0-rc.27
1 year ago
5.0.0-rc.28
1 year ago
5.0.0-rc.29
1 year ago
6.0.0-rc.1
1 year ago
3.0.0-rc.13
1 year ago
3.0.0-rc.12
1 year ago
3.0.0-rc.15
1 year ago
3.0.0-rc.14
1 year ago
3.0.0-rc.17
1 year ago
3.0.0-rc.16
1 year ago
3.0.0-rc.19
1 year ago
5.0.0-rc.31
1 year ago
3.0.0-rc.18
1 year ago
3.0.0-rc.2
1 year ago
3.0.0-rc.1
1 year ago
3.0.0-rc.0
1 year ago
3.0.0-rc.6
1 year ago
3.0.0-rc.5
1 year ago
6.0.0-rc.3
1 year ago
3.0.0-rc.11
1 year ago
3.0.0-rc.4
1 year ago
6.0.0-rc.2
1 year ago
3.0.0-rc.10
1 year ago
3.0.0-rc.3
1 year ago
3.0.0-rc.9
1 year ago
3.0.0-rc.8
1 year ago
3.0.0-rc.7
1 year ago
2.0.0
2 years ago
1.6.0
3 years ago
1.5.0
3 years ago
1.4.4
3 years ago
1.4.3
4 years ago
1.4.2
4 years ago
1.4.1
4 years ago
1.3.2
4 years ago
1.4.0
4 years ago
1.3.1
4 years ago
1.3.0
4 years ago
1.2.0
4 years ago
1.1.0
4 years ago
1.0.0
4 years ago