Skip to content

Commit 007927e

Browse files
authored
Merge pull request #1980 from dxc-technology/Mil4n0r/tooltip-button
Added custom tooltip to `Button`
2 parents 87f0295 + ed97173 commit 007927e

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

packages/lib/src/button/Button.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ describe("Button component tests", () => {
2121

2222
const button = getByRole("button");
2323
expect(button.getAttribute("aria-label")).toBe("Go home");
24-
expect(button.getAttribute("title")).toBe("Go home");
2524
expect(button.getAttribute("tabindex")).toBe("1");
2625
});
2726
});

packages/lib/src/button/Button.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getMargin } from "../common/utils";
44
import useTheme from "../useTheme";
55
import ButtonPropsType from "./types";
66
import DxcIcon from "../icon/Icon";
7+
import DxcTooltip from "../tooltip/Tooltip";
78

89
const DxcButton = ({
910
label = "",
@@ -22,25 +23,26 @@ const DxcButton = ({
2223

2324
return (
2425
<ThemeProvider theme={colorsTheme.button}>
25-
<Button
26-
aria-label={title}
27-
disabled={disabled}
28-
onClick={() => {
29-
onClick();
30-
}}
31-
tabIndex={disabled ? -1 : tabIndex}
32-
title={title}
33-
type={type}
34-
$mode={mode !== "primary" && mode !== "secondary" && mode !== "text" ? "primary" : mode}
35-
hasLabel={label ? true : false}
36-
hasIcon={icon ? true : false}
37-
iconPosition={iconPosition}
38-
size={size}
39-
margin={margin}
40-
>
41-
{label && <LabelContainer>{label}</LabelContainer>}
42-
{icon && <IconContainer>{typeof icon === "string" ? <DxcIcon icon={icon} /> : icon}</IconContainer>}
43-
</Button>
26+
<DxcTooltip label={title}>
27+
<Button
28+
aria-label={title}
29+
disabled={disabled}
30+
onClick={() => {
31+
onClick();
32+
}}
33+
tabIndex={disabled ? -1 : tabIndex}
34+
type={type}
35+
$mode={mode !== "primary" && mode !== "secondary" && mode !== "text" ? "primary" : mode}
36+
hasLabel={label ? true : false}
37+
hasIcon={icon ? true : false}
38+
iconPosition={iconPosition}
39+
size={size}
40+
margin={margin}
41+
>
42+
{label && <LabelContainer>{label}</LabelContainer>}
43+
{icon && <IconContainer>{typeof icon === "string" ? <DxcIcon icon={icon} /> : icon}</IconContainer>}
44+
</Button>
45+
</DxcTooltip>
4446
</ThemeProvider>
4547
);
4648
};

0 commit comments

Comments
 (0)