Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core] fixed preact infinite loop in popover #2752

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/mantine-core/src/Popover/Popover.tsx
@@ -1,6 +1,6 @@
/* eslint-disable react/no-unused-prop-types */

import React, { useRef, useState } from 'react';
import React, { useRef, useState, useCallback } from 'react';
import { useId, useClickOutside } from '@mantine/hooks';
import {
useMantineTheme,
Expand Down Expand Up @@ -209,6 +209,22 @@ export function Popover(props: PopoverProps) {
dropdownNode,
]);

const reference = useCallback(
(node: HTMLElement) => {
setTargetNode(node);
popover.floating.reference(node);
},
[popover.floating.reference]
);

const floating = useCallback(
(node: HTMLElement) => {
setDropdownNode(node);
popover.floating.floating(node);
},
[popover.floating.floating]
);

return (
<StylesApiProvider
classNames={classNames}
Expand All @@ -221,14 +237,8 @@ export function Popover(props: PopoverProps) {
returnFocus,
disabled,
controlled: popover.controlled,
reference: (node) => {
setTargetNode(node as HTMLElement);
popover.floating.reference(node);
},
floating: (node) => {
setDropdownNode(node);
popover.floating.floating(node);
},
reference,
floating,
x: popover.floating.x,
y: popover.floating.y,
arrowX: popover.floating?.middlewareData?.arrow?.x,
Expand Down