Skip to content

Commit cfca184

Browse files
committed
chore(website): Fix usage of useTooltip when it is conditionally applied
1 parent 42d839d commit cfca184

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

packages/documentation/src/components/AppBarAction.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Props extends AppBarActionProps {
1111
export default function AppBarAction({
1212
id,
1313
tooltip,
14+
children,
1415
onClick,
1516
onBlur,
1617
onFocus,
@@ -19,24 +20,29 @@ export default function AppBarAction({
1920
onMouseLeave,
2021
onTouchStart,
2122
onContextMenu,
22-
children,
2323
...props
2424
}: Props): ReactElement {
25-
const { elementProps, tooltipProps } = useTooltip({
26-
baseId: id,
25+
const handlers = {
2726
onClick,
2827
onBlur,
2928
onFocus,
29+
onKeyDown,
3030
onMouseEnter,
3131
onMouseLeave,
32-
onKeyDown,
3332
onTouchStart,
3433
onContextMenu,
34+
};
35+
const { elementProps, tooltipProps } = useTooltip({
36+
baseId: id,
37+
...handlers,
3538
});
3639

3740
return (
3841
<>
39-
<RMDAppBarAction {...props} {...(tooltip ? elementProps : { id })}>
42+
<RMDAppBarAction
43+
{...props}
44+
{...(tooltip ? elementProps : { id, ...handlers })}
45+
>
4046
{children}
4147
</RMDAppBarAction>
4248
<Tooltip {...tooltipProps}>{tooltip}</Tooltip>

packages/documentation/src/components/AppBarNav.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Props extends AppBarNavProps {
1111
export default function AppBarNav({
1212
id,
1313
tooltip,
14+
children,
1415
onClick,
1516
onBlur,
1617
onFocus,
@@ -19,24 +20,29 @@ export default function AppBarNav({
1920
onMouseLeave,
2021
onTouchStart,
2122
onContextMenu,
22-
children,
2323
...props
2424
}: Props): ReactElement {
25-
const { elementProps, tooltipProps } = useTooltip({
26-
baseId: id,
25+
const handlers = {
2726
onClick,
2827
onBlur,
2928
onFocus,
29+
onKeyDown,
3030
onMouseEnter,
3131
onMouseLeave,
32-
onKeyDown,
3332
onTouchStart,
3433
onContextMenu,
34+
};
35+
const { elementProps, tooltipProps } = useTooltip({
36+
baseId: id,
37+
...handlers,
3538
});
3639

3740
return (
3841
<>
39-
<RMDAppBarNav {...props} {...(tooltip ? elementProps : { id })}>
42+
<RMDAppBarNav
43+
{...props}
44+
{...(tooltip ? elementProps : { id, ...handlers })}
45+
>
4046
{children}
4147
</RMDAppBarNav>
4248
<Tooltip {...tooltipProps}>{tooltip}</Tooltip>

packages/documentation/src/components/Button.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface Props extends ButtonProps {
1111
export default function Button({
1212
id,
1313
tooltip,
14+
children,
1415
onClick,
1516
onBlur,
1617
onFocus,
@@ -19,24 +20,26 @@ export default function Button({
1920
onMouseLeave,
2021
onTouchStart,
2122
onContextMenu,
22-
children,
2323
...props
2424
}: Props): ReactElement {
25-
const { elementProps, tooltipProps } = useTooltip({
26-
baseId: id,
25+
const handlers = {
2726
onClick,
2827
onBlur,
2928
onFocus,
29+
onKeyDown,
3030
onMouseEnter,
3131
onMouseLeave,
32-
onKeyDown,
3332
onTouchStart,
3433
onContextMenu,
34+
};
35+
const { elementProps, tooltipProps } = useTooltip({
36+
baseId: id,
37+
...handlers,
3538
});
3639

3740
return (
3841
<>
39-
<RMDButton {...props} {...(tooltip ? elementProps : { id })}>
42+
<RMDButton {...props} {...(tooltip ? elementProps : { id, ...handlers })}>
4043
{children}
4144
</RMDButton>
4245
<Tooltip {...tooltipProps}>{tooltip}</Tooltip>

packages/documentation/src/components/Demos/Badge/TooltippedBadgedButton.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ export default forwardRef<HTMLButtonElement, TooltippedBadgedButtonProps>(
3131
},
3232
ref
3333
) {
34-
const { elementProps, tooltipProps } = useTooltip({
35-
baseId: id,
34+
const handlers = {
3635
onClick,
3736
onBlur,
3837
onFocus,
@@ -41,13 +40,17 @@ export default forwardRef<HTMLButtonElement, TooltippedBadgedButtonProps>(
4140
onKeyDown,
4241
onTouchStart,
4342
onContextMenu,
43+
};
44+
const { elementProps, tooltipProps } = useTooltip({
45+
baseId: id,
46+
...handlers,
4447
});
4548

4649
return (
4750
<>
4851
<BadgedButton
4952
{...props}
50-
{...(tooltip ? elementProps : { id })}
53+
{...(tooltip ? elementProps : { id, ...handlers })}
5154
ref={ref}
5255
>
5356
{children}

packages/documentation/src/components/Demos/Tooltip/TooltipHookExample.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { Tooltip, useTooltip } from "@react-md/tooltip";
55
export default function TooltipHookExample(): ReactElement {
66
const { tooltipProps, elementProps } = useTooltip({
77
baseId: "my-element-id",
8+
onClick: (_event) => {
9+
// if the button has a custom click event, it should be set here
10+
},
811
});
912

1013
return (

packages/documentation/src/components/Demos/Tooltip/TooltippedButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface TooltippedButtonProps
1111
"defaultPosition" | "dense" | "position" | "focusTime" | "touchTime"
1212
> {
1313
id: string;
14-
tooltip?: ReactNode;
14+
tooltip: ReactNode;
1515
}
1616

1717
export default function TooltippedButton({
@@ -24,6 +24,7 @@ export default function TooltippedButton({
2424
onMouseEnter,
2525
onMouseLeave,
2626
onTouchStart,
27+
onContextMenu,
2728
children,
2829
dense,
2930
position,
@@ -42,6 +43,7 @@ export default function TooltippedButton({
4243
onMouseEnter,
4344
onMouseLeave,
4445
onTouchStart,
46+
onContextMenu,
4547
position,
4648
focusTime,
4749
touchTime,

0 commit comments

Comments
 (0)