Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dropdown): prevent radix focus trap to disable scroll inside dropdown #1857

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading