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

Commit 212233c

Browse files
authored
Fix: inline links selecting radio button (#9543)
* fix: inline link selecting radio button
1 parent 7c33fc6 commit 212233c

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

src/components/views/settings/tabs/room/NotificationSettingsTab.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { logger } from "matrix-js-sdk/src/logger";
1919

2020
import { _t } from "../../../../../languageHandler";
2121
import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
22-
import AccessibleButton from "../../../elements/AccessibleButton";
22+
import AccessibleButton, { ButtonEvent } from "../../../elements/AccessibleButton";
2323
import Notifier from "../../../../../Notifier";
2424
import SettingsStore from '../../../../../settings/SettingsStore';
2525
import { SettingLevel } from "../../../../../settings/SettingLevel";
@@ -163,7 +163,9 @@ export default class NotificationsSettingsTab extends React.Component<IProps, IS
163163
this.forceUpdate();
164164
};
165165

166-
private onOpenSettingsClick = () => {
166+
private onOpenSettingsClick = (event: ButtonEvent) => {
167+
// avoid selecting the radio button
168+
event.preventDefault();
167169
this.props.closeSettingsFn();
168170
defaultDispatcher.dispatch({
169171
action: Action.ViewUserSettings,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from "react";
18+
import { render, RenderResult } from "@testing-library/react";
19+
import { MatrixClient } from "matrix-js-sdk/src/client";
20+
import userEvent from "@testing-library/user-event";
21+
22+
import NotificationSettingsTab from "../../../../../../src/components/views/settings/tabs/room/NotificationSettingsTab";
23+
import { mkStubRoom, stubClient } from "../../../../../test-utils";
24+
import { MatrixClientPeg } from "../../../../../../src/MatrixClientPeg";
25+
import { EchoChamber } from "../../../../../../src/stores/local-echo/EchoChamber";
26+
import { RoomEchoChamber } from "../../../../../../src/stores/local-echo/RoomEchoChamber";
27+
28+
describe("NotificatinSettingsTab", () => {
29+
const roomId = "!room:example.com";
30+
let cli: MatrixClient;
31+
let roomProps: RoomEchoChamber;
32+
33+
const renderTab = (): RenderResult => {
34+
return render(<NotificationSettingsTab roomId={roomId} closeSettingsFn={() => { }} />);
35+
};
36+
37+
beforeEach(() => {
38+
stubClient();
39+
cli = MatrixClientPeg.get();
40+
const room = mkStubRoom(roomId, "test room", cli);
41+
roomProps = EchoChamber.forRoom(room);
42+
43+
NotificationSettingsTab.contextType = React.createContext(cli);
44+
});
45+
46+
it("should prevent »Settings« link click from bubbling up to radio buttons", async () => {
47+
const tab = renderTab();
48+
49+
// settings link of mentions_only volume
50+
const settingsLink = tab.container.querySelector(
51+
"label.mx_NotificationSettingsTab_mentionsKeywordsEntry div.mx_AccessibleButton");
52+
if (!settingsLink) throw new Error("settings link does not exist.");
53+
54+
await userEvent.click(settingsLink);
55+
56+
expect(roomProps.notificationVolume).not.toBe("mentions_only");
57+
});
58+
});

0 commit comments

Comments
 (0)