feat(Popover): make opened prop update internal opened state in realtime
This commit is contained in:
parent
c1289b63ea
commit
c52a8843e8
@ -26,14 +26,20 @@ interface PopoverProps extends AsChild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Popover = ({ children, opened, asChild }: PopoverProps) => {
|
const Popover = ({ children, opened, asChild }: PopoverProps) => {
|
||||||
const state = React.useState<IPopoverContext>({
|
const [state, setState] = React.useState<IPopoverContext>({
|
||||||
opened: opened ?? false,
|
opened: opened ?? false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (opened !== undefined) {
|
||||||
|
setState((p) => ({ ...p, opened: opened }));
|
||||||
|
}
|
||||||
|
}, [opened]);
|
||||||
|
|
||||||
const Comp = asChild ? Slot : "div";
|
const Comp = asChild ? Slot : "div";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PopoverContext.Provider value={state}>
|
<PopoverContext.Provider value={[state, setState]}>
|
||||||
<Comp className="relative">{children}</Comp>
|
<Comp className="relative">{children}</Comp>
|
||||||
</PopoverContext.Provider>
|
</PopoverContext.Provider>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user