Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 29b79ef

Browse files
authored
Fix TAC opening with keyboard (#12285)
* Fix TAC opening with keyboard * Use compound tooltip and icon button * Revert "Fix TAC opening with keyboard" This reverts commit 5a1e5d0 * Add missing aria-label * Update tests * Add tests * Fix visual regression * Fix remaining tooltip * Fix ref typing * Fix typing
1 parent 5bd0afc commit 29b79ef

File tree

4 files changed

+65
-38
lines changed

4 files changed

+65
-38
lines changed

res/css/structures/_ThreadsActivityCentre.pcss

+17-8
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@
1717
*/
1818

1919
.mx_ThreadsActivityCentreButton {
20-
color: $secondary-content;
21-
height: 32px;
22-
min-width: 32px;
23-
display: flex;
24-
align-items: center;
25-
justify-content: center;
2620
border-radius: 8px;
2721
margin: 18px auto auto auto;
2822

2923
&.expanded {
3024
/* align with settings icon */
31-
margin-left: 25px;
25+
margin-left: 21px;
3226

33-
& > .mx_ThreadsActivityCentreButton_IndicatorIcon {
27+
/**
28+
* modify internal css of the compound component
29+
* dirty but we need to add the `Threads` label into the indicator icon button
30+
**/
31+
& > div {
32+
display: flex;
33+
align-items: center;
34+
}
35+
36+
& .mx_ThreadsActivityCentreButton_Icon {
3437
/* align with settings label */
3538
margin-right: 14px;
39+
/* required to set the icon width when into a flex container */
40+
min-width: 24px;
41+
}
42+
43+
& .mx_ThreadsActivityCentreButton_Text {
44+
color: $secondary-content;
3645
}
3746
}
3847

src/components/views/spaces/threads-activity-centre/ThreadsActivityCentreButton.tsx

+29-22
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
* /
1717
*/
1818

19-
import React, { forwardRef, HTMLProps } from "react";
19+
import React, { ComponentProps, forwardRef } from "react";
2020
import { Icon } from "@vector-im/compound-design-tokens/icons/threads-solid.svg";
2121
import classNames from "classnames";
22-
import { IndicatorIcon } from "@vector-im/compound-web";
22+
import { IconButton, Text, Tooltip } from "@vector-im/compound-web";
2323

2424
import { _t } from "../../../../languageHandler";
25-
import AccessibleTooltipButton from "../../elements/AccessibleTooltipButton";
2625
import { NotificationLevel } from "../../../../stores/notifications/NotificationLevel";
2726
import { notificationLevelToIndicator } from "../../../../utils/notifications";
2827

29-
interface ThreadsActivityCentreButtonProps extends HTMLProps<HTMLDivElement> {
28+
interface ThreadsActivityCentreButtonProps extends ComponentProps<typeof IconButton> {
3029
/**
3130
* Display the `Treads` label next to the icon.
3231
*/
@@ -40,28 +39,36 @@ interface ThreadsActivityCentreButtonProps extends HTMLProps<HTMLDivElement> {
4039
/**
4140
* A button to open the thread activity centre.
4241
*/
43-
export const ThreadsActivityCentreButton = forwardRef<HTMLDivElement, ThreadsActivityCentreButtonProps>(
42+
export const ThreadsActivityCentreButton = forwardRef<HTMLButtonElement, ThreadsActivityCentreButtonProps>(
4443
function ThreadsActivityCentreButton({ displayLabel, notificationLevel, ...props }, ref): React.JSX.Element {
44+
// Disable tooltip when the label is displayed
45+
const openTooltip = displayLabel ? false : undefined;
46+
4547
return (
46-
<AccessibleTooltipButton
47-
className={classNames("mx_ThreadsActivityCentreButton", { expanded: displayLabel })}
48-
title={_t("common|threads")}
49-
// @ts-ignore
50-
// ref nightmare...
51-
ref={ref}
52-
forceHide={displayLabel}
53-
aria-expanded={displayLabel}
54-
{...props}
55-
>
56-
<IndicatorIcon
57-
className="mx_ThreadsActivityCentreButton_IndicatorIcon"
48+
<Tooltip label={_t("common|threads")} side="right" open={openTooltip}>
49+
<IconButton
50+
aria-label={_t("common|threads")}
51+
className={classNames("mx_ThreadsActivityCentreButton", { expanded: displayLabel })}
5852
indicator={notificationLevelToIndicator(notificationLevel)}
59-
size="24px"
53+
{...props}
54+
ref={ref}
6055
>
61-
<Icon className="mx_ThreadsActivityCentreButton_Icon" />
62-
</IndicatorIcon>
63-
{displayLabel && _t("common|threads")}
64-
</AccessibleTooltipButton>
56+
<>
57+
<Icon className="mx_ThreadsActivityCentreButton_Icon" />
58+
{/* This is dirty, but we need to add the label to the indicator icon */}
59+
{displayLabel && (
60+
<Text
61+
className="mx_ThreadsActivityCentreButton_Text"
62+
as="span"
63+
size="md"
64+
title={_t("common|threads")}
65+
>
66+
{_t("common|threads")}
67+
</Text>
68+
)}
69+
</>
70+
</IconButton>
71+
</Tooltip>
6572
);
6673
},
6774
);

test/components/views/spaces/ThreadsActivityCentre-test.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
* /
1717
*/
1818

19-
import React from "react";
19+
import React, { ComponentProps } from "react";
2020
import { getByText, render, screen } from "@testing-library/react";
2121
import userEvent from "@testing-library/user-event";
2222
import { NotificationCountType, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix";
23+
import { TooltipProvider } from "@vector-im/compound-web";
2324

2425
import { ThreadsActivityCentre } from "../../../../src/components/views/spaces/threads-activity-centre";
2526
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
@@ -37,12 +38,16 @@ describe("ThreadsActivityCentre", () => {
3738
return screen.getByRole("menu");
3839
};
3940

40-
const renderTAC = () => {
41+
const getTACDescription = () => {
42+
return screen.getByText("Threads");
43+
};
44+
45+
const renderTAC = (props?: ComponentProps<typeof ThreadsActivityCentre>) => {
4146
render(
4247
<MatrixClientContext.Provider value={cli}>
43-
<ThreadsActivityCentre />
44-
);
48+
<ThreadsActivityCentre {...props} />
4549
</MatrixClientContext.Provider>,
50+
{ wrapper: TooltipProvider },
4651
);
4752
};
4853

@@ -105,6 +110,12 @@ describe("ThreadsActivityCentre", () => {
105110
expect(getTACButton()).toBeInTheDocument();
106111
});
107112

113+
it("should render the threads activity centre button and the display label", async () => {
114+
renderTAC({ displayButtonLabel: true });
115+
expect(getTACButton()).toBeInTheDocument();
116+
expect(getTACDescription()).toBeInTheDocument();
117+
});
118+
108119
it("should render the threads activity centre menu when the button is clicked", async () => {
109120
renderTAC();
110121
await userEvent.click(getTACButton());

test/components/views/spaces/__snapshots__/ThreadsActivityCentre-test.tsx.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] = `
44
<div
5-
aria-labelledby="radix-12"
5+
aria-labelledby="radix-20"
66
aria-orientation="vertical"
77
class="_menu_1x5h1_17"
88
data-align="end"
@@ -11,7 +11,7 @@ exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] =
1111
data-side="right"
1212
data-state="open"
1313
dir="ltr"
14-
id="radix-13"
14+
id="radix-21"
1515
role="menu"
1616
style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); pointer-events: auto;"
1717
tabindex="-1"
@@ -127,7 +127,7 @@ exports[`ThreadsActivityCentre renders notifications matching the snapshot 1`] =
127127

128128
exports[`ThreadsActivityCentre should match snapshot when empty 1`] = `
129129
<div
130-
aria-labelledby="radix-18"
130+
aria-labelledby="radix-28"
131131
aria-orientation="vertical"
132132
class="_menu_1x5h1_17"
133133
data-align="end"
@@ -136,7 +136,7 @@ exports[`ThreadsActivityCentre should match snapshot when empty 1`] = `
136136
data-side="right"
137137
data-state="open"
138138
dir="ltr"
139-
id="radix-19"
139+
id="radix-29"
140140
role="menu"
141141
style="outline: none; --radix-dropdown-menu-content-transform-origin: var(--radix-popper-transform-origin); --radix-dropdown-menu-content-available-width: var(--radix-popper-available-width); --radix-dropdown-menu-content-available-height: var(--radix-popper-available-height); --radix-dropdown-menu-trigger-width: var(--radix-popper-anchor-width); --radix-dropdown-menu-trigger-height: var(--radix-popper-anchor-height); pointer-events: auto;"
142142
tabindex="-1"

0 commit comments

Comments
 (0)