Skip to content

Commit

Permalink
feat(Popover): update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Orliak committed Dec 10, 2024
1 parent bccab4b commit cfed611
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 356 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ describe('Popover', () => {
expect(spanContent).toBeInTheDocument();

expect(popoverContent).toHaveAttribute('data-popover-placement', 'bottom');
expect(popoverContent).toMatchSnapshot();
});
});
20 changes: 11 additions & 9 deletions packages/react-magma-dom/src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export enum PopoverPositioning {
right = 'right',
}

export interface PopoverProps {
export interface PopoverProps extends React.HTMLAttributes<HTMLDivElement> {
onClose?: (event: React.SyntheticEvent) => void;
onOpen?: () => void;
testId?: string;
Expand Down Expand Up @@ -81,13 +81,6 @@ export const Popover = React.forwardRef<HTMLDivElement, PopoverProps>(
const popoverContentId = React.useRef<string>('');
const popoverTriggerId = React.useRef<string>('');

const idPrefix = useGenerateId();

popoverTriggerId.current = `${idPrefix}_trigger`;
popoverContentId.current = `${idPrefix}_content`;

const ref = useForkedRef(forwardedRef, ownRef);

const {
onClose,
onOpen,
Expand All @@ -102,14 +95,22 @@ export const Popover = React.forwardRef<HTMLDivElement, PopoverProps>(
matchedWidth,
withoutPointer,
openByDefault,
id: defaultId,
...other
} = props;

const popoverId = useGenerateId(defaultId);

popoverTriggerId.current = `${popoverId}_trigger`;
popoverContentId.current = `${popoverId}_content`;

const ref = useForkedRef(forwardedRef, ownRef);

React.useEffect(() => {
if (openByDefault) {
openPopover();
}
}, [openByDefault]) // Do I need this?
}, [openByDefault]); // Do I need this?

const maxHeightString =
typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight;
Expand Down Expand Up @@ -215,6 +216,7 @@ export const Popover = React.forwardRef<HTMLDivElement, PopoverProps>(
onMouseOver={handleMouseOver}
onMouseLeave={handleMouseLeave}
onFocus={onFocus}
id={popoverId}
>
{children}
</Container>
Expand Down
Loading

0 comments on commit cfed611

Please sign in to comment.