From 5080856e0fea4f059ffce3d0717d2af61800a62c Mon Sep 17 00:00:00 2001 From: lerte smith Date: Tue, 12 Nov 2024 14:45:46 +0800 Subject: [PATCH] popover --- .../components/Autocomplete/Autocomplete.tsx | 2 ++ packages/actify/src/components/Menus/Menu.tsx | 2 +- .../actify/src/components/Popover/Popover.tsx | 25 ++++++++----------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/actify/src/components/Autocomplete/Autocomplete.tsx b/packages/actify/src/components/Autocomplete/Autocomplete.tsx index cc47544..a97da43 100644 --- a/packages/actify/src/components/Autocomplete/Autocomplete.tsx +++ b/packages/actify/src/components/Autocomplete/Autocomplete.tsx @@ -40,6 +40,7 @@ const Autocomplete = (props: AutocompleteProps) => { variant={props.variant} inputRef={inputRef} inputProps={inputProps} + onFocus={() => state.setOpen(true)} trailingIcon={ (props: AutocompleteProps) => { {state.isOpen && ( (props: MenuButtonProps) { )} {props?.activator?.(ref, menuTriggerProps)} {state.isOpen && ( - + { popoverRef?: React.RefObject } -const Popover = ({ - state, - children, - offset = 16, - referenceWidth, - popoverRef: propRef, - ...props -}: PopoverProps) => { - const popoverRef = - (propRef as React.RefObject) || React.useRef(null) - const { popoverProps, underlayProps, arrowProps, placement } = usePopover( +const Popover = ({ children, referenceWidth, ...props }: PopoverProps) => { + const _popoverRef = React.useRef(null) + const { popoverRef = _popoverRef, state } = props + + const { popoverProps, underlayProps } = usePopover( { ...props, - offset, popoverRef }, state ) + // make the width of the popover the same as the reference element popoverProps.style = { ...popoverProps.style, '--reference-width': referenceWidth + 'px' @@ -44,8 +38,11 @@ const Popover = ({ return (
-
- +
} + > {children}