Enhance Dropdown API to make portal usage optional (#6182)

Using a portal in dropdown systematically can be an issue in case we are
having dropdown within dropdown. The useClickOutside listener will be
triggered. It's easier to usePortal only in the case we really need
them, which is quite rare
This commit is contained in:
Charles Bochet
2024-07-09 18:13:42 +02:00
committed by GitHub
parent 28387003d2
commit 9683a19287
3 changed files with 15 additions and 2 deletions

View File

@ -1 +0,0 @@
export const COLUMN_HEAD_DROPDOWN_ID = 'table-head-options-dropdown-id';

View File

@ -28,6 +28,7 @@ export const RecordTableColumnHeadWithDropdown = ({
clickableComponent={<RecordTableColumnHead column={column} />}
dropdownComponents={<RecordTableColumnHeadDropdownMenu column={column} />}
dropdownOffset={{ x: -1 }}
usePortal
dropdownPlacement="bottom-start"
dropdownHotkeyScope={{ scope: column.fieldMetadataId + '-header' }}
/>

View File

@ -40,6 +40,7 @@ type DropdownProps = {
dropdownStrategy?: 'fixed' | 'absolute';
disableBlur?: boolean;
onClickOutside?: () => void;
usePortal?: boolean;
onClose?: () => void;
onOpen?: () => void;
};
@ -56,6 +57,7 @@ export const Dropdown = ({
dropdownStrategy = 'absolute',
dropdownOffset = { x: 0, y: 0 },
disableBlur = false,
usePortal = false,
onClickOutside,
onClose,
onOpen,
@ -131,7 +133,7 @@ export const Dropdown = ({
onHotkeyTriggered={handleHotkeyTriggered}
/>
)}
{isDropdownOpen && (
{isDropdownOpen && usePortal && (
<FloatingPortal>
<DropdownMenu
disableBlur={disableBlur}
@ -144,6 +146,17 @@ export const Dropdown = ({
</DropdownMenu>
</FloatingPortal>
)}
{isDropdownOpen && !usePortal && (
<DropdownMenu
disableBlur={disableBlur}
width={dropdownMenuWidth ?? dropdownWidth}
data-select-disable
ref={refs.setFloating}
style={floatingStyles}
>
{dropdownComponents}
</DropdownMenu>
)}
<DropdownOnToggleEffect
onDropdownClose={onClose}
onDropdownOpen={onOpen}