Skip to content

Commit

Permalink
Merge pull request #1857 from adevinta/debug-dropdown-dialog
Browse files Browse the repository at this point in the history
fix(dropdown): prevent radix focus trap to disable scroll inside dropdown
  • Loading branch information
Powerplex authored Jan 30, 2024
2 parents 522d8cc + 73d2e49 commit 7e69308
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/components/dropdown/src/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const Controlled: StoryFn = () => {
}

export const ControlledOpenState: StoryFn = () => {
const [open, setOpen] = useState(true)
const [open, setOpen] = useState(false)

return (
<div className="flex flex-col gap-lg">
Expand Down
12 changes: 11 additions & 1 deletion packages/components/dropdown/src/DropdownItems.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMergeRefs } from '@spark-ui/use-merge-refs'
import { cx } from 'class-variance-authority'
import { forwardRef, ReactNode, type Ref } from 'react'
import { CSSProperties, forwardRef, ReactNode, type Ref } from 'react'

import { useDropdownContext } from './DropdownContext'

Expand Down Expand Up @@ -32,6 +32,16 @@ export const Items = forwardRef(
)}
{...props}
{...downshiftMenuProps}
/**
* When used inside a Radix dialog/drawer, the focus trap behaviour of Radix prevent scrolling and hovering inside absolutely positioned elements in the dialog.
* It does programatically in JS using the `style` attribute.
*
* Issue is known but there is no clear fix in sight: https://github.com/radix-ui/primitives/issues/1159
*
* A solution would be to make an abstraction of `Dialog.Overlay` instead of using the radix one, but that would mean managing body scroll freeze and scrollbar shifting ourselves.
*
*/
style={{ ...(props as { style: CSSProperties }).style, pointerEvents: undefined }}
data-spark-component="dropdown-items"
>
{children}
Expand Down

0 comments on commit 7e69308

Please sign in to comment.