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

a11y - wrap notification level radios in fieldsets #7471

Merged
merged 5 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 42 additions & 39 deletions res/css/views/settings/_Notifications.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,56 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_UserNotifSettings {
color: $primary-content; // override from default settings page styles

.mx_UserNotifSettings_pushRulesTable {
width: calc(100% + 12px); // +12px to line up center of 'Noisy' column with toggle switches
table-layout: fixed;
border-collapse: collapse;
border-spacing: 0;
margin-top: 40px;

tr > th {
font-weight: $font-semi-bold;
.mx_UserNotifSettings_grid {
width: calc(100% + 12px); // +12px to line up center of 'Noisy' column with toggle switches
display: grid;
grid-template-columns: auto repeat(3, 62px);
place-items: center center;
grid-gap: 8px;
margin-top: $spacing-40;

// Override StyledRadioButton default styles
.mx_StyledRadioButton {
justify-content: center;

.mx_StyledRadioButton_content {
display: none;
}

tr > th:first-child {
text-align: left;
font-size: $font-18px;
}

tr > th:nth-child(n + 2) {
color: $secondary-content;
font-size: $font-12px;
vertical-align: middle;
width: 66px;
.mx_StyledRadioButton_spacer {
display: none;
}
}
}

tr > td:nth-child(n + 2) {
text-align: center;
}
.mx_UserNotifSettings_gridRowContainer {
display: contents;
}

tr > td {
padding-top: 8px;
}
.mx_UserNotifSettings_gridRow {
display: contents;
}

// Override StyledRadioButton default styles
.mx_StyledRadioButton {
justify-content: center;
.mx_UserNotifSettings_gridRowLabel {
justify-self: start;
// <legend> does not accept
// display: inline | inline-block
// force it inline using float
float: left;
}
.mx_UserNotifSettings_gridRowHeading {
font-size: $font-18px;
font-weight: $font-semi-bold;
}

.mx_StyledRadioButton_content {
display: none;
}
.mx_UserNotifSettings_gridColumnLabel {
color: $secondary-content;
font-size: $font-12px;
font-weight: $font-semi-bold;
}

.mx_StyledRadioButton_spacer {
display: none;
}
}
}
.mx_UserNotifSettings {
color: $primary-content; // override from default settings page styles

.mx_UserNotifSettings_floatingSection {
margin-top: 40px;
Expand Down
42 changes: 19 additions & 23 deletions src/components/views/settings/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {

const makeRadio = (r: IVectorPushRule, s: VectorState) => (
<StyledRadioButton
key={r.ruleId}
key={r.ruleId + s}
name={r.ruleId}
checked={r.vectorState === s}
onChange={this.onRadioChecked.bind(this, r, s)}
Expand All @@ -581,15 +581,17 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
/>
);

const rows = this.state.vectorPushRules[category].map(r => <tr
data-test-id={category + r.ruleId}
key={category + r.ruleId}
>
<td>{ r.description }</td>
<td>{ makeRadio(r, VectorState.Off) }</td>
<td>{ makeRadio(r, VectorState.On) }</td>
<td>{ makeRadio(r, VectorState.Loud) }</td>
</tr>);
const fieldsetRows = this.state.vectorPushRules[category].map(r =>
<fieldset
key={category + r.ruleId}
data-test-id={category + r.ruleId}
className='mx_UserNotifSettings_gridRowContainer'
>
<legend className='mx_UserNotifSettings_gridRowLabel'>{ r.description }</legend>
{ makeRadio(r, VectorState.Off) }
{ makeRadio(r, VectorState.On) }
{ makeRadio(r, VectorState.Loud) }
</fieldset>);

let sectionName: TranslatedString;
switch (category) {
Expand All @@ -607,19 +609,13 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
}

return <>
<table data-test-id={`notif-section-${category}`} className='mx_UserNotifSettings_pushRulesTable'>
<thead>
<tr>
<th>{ sectionName }</th>
<th>{ VectorStateToLabel[VectorState.Off] }</th>
<th>{ VectorStateToLabel[VectorState.On] }</th>
<th>{ VectorStateToLabel[VectorState.Loud] }</th>
</tr>
</thead>
<tbody>
{ rows }
</tbody>
</table>
<div data-test-id={`notif-section-${category}`} className='mx_UserNotifSettings_grid'>
<span className='mx_UserNotifSettings_gridRowLabel mx_UserNotifSettings_gridRowHeading'>{ sectionName }</span>
<span className='mx_UserNotifSettings_gridColumnLabel'>{ VectorStateToLabel[VectorState.Off] }</span>
<span className='mx_UserNotifSettings_gridColumnLabel'>{ VectorStateToLabel[VectorState.On] }</span>
<span className='mx_UserNotifSettings_gridColumnLabel'>{ VectorStateToLabel[VectorState.Loud] }</span>
{ fieldsetRows }
</div>
{ clearNotifsButton }
{ keywordComposer }
</>;
Expand Down
4 changes: 2 additions & 2 deletions test/components/views/settings/Notifications-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ describe('<Notifications />', () => {
const section = 'vector_global';

const globalSection = findByTestId(component, `notif-section-${section}`);
// 16 notification rules with class 'global'
expect(globalSection.find('td').length).toEqual(16);
// 4 notification rules with class 'global'
expect(globalSection.find('fieldset').length).toEqual(4);
// oneToOneRule is set to 'on'
const oneToOneRuleElement = findByTestId(component, section + oneToOneRule.rule_id);
expect(getCheckedRadioForRule(oneToOneRuleElement)).toEqual('On');
Expand Down