fix: Button icons tooltips opening out of view due to padding issue (#11847)

Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2023-10-13 11:17:12 +00:00
1 parent 0a4f7da2df
commit 61be5c9bc1
2 files changed
+31 -5

No files matched your search

+21 -3
View File
@@ -23,6 +23,8 @@ export type ButtonBaseProps = {
shallow?: boolean;
/**Tool tip used when icon size is set to small */
tooltip?: string;
tooltipSide?: "top" | "right" | "bottom" | "left";
tooltipOffset?: number;
disabled?: boolean;
flex?: boolean;
} & Omit<InferredVariantProps, "color"> & {
@@ -123,6 +125,8 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
size,
variant = "button",
type = "button",
tooltipSide = "top",
tooltipOffset = 4,
StartIcon,
EndIcon,
shallow,
@@ -213,19 +217,33 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
{element}
</Link>
) : (
<Wrapper data-testid="wrapper" tooltip={props.tooltip}>
<Wrapper
data-testid="wrapper"
tooltip={props.tooltip}
tooltipSide={tooltipSide}
tooltipOffset={tooltipOffset}>
{element}
</Wrapper>
);
});
const Wrapper = ({ children, tooltip }: { tooltip?: string; children: React.ReactNode }) => {
const Wrapper = ({
children,
tooltip,
tooltipSide,
tooltipOffset,
}: {
tooltip?: string;
children: React.ReactNode;
tooltipSide?: "top" | "right" | "bottom" | "left";
tooltipOffset?: number;
}) => {
if (!tooltip) {
return <>{children}</>;
}
return (
<Tooltip data-testid="tooltip" content={tooltip}>
<Tooltip data-testid="tooltip" content={tooltip} side={tooltipSide} sideOffset={tooltipOffset}>
{children}
</Tooltip>
);