Skip to content

Commit 8ac308c

Browse files
committed
improvement: a11y: landmark-ify "Chat" section
So that when the focus enters the region, screen readers announce "Bob chat region". This also includes e.g. moving focus from the "Search for chats" input to the composer.
1 parent 09da526 commit 8ac308c

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

packages/frontend/scss/_global.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,22 @@ audio {
284284
p.whitespace {
285285
white-space: break-spaces;
286286
}
287+
288+
// Only for screen-readers.
289+
// Taken from
290+
// https://github.com/twbs/bootstrap/blob/4c98145482719f5113ca31e389a7be07c5404e13/scss/mixins/_visually-hidden.scss#L3-L22
291+
.visually-hidden {
292+
width: 1px !important;
293+
height: 1px !important;
294+
padding: 0 !important;
295+
margin: -1px !important; // Fix for https://github.com/twbs/bootstrap/issues/25686
296+
overflow: hidden !important;
297+
clip: rect(0, 0, 0, 0) !important;
298+
white-space: nowrap !important;
299+
border: 0 !important;
300+
301+
// Fix for positioned table caption that could become anonymous cells
302+
&:not(caption) {
303+
position: absolute !important;
304+
}
305+
}

packages/frontend/src/components/composer/Composer.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,13 @@ const Composer = forwardRef<
503503
// TODO a11y: when `isEditingModeActive`, we have an "Edit message"
504504
// text, which we can use as the label / header.
505505
aria-label={
506-
(messageEditing.isEditingModeActive
506+
messageEditing.isEditingModeActive
507507
? window.static_translate('edit_message')
508-
: window.static_translate('write_message_desktop')) +
509-
// Make it clear which chat we're in.
510-
// TODO probably need a proper string, with interpolation.
511-
': ' +
512-
selectedChat.name
508+
: window.static_translate('write_message_desktop')
509+
// We could also add chat name here to make it extra clear
510+
// which chat we're in,
511+
// but the "Chat" region label
512+
// (`id='chat-section-heading'`) is probably enough.
513513
}
514514
>
515515
<div className='upper-bar'>

packages/frontend/src/components/screens/MainScreen/MainScreen.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ export default function MainScreen({ accountId }: Props) {
286286
}}
287287
/>
288288
</section>
289-
<section className={styles.chatAndNavbar}>
289+
<section
290+
role='region'
291+
aria-labelledby='chat-section-heading'
292+
className={styles.chatAndNavbar}
293+
>
290294
<nav className={styles.chatNavbar} data-tauri-drag-region>
291295
{smallScreenMode && (
292296
<span data-no-drag-region>
@@ -468,7 +472,13 @@ function ChatHeading({ chat }: { chat: T.FullChat }) {
468472
/>
469473
<div style={{ marginInlineStart: '7px', overflow: 'hidden' }}>
470474
<div className='navbar-chat-name'>
471-
<div className='truncated'>{chat.name}</div>
475+
<h2 id='chat-section-heading' className='truncated'>
476+
{chat.name}
477+
<span className='visually-hidden'>
478+
<br />
479+
{tx('chat')}
480+
</span>
481+
</h2>
472482
<div className='chat_property_icons'>
473483
{chat.ephemeralTimer !== 0 && (
474484
<div

packages/frontend/src/components/screens/MainScreen/styles.module.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@
9191
font-size: 18px;
9292
font-weight: bold;
9393
overflow: hidden;
94+
95+
h1,
96+
h2,
97+
h3,
98+
h4,
99+
h5,
100+
h6 {
101+
font-size: inherit;
102+
font-weight: inherit;
103+
display: block;
104+
margin: 0;
105+
}
94106
}
95107
:global(.navbar-heading-chat-info-button) {
96108
// Fill the parent, overlay the siblings.

0 commit comments

Comments
 (0)