Skip to content

Commit d87b692

Browse files
feat(combobox): new selectedIndex bind, minor bug fixes
1 parent 360a211 commit d87b692

File tree

12 files changed

+48
-33
lines changed

12 files changed

+48
-33
lines changed

.changeset/honest-timers-dream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik-ui/headless': patch
3+
---
4+
5+
bind syntax Sig suffix removed, new bind:selectedIndex prop, bug fixes

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default component$(() => {
5454
<ComboboxIcon class="stroke-white transition-transform duration-[450ms] group-aria-expanded:-rotate-180" />
5555
</ComboboxTrigger>
5656
</ComboboxControl>
57-
<ComboboxPopover gutter={8}>
57+
<ComboboxPopover class="rounded-sm" gutter={8}>
5858
<ComboboxListbox
5959
class="rounded-sm border-[1px] border-slate-400 bg-slate-900 px-4 py-2"
6060
optionRenderer$={(option: ResolvedOption, index: number) => {
@@ -67,7 +67,7 @@ export default component$(() => {
6767
class="aria-disabled:text-muted-foreground data-[highlighted]:border-border group flex justify-between gap-4 rounded-sm border border-transparent px-2 text-white aria-disabled:font-light aria-disabled:hover:border-slate-500 data-[highlighted]:cursor-pointer data-[highlighted]:bg-slate-800"
6868
>
6969
<span>{myData.testLabel}</span>
70-
<span>{selectedOptionIndexSig.value === index ? 'Selected' : ''} </span>
70+
{selectedOptionIndexSig.value === index && <span>Selected</span>}
7171
</ComboboxOption>
7272
);
7373
}}

apps/website/src/routes/docs/headless/combobox/examples/highlighted-index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default component$(() => {
2828
<Combobox
2929
class="w-fit"
3030
options={highlightedExample}
31-
bind:highlightedIndexSig={highlightedIndexSig}
31+
bind:highlightedIndex={highlightedIndexSig}
3232
>
3333
<ComboboxControl class="relative flex items-center rounded-sm border">
3434
<ComboboxInput class="px-d2 bg-background placeholder:text-muted-foreground w-fit rounded-sm px-2 pr-6" />

apps/website/src/routes/docs/headless/combobox/examples/placement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default component$(() => {
3333
class="w-fit"
3434
options={placementExample}
3535
optionDisabledKey="myDisabledKey"
36-
bind:inputValueSig={inputValueSig}
36+
bind:inputValue={inputValueSig}
3737
>
3838
<ComboboxLabel>Positions</ComboboxLabel>
3939
<ComboboxControl class="relative mt-2 flex items-center rounded-sm border">

apps/website/src/routes/docs/headless/combobox/examples/search-bar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export default component$(() => {
3838

3939
return (
4040
<Combobox
41-
bind:inputValueSig={inputValueSig}
42-
bind:highlightedIndexSig={highlightedIndexSig}
43-
bind:isListboxOpenSig={isListboxOpenSig}
41+
bind:inputValue={inputValueSig}
42+
bind:highlightedIndex={highlightedIndexSig}
43+
bind:isListboxOpen={isListboxOpenSig}
4444
optionValueKey="component"
4545
class="w-fit"
4646
options={components}

apps/website/src/routes/docs/headless/combobox/examples/shift.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default component$(() => {
2626
<Combobox
2727
class="w-fit"
2828
options={shiftExample}
29-
bind:isListboxOpenSig={isListboxOpenSig}
29+
bind:isListboxOpen={isListboxOpenSig}
3030
>
3131
<ComboboxLabel class=" font-semibold">Fruits 🍓</ComboboxLabel>
3232
<ComboboxControl class="relative flex items-center rounded-sm border">

apps/website/src/routes/docs/headless/combobox/examples/signal-binds.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export default component$(() => {
3030
<Combobox
3131
class="w-fit"
3232
options={signalsExample}
33-
bind:isListboxOpenSig={isListboxOpenSig}
34-
bind:highlightedIndexSig={highlightedIndexSig}
33+
bind:isListboxOpen={isListboxOpenSig}
34+
bind:highlightedIndex={highlightedIndexSig}
3535
>
3636
<ComboboxControl class="relative flex items-center rounded-sm border">
3737
<ComboboxInput

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Qwik UI's Combobox implementation follows the [WAI-Aria Combobox specifications]
7070
description: `A button that toggles the corresponding listbox when clicked.`,
7171
},
7272
{
73-
name: 'ComboboxPortal',
74-
description: `A portal component that teleports the children outside its parent when the listbox state is open.`,
73+
name: 'ComboboxPopover',
74+
description: `A Popover component that teleports the children outside its parent when the listbox state is open.`,
7575
},
7676
{
7777
name: 'ComboboxListbox',
@@ -170,29 +170,34 @@ To disable this behavior, set `disableOnBlur={true}` on the Input.
170170

171171
The Combobox component allows you to customize its state signals. This can be useful if you want to control or observe these states externally.
172172

173-
This involves creating a signal and passing it in using the [bind syntax](https://qwik.builder.io/docs/components/rendering/#bind-attribute), such as in the Qwik docs.
173+
In reality it is a signal prop, we prefer using this syntax, because we believe it is familiar to Qwik developers with the [bind syntax](https://qwik.builder.io/docs/components/rendering/#bind-attribute).
174174

175175
<APITable
176176
propDescriptors={[
177177
{
178-
name: 'bind:isListboxOpenSig',
178+
name: 'bind:inputValue',
179179
type: 'Signal',
180-
description: 'Controls the open state of the listbox.',
180+
description: 'Controls the current value of the input.',
181181
},
182182
{
183-
name: 'bind:isInputFocusedSig',
183+
name: 'bind:selectedIndex',
184184
type: 'Signal',
185-
description: 'Controls the focus state of the input.',
185+
description: 'Controls the selected option index.',
186186
},
187187
{
188-
name: 'bind:highlightedIndexSig',
188+
name: 'bind:isListboxOpen',
189189
type: 'Signal',
190-
description: 'Controls which option is highlighted.',
190+
description: 'Controls the open state of the listbox.',
191191
},
192192
{
193-
name: 'bind:inputValueSig',
193+
name: 'bind:isInputFocused',
194194
type: 'Signal',
195-
description: 'Controls the current value of the input.',
195+
description: 'Controls the focus state of the input.',
196+
},
197+
{
198+
name: 'bind:highlightedIndex',
199+
type: 'Signal',
200+
description: 'Controls which option is highlighted.',
196201
},
197202
]}
198203
/>
@@ -298,22 +303,27 @@ The Combobox component API provides a set of properties that allow you to custom
298303
description: 'The default label for the combobox.',
299304
},
300305
{
301-
name: 'bind:isListboxOpenSig',
306+
name: 'bind:selectedIndex',
307+
type: `Signal<number>`,
308+
description: 'A signal for the selected option index.',
309+
},
310+
{
311+
name: 'bind:isListboxOpen',
302312
type: `Signal<boolean>`,
303313
description: 'A signal for the open state of the listbox.',
304314
},
305315
{
306-
name: 'bind:isInputFocusedSig',
316+
name: 'bind:isInputFocused',
307317
type: 'Signal<boolean>',
308318
description: 'A signal for the focus state of the input.',
309319
},
310320
{
311-
name: 'bind:inputValueSig',
321+
name: 'bind:inputValue',
312322
type: 'Signal<string>',
313323
description: 'A signal for the current value of the input.',
314324
},
315325
{
316-
name: 'bind:highlightedIndexSig',
326+
name: 'bind:highlightedIndex',
317327
type: 'Signal<number>',
318328
description: 'A signal for the highlighted option index.',
319329
},

packages/kit-headless/src/components/combobox/combobox-context.type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface ComboboxContext<O extends Option = Option> {
2121
isInputFocusedSig: Signal<boolean | undefined>;
2222
isListboxOpenSig: Signal<boolean | undefined>;
2323
highlightedIndexSig: Signal<number>;
24-
selectedOptionIndexSig: Signal<number>;
24+
selectedIndexSig: Signal<number>;
2525

2626
// option settings
2727
optionValueKey: string;

packages/kit-headless/src/components/combobox/combobox-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const ComboboxInput = component$(
7272

7373
if (e.key === 'Enter') {
7474
context.isListboxOpenSig.value = false;
75-
context.selectedOptionIndexSig.value = context.highlightedIndexSig.value;
75+
context.selectedIndexSig.value = context.highlightedIndexSig.value;
7676

7777
// if they somehow manage to highlight a disabled option (bug)
7878
if (

0 commit comments

Comments
 (0)