Skip to content

Commit

Permalink
fix(dropdown): apply pointer-event styles correctly when dropdown is …
Browse files Browse the repository at this point in the history
…open
  • Loading branch information
acd02 committed Apr 11, 2024
1 parent 1291e6c commit f450dbc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions 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 { CSSProperties, forwardRef, ReactNode, type Ref } from 'react'
import { forwardRef, ReactNode, type Ref, useLayoutEffect, useRef } from 'react'

import { useDropdownContext } from './DropdownContext'

Expand All @@ -19,7 +19,15 @@ export const Items = forwardRef(
},
})

const ref = useMergeRefs(forwardedRef, downshiftRef)
const innerRef = useRef<HTMLElement>(null)

const ref = useMergeRefs(forwardedRef, downshiftRef, innerRef)

useLayoutEffect(() => {
if (innerRef.current?.parentElement) {
innerRef.current.parentElement.style.pointerEvents = isOpen ? '' : 'none'
}
}, [isOpen, downshiftRef])

return (
<ul
Expand All @@ -41,7 +49,6 @@ export const Items = forwardRef(
* 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 f450dbc

Please sign in to comment.