Skip to content

Commit 068a224

Browse files
authored
Merge pull request #1978 from dxc-technology/Mil4n0r/tooltip-actionicon
Added custom tooltip to `ActionIcon`
2 parents c723cf5 + 906fe61 commit 068a224

File tree

12 files changed

+35
-62
lines changed

12 files changed

+35
-62
lines changed

apps/website/screens/components/resultset-table/code/examples/paginatorHidden.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const code = `() => {
1111
const actions = [
1212
{
1313
icon: "filled_delete",
14-
title: "icon",
14+
title: "Delete",
1515
onClick: () => {},
1616
},
1717
{

apps/website/screens/components/resultset-table/code/examples/reduced.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const code = `() => {
1111
const actions = [
1212
{
1313
icon: "delete",
14-
title: "icon",
14+
title: "Delete",
1515
onClick: () => {},
1616
},
1717
{

apps/website/screens/components/table/code/examples/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const code = `() => {
44
const actions = [
55
{
66
icon: "delete",
7-
title: "icon",
7+
title: "Delete",
88
onClick: () => {},
99
},
1010
{

packages/lib/src/action-icon/ActionIcon.test.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,18 @@ const iconSVG = (
88
</svg>
99
);
1010
describe("Action icon component tests", () => {
11-
test("Action icon renders with correct text", () => {
12-
const { getByTitle } = render(<DxcActionIcon icon={iconSVG} title="favourite" />);
13-
expect(getByTitle("favourite")).toBeTruthy();
14-
});
15-
1611
test("Calls correct function on click", () => {
1712
const onClick = jest.fn();
18-
const { getByTitle } = render(<DxcActionIcon icon={iconSVG} title="favourite" onClick={onClick} />);
19-
const action = getByTitle("favourite");
13+
const { getByRole } = render(<DxcActionIcon icon={iconSVG} title="favourite" onClick={onClick} />);
14+
const action = getByRole("button");
2015
fireEvent.click(action);
2116
expect(onClick).toHaveBeenCalled();
2217
});
2318

2419
test("On click is not called when disabled", () => {
2520
const onClick = jest.fn();
26-
const { getByTitle } = render(<DxcActionIcon disabled icon={iconSVG} title="favourite" onClick={onClick} />);
27-
const action = getByTitle("favourite");
21+
const { getByRole } = render(<DxcActionIcon disabled icon={iconSVG} title="favourite" onClick={onClick} />);
22+
const action = getByRole("button");
2823
fireEvent.click(action);
2924
expect(onClick).toHaveBeenCalledTimes(0);
3025
});
@@ -34,7 +29,6 @@ describe("Action icon component tests", () => {
3429

3530
const button = getByRole("button");
3631
expect(button.getAttribute("aria-label")).toBe("favourite");
37-
expect(button.getAttribute("title")).toBe("favourite");
3832
expect(button.getAttribute("tabindex")).toBe("1");
3933
});
4034
});

packages/lib/src/action-icon/ActionIcon.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@ import ActionIconPropsTypes, { RefType } from "./types";
33
import styled from "styled-components";
44
import CoreTokens from "../common/coreTokens";
55
import DxcIcon from "../icon/Icon";
6+
import DxcTooltip from "../tooltip/Tooltip";
67

78
const DxcActionIcon = forwardRef<RefType, ActionIconPropsTypes>(
8-
({ disabled = false, title, icon, onClick, tabIndex }, ref): JSX.Element => (
9-
<ActionIcon
10-
aria-label={title}
11-
disabled={disabled}
12-
onClick={onClick}
13-
onMouseDown={(event) => {
14-
event.stopPropagation();
15-
}}
16-
tabIndex={tabIndex}
17-
title={title}
18-
type="button"
19-
ref={ref}
20-
>
21-
{typeof icon === "string" ? <DxcIcon icon={icon} /> : icon}
22-
</ActionIcon>
23-
)
9+
({ disabled = false, title, icon, onClick, tabIndex }, ref): JSX.Element => {
10+
return (
11+
<DxcTooltip label={title}>
12+
<ActionIcon
13+
aria-label={title}
14+
disabled={disabled}
15+
onClick={onClick}
16+
onMouseDown={(event) => {
17+
event.stopPropagation();
18+
}}
19+
tabIndex={tabIndex}
20+
type="button"
21+
ref={ref}
22+
>
23+
{typeof icon === "string" ? <DxcIcon icon={icon} /> : icon}
24+
</ActionIcon>
25+
</DxcTooltip>
26+
);
27+
}
2428
);
2529

2630
const ActionIcon = styled.button`

packages/lib/src/date-input/DateInput.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ const DatePickerButtonStates = () => {
230230
export const DatePickerStates = DatePickerButtonStates.bind({});
231231
DatePickerStates.play = async ({ canvasElement }) => {
232232
const canvas = within(canvasElement);
233-
const dateBtn = canvas.getAllByTitle("Select date")[0];
233+
const dateBtn = canvas.getAllByRole("combobox")[0];
234234
await userEvent.click(dateBtn);
235235
};
236236

packages/lib/src/date-input/DateInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const DxcDateInput = forwardRef<RefType, DateInputPropsType>(
174174

175175
useEffect(() => {
176176
if (!disabled) {
177-
const actionButtonRef = dateRef?.current.querySelector("[title='Select date']");
177+
const actionButtonRef = dateRef?.current.querySelector("[aria-label='Select date']");
178178
actionButtonRef?.setAttribute("aria-haspopup", true);
179179
actionButtonRef?.setAttribute("role", "combobox");
180180
actionButtonRef?.setAttribute("aria-expanded", isOpen);

packages/lib/src/number-input/NumberInput.test.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ describe("Number input component tests", () => {
2525
expect(queryAllByRole("button").length).toBe(2);
2626
});
2727

28-
test("Number input buttons' tooltip is correct", () => {
29-
const { getByTitle } = render(<DxcNumberInput label="Number label" />);
30-
expect(getByTitle("Decrement value")).toBeTruthy();
31-
expect(getByTitle("Increment value")).toBeTruthy();
32-
});
33-
3428
test("Number input is disabled", () => {
3529
const { getByLabelText } = render(<DxcNumberInput label="Number label" disabled />);
3630
const number = getByLabelText("Number label") as HTMLInputElement;

packages/lib/src/password-input/PasswordInput.test.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,6 @@ describe("Password input component tests", () => {
7474
expect(passwordInput.type).toBe("text");
7575
});
7676

77-
test("Password tooltip is correct", async () => {
78-
const { getAllByRole, getByTitle, queryByTitle } = render(
79-
<DxcPasswordInput label="Password input" clearable value="Password" />
80-
);
81-
const showButton = getAllByRole("button")[1];
82-
userEvent.hover(showButton);
83-
expect(getByTitle("Show password")).toBeTruthy();
84-
userEvent.unhover(showButton);
85-
expect(queryByTitle("Hide password")).toBeFalsy();
86-
});
87-
8877
test("Password input has correct accessibility attributes", async () => {
8978
const { getByRole, getByLabelText } = render(<DxcPasswordInput label="Password input" />);
9079
const showButton = getByRole("button");

packages/lib/src/status-light/StatusLight.test.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ describe("StatusLight component tests", () => {
88
});
99

1010
test("StatusLight applies accessibility attributes", () => {
11-
const { getByTestId } = render(<DxcStatusLight label="Status Light Test" />);
12-
const statusLightContainer = getByTestId("status_light-container");
13-
const statusDot = getByTestId("status-dot");
11+
const { getByRole } = render(<DxcStatusLight label="Status Light Test" />);
12+
const statusLightContainer = getByRole("status");
1413
expect(statusLightContainer.getAttribute("aria-label")).toBe("default: Status Light Test");
15-
expect(statusDot.getAttribute("aria-hidden")).toBe("true");
1614
});
1715
});

0 commit comments

Comments
 (0)