Skip to content

Commit

Permalink
[@mantine/core] Tooltip: Allow usage with Popover.Target and other *.…
Browse files Browse the repository at this point in the history
…Target elements (#1897)
  • Loading branch information
rtivital committed Aug 12, 2022
1 parent f285b35 commit ebd695b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/mantine-core/src/Popover/Popover.story.tsx
Expand Up @@ -85,15 +85,15 @@ export function WithinGroup() {
export function PopoverTargetWithTooltip() {
return (
<div style={{ padding: 40 }}>
<Popover>
{/* <Popover>
<Tooltip label="Tooltip first">
<Popover.Target>
<Button>Tooltip first</Button>
</Popover.Target>
</Tooltip>
<Popover.Dropdown>Dropdown</Popover.Dropdown>
</Popover>
</Popover> */}

<Popover>
<Popover.Target>
Expand Down
10 changes: 5 additions & 5 deletions src/mantine-core/src/Tooltip/Tooltip.tsx
@@ -1,4 +1,4 @@
import React, { cloneElement } from 'react';
import React, { cloneElement, forwardRef } from 'react';
import { isElement } from '@mantine/utils';
import { useMergedRef } from '@mantine/hooks';
import { getDefaultZIndex, useComponentDefaultProps } from '@mantine/styles';
Expand Down Expand Up @@ -66,7 +66,7 @@ const defaultProps: Partial<TooltipProps> = {
positionDependencies: [],
};

export function Tooltip(props: TooltipProps) {
export const Tooltip = forwardRef<HTMLElement, TooltipProps>((props, ref) => {
const {
children,
position,
Expand Down Expand Up @@ -119,7 +119,7 @@ export function Tooltip(props: TooltipProps) {
throw new Error(TOOLTIP_ERRORS.children);
}

const targetRef = useMergedRef(tooltip.reference, (children as any).ref);
const targetRef = useMergedRef(tooltip.reference, (children as any).ref, ref);

return (
<>
Expand All @@ -131,7 +131,6 @@ export function Tooltip(props: TooltipProps) {
>
{(transitionStyles) => (
<Box
{...others}
{...tooltip.getFloatingProps({
ref: tooltip.floating,
className: classes.tooltip,
Expand Down Expand Up @@ -162,14 +161,15 @@ export function Tooltip(props: TooltipProps) {
{cloneElement(
children,
tooltip.getReferenceProps({
...others,
[refProp]: targetRef,
className: cx(className, children.props.className),
...children.props,
})
)}
</>
);
}
}) as any;

Tooltip.Group = TooltipGroup;
Tooltip.Floating = TooltipFloating;
Expand Down

0 comments on commit ebd695b

Please sign in to comment.