Skip to content

Commit 3659c02

Browse files
Merge pull request #722 from thejackshelton/multi-select
Initial multi-select capabilities
2 parents 2a34656 + 447ebe5 commit 3659c02

24 files changed

+328
-157
lines changed

apps/website/src/routes/docs/headless/select/examples/bind-open.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default component$(() => {
1717
return (
1818
<>
1919
<button onClick$={() => (isOpen.value = true)}>Toggle open state</button>
20-
<Select bind:open={isOpen} class="select" aria-label="hero">
20+
<Select bind:open={isOpen} class="select">
2121
<SelectTrigger class="select-trigger">
2222
<SelectValue placeholder="Select an option" />
2323
</SelectTrigger>

apps/website/src/routes/docs/headless/select/examples/controlled-value.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ export default component$(() => {
1515

1616
return (
1717
<>
18-
<Select
19-
onChange$={$((value: string) => {
20-
selected.value = value;
21-
})}
22-
bind:value={selected}
23-
class="select"
24-
>
18+
<Select bind:value={selected} class="select">
2519
<SelectTrigger class="select-trigger">
2620
<SelectValue placeholder="Select an option" />
2721
</SelectTrigger>

apps/website/src/routes/docs/headless/select/examples/form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default component$(() => {
1515

1616
return (
1717
<form preventdefault:submit>
18-
<Select required class="select" aria-label="hero">
18+
<Select required class="select">
1919
<SelectTrigger class="select-trigger">
2020
<SelectValue placeholder="Select an option" />
2121
</SelectTrigger>

apps/website/src/routes/docs/headless/select/examples/group.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Select,
44
SelectPopover,
55
SelectGroup,
6-
SelectLabel,
6+
SelectGroupLabel,
77
SelectListbox,
88
SelectOption,
99
SelectTrigger,
@@ -24,13 +24,13 @@ export default component$(() => {
2424
<SelectPopover class="select-popover">
2525
<SelectListbox class="select-listbox">
2626
<SelectGroup>
27-
<SelectLabel class="select-label">People</SelectLabel>
27+
<SelectGroupLabel class="select-label">People</SelectGroupLabel>
2828
{users.map((user) => (
2929
<SelectOption key={user}>{user}</SelectOption>
3030
))}
3131
</SelectGroup>
3232
<SelectGroup>
33-
<SelectLabel class="select-label">Animals</SelectLabel>
33+
<SelectGroupLabel class="select-group-label">Animals</SelectGroupLabel>
3434
{animals.map((animal) => (
3535
<SelectOption class="select-option" key={animal}>
3636
{animal}

apps/website/src/routes/docs/headless/select/examples/hero.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { component$, useStyles$ } from '@builder.io/qwik';
22
import {
33
Select,
4+
SelectLabel,
45
SelectListbox,
56
SelectOption,
67
SelectPopover,
@@ -14,7 +15,8 @@ export default component$(() => {
1415
const users = ['Tim', 'Ryan', 'Jim', 'Jessie', 'Abby'];
1516

1617
return (
17-
<Select class="select" aria-label="hero">
18+
<Select class="select">
19+
<SelectLabel>Logged in users</SelectLabel>
1820
<SelectTrigger class="select-trigger">
1921
<SelectValue placeholder="Select an option" />
2022
</SelectTrigger>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
2+
import {
3+
Select,
4+
SelectListbox,
5+
SelectOption,
6+
SelectPopover,
7+
SelectTrigger,
8+
SelectValue,
9+
} from '@qwik-ui/headless';
10+
import styles from '../snippets/select.css?inline';
11+
12+
export default component$(() => {
13+
useStyles$(styles);
14+
const users = ['Tim', 'Ryan', 'Jim', 'Jessie', 'Abby'];
15+
const selected = useSignal<string[]>([]);
16+
17+
return (
18+
<Select multiple bind:value={selected} class="select">
19+
<SelectTrigger class="select-trigger">
20+
<SelectValue>{selected.value}</SelectValue>
21+
</SelectTrigger>
22+
<SelectPopover class="select-popover">
23+
<SelectListbox class="select-listbox">
24+
{users.map((user) => (
25+
<SelectOption key={user}>{user}</SelectOption>
26+
))}
27+
</SelectListbox>
28+
</SelectPopover>
29+
</Select>
30+
);
31+
});

apps/website/src/routes/docs/headless/select/examples/scrollable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Select,
44
SelectPopover,
55
SelectGroup,
6-
SelectLabel,
6+
SelectGroupLabel,
77
SelectListbox,
88
SelectOption,
99
SelectTrigger,
@@ -24,15 +24,15 @@ export default component$(() => {
2424
<SelectPopover class="select-popover">
2525
<SelectListbox class="select-listbox select-max-height">
2626
<SelectGroup>
27-
<SelectLabel class="select-label">People</SelectLabel>
27+
<SelectGroupLabel class="select-label">People</SelectGroupLabel>
2828
{users.map((user) => (
2929
<SelectOption class="select-option" key={user}>
3030
{user}
3131
</SelectOption>
3232
))}
3333
</SelectGroup>
3434
<SelectGroup>
35-
<SelectLabel class="select-label">Animals</SelectLabel>
35+
<SelectGroupLabel class="select-label">Animals</SelectGroupLabel>
3636
{animals.map((animal) => (
3737
<SelectOption key={animal}>{animal}</SelectOption>
3838
))}

apps/website/src/routes/docs/headless/select/index.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ A common use case is the addition of options dynamically. For example, an infini
207207

208208
Clicking the `Add Users` button adds a couple new users mapped to the list. Taking this further, we could grab more data from the server and add it to the list, or even hitting a database to get more users.
209209

210+
### Multiple selections
211+
212+
<Showcase name="multiple" />
213+
214+
The `multiple` prop allows the user to select multiple options.
215+
210216
## Menu behavior
211217

212218
### Typeahead

apps/website/src/routes/docs/headless/select/snippets/building-blocks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
SelectPopover,
55
SelectTrigger,
66
SelectGroup,
7-
SelectLabel,
7+
SelectGroupLabel,
88
SelectValue,
99
SelectListbox,
1010
SelectOption,
@@ -22,7 +22,7 @@ export default component$(() => (
2222

2323
{/* optional */}
2424
<SelectGroup>
25-
<SelectLabel>group label</SelectLabel>
25+
<SelectGroupLabel>group label</SelectGroupLabel>
2626
<SelectOption>group option</SelectOption>
2727
</SelectGroup>
2828
</SelectListbox>

apps/website/src/routes/docs/headless/select/snippets/select.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
color: hsl(var(--foreground));
2929
}
3030

31-
.select-label {
31+
.select-group-label {
3232
font-size: 0.875rem;
3333
line-height: 1.25rem;
3434
color: hsla(var(--foreground) / 0.8);

0 commit comments

Comments
 (0)