Skip to content

Commit

Permalink
Enhance Dropdown API to make portal usage optional (#6182)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
charlesBochet authored Jul 9, 2024
1 parent 2838700 commit 9683a19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type DropdownProps = {
dropdownStrategy?: 'fixed' | 'absolute';
disableBlur?: boolean;
onClickOutside?: () => void;
usePortal?: boolean;
onClose?: () => void;
onOpen?: () => void;
};
Expand All @@ -56,6 +57,7 @@ export const Dropdown = ({
dropdownStrategy = 'absolute',
dropdownOffset = { x: 0, y: 0 },
disableBlur = false,
usePortal = false,
onClickOutside,
onClose,
onOpen,
Expand Down Expand Up @@ -131,7 +133,7 @@ export const Dropdown = ({
onHotkeyTriggered={handleHotkeyTriggered}
/>
)}
{isDropdownOpen && (
{isDropdownOpen && usePortal && (
<FloatingPortal>
<DropdownMenu
disableBlur={disableBlur}
Expand All @@ -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}
Expand Down

0 comments on commit 9683a19

Please sign in to comment.