Skip to content

Commit 742ccfd

Browse files
thejacksheltonwmertens
authored andcommitted
feat(combobox): more feature parity with floating UI
1 parent 185ce42 commit 742ccfd

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

apps/website/src/routes/docs/headless/(components)/combobox/examples.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export const HeroExample = component$(() => {
9797
</ComboboxControl>
9898
<ComboboxPortal>
9999
<ComboboxListbox
100-
position="bottom"
101-
gap={8}
100+
placement="bottom"
101+
setOffset={8}
102102
class="text-white w-44 bg-[#1f2532] px-4 py-2 rounded-sm border-[#7d95b3] border-[1px]"
103103
/>
104104
</ComboboxPortal>

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,39 @@ import {
66
} from '@builder.io/qwik';
77
import {
88
ReferenceElement,
9+
arrow,
910
autoUpdate,
1011
computePosition,
1112
flip,
1213
offset,
14+
shift,
1315
} from '@floating-ui/dom';
1416
import ComboboxContextId from './combobox-context-id';
1517
import type { ComboboxContext, Option } from './combobox-context.type';
1618

19+
// type ArrowData = { element: HTMLElement; padding?: number | undefined };
20+
1721
export type ComboboxListboxProps = {
18-
shift?: {
22+
// come back to shift later
23+
arrowData?: { element: HTMLElement; padding?: number | undefined };
24+
setArrow?: boolean;
25+
setShift?: {
1926
mainAxis?: boolean;
2027
crossAxis?: boolean;
2128
limiter?: {
2229
fn: (state: unknown) => unknown;
2330
options?: unknown;
2431
};
2532
};
26-
gap?:
33+
setOffset?:
2734
| number
2835
| {
2936
mainAxis?: number;
3037
crossAxis?: number;
3138
alignmentAxis?: number | null;
3239
};
33-
toggleFlip?: boolean;
34-
position?:
40+
setFlip?: boolean;
41+
placement?:
3542
| 'top'
3643
| 'top-start'
3744
| 'top-end'
@@ -53,9 +60,12 @@ export type ComboboxListboxProps = {
5360

5461
export const ComboboxListbox = component$(
5562
<O extends Option = Option>({
56-
gap,
57-
toggleFlip = true,
58-
position = 'bottom',
63+
setOffset,
64+
setFlip = true,
65+
placement = 'bottom',
66+
setShift,
67+
setArrow,
68+
arrowData,
5969
ancestorScroll = true,
6070
ancestorResize = true,
6171
elementResize = true,
@@ -68,12 +78,18 @@ export const ComboboxListbox = component$(
6878
useVisibleTask$(function setListboxPosition({ cleanup }) {
6979
// Our settings from Floating UI
7080
function updatePosition() {
81+
const middleware = [offset(setOffset), setFlip && flip(), setShift && shift()];
82+
83+
if (setArrow && arrowData) {
84+
middleware.push(arrow(arrowData));
85+
}
86+
7187
computePosition(
7288
context.inputRef.value as ReferenceElement,
7389
context.listboxRef.value as HTMLElement,
7490
{
75-
placement: position,
76-
middleware: [offset(gap), toggleFlip && flip()],
91+
placement: placement,
92+
middleware: middleware,
7793
},
7894
).then(({ x, y }) => {
7995
if (context.listboxRef.value) {

0 commit comments

Comments
 (0)