feat(system): pass open state to children in ContextMenu
This commit is contained in:
parent
b662c253f3
commit
43ab8e6240
|
@ -1,4 +1,4 @@
|
|||
import React from 'react'
|
||||
import React, { cloneElement, useState } from 'react'
|
||||
|
||||
import * as Primitive from '@radix-ui/react-context-menu'
|
||||
|
||||
|
@ -18,12 +18,14 @@ interface TriggerProps extends ContextMenuTriggerProps {
|
|||
const ContextMenuTrigger = (props: TriggerProps) => {
|
||||
const { children, ...triggerProps } = props
|
||||
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const [trigger, menu] = children
|
||||
|
||||
return (
|
||||
<Primitive.Root>
|
||||
<Primitive.Root onOpenChange={setOpen}>
|
||||
<Primitive.Trigger {...triggerProps} asChild>
|
||||
{trigger}
|
||||
{cloneElement(trigger, { 'data-open': open })}
|
||||
</Primitive.Trigger>
|
||||
{menu}
|
||||
</Primitive.Root>
|
||||
|
|
Loading…
Reference in New Issue