Skip to content

Commit 6e104ef

Browse files
committed
fix: floating behavior of MultiComboBox options (#15373)
1 parent 5988bf5 commit 6e104ef

File tree

2 files changed

+213
-179
lines changed

2 files changed

+213
-179
lines changed

airbyte-webapp/src/components/ui/ComboBox/ComboBox.tsx

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { autoUpdate, useFloating } from "@floating-ui/react-dom";
12
import { Combobox, ComboboxButton, ComboboxInput, ComboboxOption, ComboboxOptions } from "@headlessui/react";
23
import classNames from "classnames";
34
import React, { ReactNode, useMemo, useState } from "react";
5+
import { createPortal } from "react-dom";
46
import { ControllerRenderProps, FieldValues } from "react-hook-form";
57
import { useIntl } from "react-intl";
68

@@ -301,20 +303,40 @@ export const MultiComboBox = ({
301303
error,
302304
fieldInputProps,
303305
disabled,
304-
}: MultiComboBoxProps) => (
305-
<Combobox value={value} onChange={onChange} multiple immediate>
306-
<ComboboxInput as={React.Fragment}>
307-
<TagInput
308-
name={name}
309-
fieldValue={value ?? []}
310-
onChange={onChange}
311-
onBlur={fieldInputProps?.onBlur}
312-
error={error}
313-
disabled={disabled}
314-
/>
315-
</ComboboxInput>
316-
<ComboboxOptions as="ul" className={styles.optionsMenu} modal={false}>
317-
<Options optionSections={normalizeOptionsAsSections(options)} />
318-
</ComboboxOptions>
319-
</Combobox>
320-
);
306+
}: MultiComboBoxProps) => {
307+
const { x, y, reference, floating, strategy } = useFloating({
308+
whileElementsMounted: autoUpdate,
309+
placement: "bottom-start",
310+
});
311+
312+
return (
313+
<Combobox ref={reference} as="div" value={value} onChange={onChange} multiple immediate>
314+
<ComboboxInput as={React.Fragment}>
315+
<TagInput
316+
name={name}
317+
fieldValue={value ?? []}
318+
onChange={onChange}
319+
onBlur={fieldInputProps?.onBlur}
320+
error={error}
321+
disabled={disabled}
322+
/>
323+
</ComboboxInput>
324+
{createPortal(
325+
<ComboboxOptions
326+
ref={floating}
327+
as="ul"
328+
className={styles.optionsMenu}
329+
modal={false}
330+
style={{
331+
position: strategy,
332+
top: y ?? 0,
333+
left: x ?? 0,
334+
}}
335+
>
336+
<Options optionSections={normalizeOptionsAsSections(options)} />
337+
</ComboboxOptions>,
338+
document.body
339+
)}
340+
</Combobox>
341+
);
342+
};

0 commit comments

Comments
 (0)