Fix spotlight opening in TAC (#12315)
* Fix spotlight opening in TAC * Add tests * Remove `RovingTabIndexProvider`
This commit is contained in:
parent
70365c891b
commit
ddbc6439ce
4 changed files with 95 additions and 31 deletions
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { expect, test } from ".";
|
import { expect, test } from ".";
|
||||||
|
import { CommandOrControl } from "../../utils";
|
||||||
|
|
||||||
test.describe("Threads Activity Centre", () => {
|
test.describe("Threads Activity Centre", () => {
|
||||||
test.use({
|
test.use({
|
||||||
|
@ -118,4 +119,19 @@ test.describe("Threads Activity Centre", () => {
|
||||||
]);
|
]);
|
||||||
await expect(util.getTacPanel()).toMatchScreenshot("tac-panel-notification-unread.png");
|
await expect(util.getTacPanel()).toMatchScreenshot("tac-panel-notification-unread.png");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("should block the Spotlight to open when the TAC is opened", async ({ util, page }) => {
|
||||||
|
const toggleSpotlight = () => page.keyboard.press(`${CommandOrControl}+k`);
|
||||||
|
|
||||||
|
// Sanity check
|
||||||
|
// Open and close the spotlight
|
||||||
|
await toggleSpotlight();
|
||||||
|
await expect(page.locator(".mx_SpotlightDialog")).toBeVisible();
|
||||||
|
await toggleSpotlight();
|
||||||
|
|
||||||
|
await util.openTac();
|
||||||
|
// The spotlight should not be opened
|
||||||
|
await toggleSpotlight();
|
||||||
|
await expect(page.locator(".mx_SpotlightDialog")).not.toBeVisible();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
* /
|
* /
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
.mx_ThreadsActivityCentre_container {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
.mx_ThreadsActivityCentreButton {
|
.mx_ThreadsActivityCentreButton {
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
margin: 18px auto auto auto;
|
margin: 18px auto auto auto;
|
||||||
|
|
|
@ -32,6 +32,8 @@ import { useUnreadThreadRooms } from "./useUnreadThreadRooms";
|
||||||
import { StatelessNotificationBadge } from "../../rooms/NotificationBadge/StatelessNotificationBadge";
|
import { StatelessNotificationBadge } from "../../rooms/NotificationBadge/StatelessNotificationBadge";
|
||||||
import { NotificationLevel } from "../../../../stores/notifications/NotificationLevel";
|
import { NotificationLevel } from "../../../../stores/notifications/NotificationLevel";
|
||||||
import PosthogTrackers from "../../../../PosthogTrackers";
|
import PosthogTrackers from "../../../../PosthogTrackers";
|
||||||
|
import { getKeyBindingsManager } from "../../../../KeyBindingsManager";
|
||||||
|
import { KeyBindingAction } from "../../../../accessibility/KeyboardShortcuts";
|
||||||
|
|
||||||
interface ThreadsActivityCentreProps {
|
interface ThreadsActivityCentreProps {
|
||||||
/**
|
/**
|
||||||
|
@ -49,41 +51,56 @@ export function ThreadsActivityCentre({ displayButtonLabel }: ThreadsActivityCen
|
||||||
const roomsAndNotifications = useUnreadThreadRooms(open);
|
const roomsAndNotifications = useUnreadThreadRooms(open);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu
|
<div
|
||||||
align="end"
|
className="mx_ThreadsActivityCentre_container"
|
||||||
open={open}
|
onKeyDown={(evt) => {
|
||||||
onOpenChange={(newOpen) => {
|
// Do nothing if the TAC is closed
|
||||||
// Track only when the Threads Activity Centre is opened
|
if (!open) return;
|
||||||
if (newOpen) PosthogTrackers.trackInteraction("WebThreadsActivityCentreButton");
|
|
||||||
|
|
||||||
setOpen(newOpen);
|
const action = getKeyBindingsManager().getNavigationAction(evt);
|
||||||
|
|
||||||
|
// Block spotlight opening
|
||||||
|
if (action === KeyBindingAction.FilterRooms) {
|
||||||
|
evt.stopPropagation();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
side="right"
|
|
||||||
title={_t("threads_activity_centre|header")}
|
|
||||||
trigger={
|
|
||||||
<ThreadsActivityCentreButton
|
|
||||||
displayLabel={displayButtonLabel}
|
|
||||||
notificationLevel={roomsAndNotifications.greatestNotificationLevel}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
{/* Make the content of the pop-up scrollable */}
|
<Menu
|
||||||
<div className="mx_ThreadsActivity_rows">
|
align="end"
|
||||||
{roomsAndNotifications.rooms.map(({ room, notificationLevel }) => (
|
open={open}
|
||||||
<ThreadsActivityRow
|
onOpenChange={(newOpen) => {
|
||||||
key={room.roomId}
|
// Track only when the Threads Activity Centre is opened
|
||||||
room={room}
|
if (newOpen) PosthogTrackers.trackInteraction("WebThreadsActivityCentreButton");
|
||||||
notificationLevel={notificationLevel}
|
|
||||||
onClick={() => setOpen(false)}
|
setOpen(newOpen);
|
||||||
|
}}
|
||||||
|
side="right"
|
||||||
|
title={_t("threads_activity_centre|header")}
|
||||||
|
trigger={
|
||||||
|
<ThreadsActivityCentreButton
|
||||||
|
displayLabel={displayButtonLabel}
|
||||||
|
notificationLevel={roomsAndNotifications.greatestNotificationLevel}
|
||||||
/>
|
/>
|
||||||
))}
|
}
|
||||||
{roomsAndNotifications.rooms.length === 0 && (
|
>
|
||||||
<div className="mx_ThreadsActivityCentre_emptyCaption">
|
{/* Make the content of the pop-up scrollable */}
|
||||||
{_t("threads_activity_centre|no_rooms_with_unreads_threads")}
|
<div className="mx_ThreadsActivity_rows">
|
||||||
</div>
|
{roomsAndNotifications.rooms.map(({ room, notificationLevel }) => (
|
||||||
)}
|
<ThreadsActivityRow
|
||||||
</div>
|
key={room.roomId}
|
||||||
</Menu>
|
room={room}
|
||||||
|
notificationLevel={notificationLevel}
|
||||||
|
onClick={() => setOpen(false)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{roomsAndNotifications.rooms.length === 0 && (
|
||||||
|
<div className="mx_ThreadsActivityCentre_emptyCaption">
|
||||||
|
{_t("threads_activity_centre|no_rooms_with_unreads_threads")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,4 +180,31 @@ describe("ThreadsActivityCentre", () => {
|
||||||
|
|
||||||
expect(screen.getByRole("menu")).toMatchSnapshot();
|
expect(screen.getByRole("menu")).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should block Ctrl/CMD + k shortcut", async () => {
|
||||||
|
cli.getVisibleRooms = jest.fn().mockReturnValue([roomWithHighlight]);
|
||||||
|
|
||||||
|
const keyDownHandler = jest.fn();
|
||||||
|
render(
|
||||||
|
<div
|
||||||
|
onKeyDown={(evt) => {
|
||||||
|
keyDownHandler(evt.key, evt.ctrlKey);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MatrixClientContext.Provider value={cli}>
|
||||||
|
<ThreadsActivityCentre />
|
||||||
|
</MatrixClientContext.Provider>
|
||||||
|
</div>,
|
||||||
|
{ wrapper: TooltipProvider },
|
||||||
|
);
|
||||||
|
await userEvent.click(getTACButton());
|
||||||
|
|
||||||
|
// CTRL/CMD + k should be blocked
|
||||||
|
await userEvent.keyboard("{Control>}k{/Control}");
|
||||||
|
expect(keyDownHandler).not.toHaveBeenCalledWith("k", true);
|
||||||
|
|
||||||
|
// Sanity test
|
||||||
|
await userEvent.keyboard("{Control>}a{/Control}");
|
||||||
|
expect(keyDownHandler).toHaveBeenCalledWith("a", true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue