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

Commit 9211da2

Browse files
author
Kerry
authored
Use semantic headings in user settings - Notifications (#10948)
* use semantic headings in user notif settings * unset margin for subsection content when no heading * remove debug
1 parent f491f2f commit 9211da2

File tree

6 files changed

+79
-83
lines changed

6 files changed

+79
-83
lines changed

res/css/components/views/settings/shared/_SettingsSubsection.pcss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,8 @@ limitations under the License.
5252
&.mx_SettingsSubsection_contentStretch {
5353
justify-items: stretch;
5454
}
55+
56+
&.mx_SettingsSubsection_noHeading {
57+
margin-top: 0;
58+
}
5559
}

res/css/views/settings/_Notifications.pcss

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ limitations under the License.
2020
grid-template-columns: auto repeat(3, 62px);
2121
place-items: center center;
2222
grid-gap: 8px;
23-
margin-top: $spacing-40;
2423

2524
/* Override StyledRadioButton default styles */
2625
.mx_StyledRadioButton {
@@ -34,6 +33,11 @@ limitations under the License.
3433
display: none;
3534
}
3635
}
36+
37+
// left align section heading
38+
.mx_SettingsSubsectionHeading {
39+
justify-self: start;
40+
}
3741
}
3842

3943
.mx_UserNotifSettings_gridRowContainer {
@@ -51,10 +55,6 @@ limitations under the License.
5155
/* force it inline using float */
5256
float: left;
5357
}
54-
.mx_UserNotifSettings_gridRowHeading {
55-
font-size: $font-18px;
56-
font-weight: var(--font-semi-bold);
57-
}
5858

5959
.mx_UserNotifSettings_gridColumnLabel {
6060
color: $secondary-content;
@@ -70,37 +70,33 @@ limitations under the License.
7070
margin-top: -$spacing-4;
7171
}
7272

73-
.mx_UserNotifSettings {
74-
color: $primary-content; /* override from default settings page styles */
73+
.mx_UserNotifSettings_floatingSection {
74+
margin-top: 40px;
7575

76-
.mx_UserNotifSettings_floatingSection {
77-
margin-top: 40px;
78-
79-
& > div:first-child {
80-
/* section header */
81-
font-size: $font-18px;
82-
font-weight: var(--font-semi-bold);
83-
}
76+
& > div:first-child {
77+
/* section header */
78+
font-size: $font-18px;
79+
font-weight: var(--font-semi-bold);
80+
}
8481

85-
> table {
86-
border-collapse: collapse;
87-
border-spacing: 0;
88-
margin-top: 8px;
82+
> table {
83+
border-collapse: collapse;
84+
border-spacing: 0;
85+
margin-top: 8px;
8986

90-
tr > td:first-child {
91-
/* Just for a bit of spacing */
92-
padding-right: 8px;
93-
}
87+
tr > td:first-child {
88+
/* Just for a bit of spacing */
89+
padding-right: 8px;
9490
}
9591
}
92+
}
9693

97-
.mx_UserNotifSettings_clearNotifsButton {
98-
margin-top: 8px;
99-
}
94+
.mx_UserNotifSettings_clearNotifsButton {
95+
margin-top: 8px;
96+
}
10097

101-
.mx_TagComposer {
102-
margin-top: 35px; /* lots of distance from the last line of the table */
103-
}
98+
.mx_TagComposer {
99+
margin-top: 35px; /* lots of distance from the last line of the table */
104100
}
105101

106102
.mx_AccessibleButton.mx_NotificationSound_browse {

src/components/views/settings/Notifications.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ import {
4848
updatePushRuleActions,
4949
} from "../../../utils/pushRules/updatePushRuleActions";
5050
import { Caption } from "../typography/Caption";
51+
import { SettingsSubsectionHeading } from "./shared/SettingsSubsectionHeading";
52+
import SettingsSubsection from "./shared/SettingsSubsection";
5153

5254
// TODO: this "view" component still has far too much application logic in it,
5355
// which should be factored out to other files.
@@ -649,16 +651,14 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
649651

650652
private renderTopSection(): JSX.Element {
651653
const masterSwitch = (
652-
<>
653-
<LabelledToggleSwitch
654-
data-testid="notif-master-switch"
655-
value={!this.isInhibited}
656-
label={_t("Enable notifications for this account")}
657-
caption={_t("Turn off to disable notifications on all your devices and sessions")}
658-
onChange={this.onMasterRuleChanged}
659-
disabled={this.state.phase === Phase.Persisting}
660-
/>
661-
</>
654+
<LabelledToggleSwitch
655+
data-testid="notif-master-switch"
656+
value={!this.isInhibited}
657+
label={_t("Enable notifications for this account")}
658+
caption={_t("Turn off to disable notifications on all your devices and sessions")}
659+
onChange={this.onMasterRuleChanged}
660+
disabled={this.state.phase === Phase.Persisting}
661+
/>
662662
);
663663

664664
// If all the rules are inhibited, don't show anything.
@@ -680,7 +680,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
680680
));
681681

682682
return (
683-
<>
683+
<SettingsSubsection>
684684
{masterSwitch}
685685

686686
<LabelledToggleSwitch
@@ -718,7 +718,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
718718
)}
719719

720720
{emailSwitches}
721-
</>
721+
</SettingsSubsection>
722722
);
723723
}
724724

@@ -814,7 +814,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
814814
</fieldset>
815815
));
816816

817-
let sectionName: TranslatedString;
817+
let sectionName: string;
818818
switch (category) {
819819
case RuleClass.VectorGlobal:
820820
sectionName = _t("Global");
@@ -830,19 +830,17 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
830830
}
831831

832832
return (
833-
<>
833+
<div>
834834
<div data-testid={`notif-section-${category}`} className="mx_UserNotifSettings_grid">
835-
<span className="mx_UserNotifSettings_gridRowLabel mx_UserNotifSettings_gridRowHeading">
836-
{sectionName}
837-
</span>
835+
<SettingsSubsectionHeading heading={sectionName} />
838836
<span className="mx_UserNotifSettings_gridColumnLabel">{VectorStateToLabel[VectorState.Off]}</span>
839837
<span className="mx_UserNotifSettings_gridColumnLabel">{VectorStateToLabel[VectorState.On]}</span>
840838
<span className="mx_UserNotifSettings_gridColumnLabel">{VectorStateToLabel[VectorState.Loud]}</span>
841839
{fieldsetRows}
842840
</div>
843841
{clearNotifsButton}
844842
{keywordComposer}
845-
</>
843+
</div>
846844
);
847845
}
848846

@@ -877,13 +875,13 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
877875
}
878876

879877
return (
880-
<div className="mx_UserNotifSettings">
878+
<>
881879
{this.renderTopSection()}
882880
{this.renderCategory(RuleClass.VectorGlobal)}
883881
{this.renderCategory(RuleClass.VectorMentions)}
884882
{this.renderCategory(RuleClass.VectorOther)}
885883
{this.renderTargets()}
886-
</div>
884+
</>
887885
);
888886
}
889887
}

src/components/views/settings/shared/SettingsSubsection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import React, { HTMLAttributes } from "react";
2020
import { SettingsSubsectionHeading } from "./SettingsSubsectionHeading";
2121

2222
export interface SettingsSubsectionProps extends HTMLAttributes<HTMLDivElement> {
23-
heading: string | React.ReactNode;
23+
heading?: string | React.ReactNode;
2424
description?: string | React.ReactNode;
2525
children?: React.ReactNode;
2626
// when true content will be justify-items: stretch, which will make items within the section stretch to full width.
@@ -50,6 +50,7 @@ export const SettingsSubsection: React.FC<SettingsSubsectionProps> = ({
5050
<div
5151
className={classNames("mx_SettingsSubsection_content", {
5252
mx_SettingsSubsection_contentStretch: !!stretchContent,
53+
mx_SettingsSubsection_noHeading: !heading && !description,
5354
})}
5455
>
5556
{children}

src/components/views/settings/tabs/user/NotificationUserSettingsTab.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ import React from "react";
1818

1919
import { _t } from "../../../../../languageHandler";
2020
import Notifications from "../../Notifications";
21+
import { SettingsSection } from "../../shared/SettingsSection";
22+
import SettingsTab from "../SettingsTab";
2123

2224
export default class NotificationUserSettingsTab extends React.Component {
2325
public render(): React.ReactNode {
2426
return (
25-
<div className="mx_SettingsTab">
26-
<div className="mx_SettingsTab_heading">{_t("Notifications")}</div>
27-
<div className="mx_SettingsTab_section mx_SettingsTab_subsectionText">
27+
<SettingsTab>
28+
<SettingsSection heading={_t("Notifications")}>
2829
<Notifications />
29-
</div>
30-
</div>
30+
</SettingsSection>
31+
</SettingsTab>
3132
);
3233
}
3334
}

test/components/views/settings/__snapshots__/Notifications-test.tsx.snap

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,36 @@
33
exports[`<Notifications /> main notification switches renders only enable notifications switch when notifications are disabled 1`] = `
44
<div>
55
<div
6-
class="mx_UserNotifSettings"
6+
class="mx_SettingsFlag"
7+
data-testid="notif-master-switch"
78
>
8-
<div
9-
class="mx_SettingsFlag"
10-
data-testid="notif-master-switch"
9+
<span
10+
class="mx_SettingsFlag_label"
1111
>
12+
<div
13+
id="mx_LabelledToggleSwitch_testid_0"
14+
>
15+
Enable notifications for this account
16+
</div>
1217
<span
13-
class="mx_SettingsFlag_label"
18+
class="mx_Caption"
19+
id="mx_LabelledToggleSwitch_testid_0_caption"
1420
>
15-
<div
16-
id="mx_LabelledToggleSwitch_testid_0"
17-
>
18-
Enable notifications for this account
19-
</div>
20-
<span
21-
class="mx_Caption"
22-
id="mx_LabelledToggleSwitch_testid_0_caption"
23-
>
24-
Turn off to disable notifications on all your devices and sessions
25-
</span>
21+
Turn off to disable notifications on all your devices and sessions
2622
</span>
23+
</span>
24+
<div
25+
aria-checked="false"
26+
aria-describedby="mx_LabelledToggleSwitch_testid_0_caption"
27+
aria-disabled="false"
28+
aria-labelledby="mx_LabelledToggleSwitch_testid_0"
29+
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
30+
role="switch"
31+
tabindex="0"
32+
>
2733
<div
28-
aria-checked="false"
29-
aria-describedby="mx_LabelledToggleSwitch_testid_0_caption"
30-
aria-disabled="false"
31-
aria-labelledby="mx_LabelledToggleSwitch_testid_0"
32-
class="mx_AccessibleButton mx_ToggleSwitch mx_ToggleSwitch_enabled"
33-
role="switch"
34-
tabindex="0"
35-
>
36-
<div
37-
class="mx_ToggleSwitch_ball"
38-
/>
39-
</div>
34+
class="mx_ToggleSwitch_ball"
35+
/>
4036
</div>
4137
</div>
4238
</div>

0 commit comments

Comments
 (0)