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