Skip to content

Commit

Permalink
chore(website): Fix usage of useTooltip when it is conditionally applied
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaursen committed Mar 9, 2022
1 parent 42d839d commit cfca184
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 19 deletions.
16 changes: 11 additions & 5 deletions packages/documentation/src/components/AppBarAction.tsx
Expand Up @@ -11,6 +11,7 @@ interface Props extends AppBarActionProps {
export default function AppBarAction({
id,
tooltip,
children,
onClick,
onBlur,
onFocus,
Expand All @@ -19,24 +20,29 @@ export default function AppBarAction({
onMouseLeave,
onTouchStart,
onContextMenu,
children,
...props
}: Props): ReactElement {
const { elementProps, tooltipProps } = useTooltip({
baseId: id,
const handlers = {
onClick,
onBlur,
onFocus,
onKeyDown,
onMouseEnter,
onMouseLeave,
onKeyDown,
onTouchStart,
onContextMenu,
};
const { elementProps, tooltipProps } = useTooltip({
baseId: id,
...handlers,
});

return (
<>
<RMDAppBarAction {...props} {...(tooltip ? elementProps : { id })}>
<RMDAppBarAction
{...props}
{...(tooltip ? elementProps : { id, ...handlers })}
>
{children}
</RMDAppBarAction>
<Tooltip {...tooltipProps}>{tooltip}</Tooltip>
Expand Down
16 changes: 11 additions & 5 deletions packages/documentation/src/components/AppBarNav.tsx
Expand Up @@ -11,6 +11,7 @@ interface Props extends AppBarNavProps {
export default function AppBarNav({
id,
tooltip,
children,
onClick,
onBlur,
onFocus,
Expand All @@ -19,24 +20,29 @@ export default function AppBarNav({
onMouseLeave,
onTouchStart,
onContextMenu,
children,
...props
}: Props): ReactElement {
const { elementProps, tooltipProps } = useTooltip({
baseId: id,
const handlers = {
onClick,
onBlur,
onFocus,
onKeyDown,
onMouseEnter,
onMouseLeave,
onKeyDown,
onTouchStart,
onContextMenu,
};
const { elementProps, tooltipProps } = useTooltip({
baseId: id,
...handlers,
});

return (
<>
<RMDAppBarNav {...props} {...(tooltip ? elementProps : { id })}>
<RMDAppBarNav
{...props}
{...(tooltip ? elementProps : { id, ...handlers })}
>
{children}
</RMDAppBarNav>
<Tooltip {...tooltipProps}>{tooltip}</Tooltip>
Expand Down
13 changes: 8 additions & 5 deletions packages/documentation/src/components/Button.tsx
Expand Up @@ -11,6 +11,7 @@ interface Props extends ButtonProps {
export default function Button({
id,
tooltip,
children,
onClick,
onBlur,
onFocus,
Expand All @@ -19,24 +20,26 @@ export default function Button({
onMouseLeave,
onTouchStart,
onContextMenu,
children,
...props
}: Props): ReactElement {
const { elementProps, tooltipProps } = useTooltip({
baseId: id,
const handlers = {
onClick,
onBlur,
onFocus,
onKeyDown,
onMouseEnter,
onMouseLeave,
onKeyDown,
onTouchStart,
onContextMenu,
};
const { elementProps, tooltipProps } = useTooltip({
baseId: id,
...handlers,
});

return (
<>
<RMDButton {...props} {...(tooltip ? elementProps : { id })}>
<RMDButton {...props} {...(tooltip ? elementProps : { id, ...handlers })}>
{children}
</RMDButton>
<Tooltip {...tooltipProps}>{tooltip}</Tooltip>
Expand Down
Expand Up @@ -31,8 +31,7 @@ export default forwardRef<HTMLButtonElement, TooltippedBadgedButtonProps>(
},
ref
) {
const { elementProps, tooltipProps } = useTooltip({
baseId: id,
const handlers = {
onClick,
onBlur,
onFocus,
Expand All @@ -41,13 +40,17 @@ export default forwardRef<HTMLButtonElement, TooltippedBadgedButtonProps>(
onKeyDown,
onTouchStart,
onContextMenu,
};
const { elementProps, tooltipProps } = useTooltip({
baseId: id,
...handlers,
});

return (
<>
<BadgedButton
{...props}
{...(tooltip ? elementProps : { id })}
{...(tooltip ? elementProps : { id, ...handlers })}
ref={ref}
>
{children}
Expand Down
Expand Up @@ -5,6 +5,9 @@ import { Tooltip, useTooltip } from "@react-md/tooltip";
export default function TooltipHookExample(): ReactElement {
const { tooltipProps, elementProps } = useTooltip({
baseId: "my-element-id",
onClick: (_event) => {
// if the button has a custom click event, it should be set here
},
});

return (
Expand Down
Expand Up @@ -11,7 +11,7 @@ interface TooltippedButtonProps
"defaultPosition" | "dense" | "position" | "focusTime" | "touchTime"
> {
id: string;
tooltip?: ReactNode;
tooltip: ReactNode;
}

export default function TooltippedButton({
Expand All @@ -24,6 +24,7 @@ export default function TooltippedButton({
onMouseEnter,
onMouseLeave,
onTouchStart,
onContextMenu,
children,
dense,
position,
Expand All @@ -42,6 +43,7 @@ export default function TooltippedButton({
onMouseEnter,
onMouseLeave,
onTouchStart,
onContextMenu,
position,
focusTime,
touchTime,
Expand Down

1 comment on commit cfca184

@vercel
Copy link

@vercel vercel bot commented on cfca184 Mar 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.