Skip to content

Commit

Permalink
fix(dropdown): conditional portal was moving the dropdown deep in the…
Browse files Browse the repository at this point in the history
… dom
  • Loading branch information
Powerplex committed Mar 22, 2024
1 parent 5ab4e12 commit d2ea405
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 24 additions & 22 deletions packages/components/dropdown/src/DropdownPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,32 @@ export const Popover = forwardRef(
return () => setHasPopover(false)
}, [])

return isOpen ? (
return (
<SparkPopover.Portal>
<SparkPopover.Content
ref={forwardedRef}
inset
asChild
matchTriggerWidth={matchTriggerWidth}
className={cx('!z-dropdown', className)}
sideOffset={sideOffset}
onOpenAutoFocus={e => {
/**
* With a combobox pattern, the focus should remain on the trigger at all times.
* Passing the focus to the dropdown popover would break keyboard navigation.
*/
e.preventDefault()
}}
{...props}
data-spark-component="dropdown-popover"
>
{children}
</SparkPopover.Content>
{isOpen ? (
<SparkPopover.Content
ref={forwardedRef}
inset
asChild
matchTriggerWidth={matchTriggerWidth}
className={cx('!z-dropdown', className)}
sideOffset={sideOffset}
onOpenAutoFocus={e => {
/**
* With a combobox pattern, the focus should remain on the trigger at all times.
* Passing the focus to the dropdown popover would break keyboard navigation.
*/
e.preventDefault()
}}
{...props}
data-spark-component="dropdown-popover"
>
{children}
</SparkPopover.Content>
) : (
children
)}
</SparkPopover.Portal>
) : (
children
)
}
)
Expand Down

0 comments on commit d2ea405

Please sign in to comment.