Skip to content

Commit d8a96de

Browse files
committed
improvement: a11y: landmark-ify composer section
Otherwise for screen-reader users all these "remove quote" "attach file", "emoji" buttons don't make sense, they have no context. This commit makes screen-readers announce "Write a message: Bob" when the focus enters the composer area.
1 parent 84b8819 commit d8a96de

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,12 @@ const Composer = forwardRef<
449449
}, [settingsStore])
450450

451451
if (chatId === null) {
452-
return <div ref={ref}>Error, chatid missing</div>
452+
return <section ref={ref}>Error, chatid missing</section>
453453
}
454454

455455
if (isContactRequest) {
456456
return (
457-
<div ref={ref} className='composer contact-request'>
457+
<section ref={ref} className='composer contact-request'>
458458
<button
459459
className='contact-request-button delete'
460460
onClick={async () => {
@@ -487,13 +487,31 @@ const Composer = forwardRef<
487487
>
488488
{tx('accept')}
489489
</button>
490-
</div>
490+
</section>
491491
)
492492
} else if (!selectedChat.canSend) {
493493
return null
494494
} else {
495495
return (
496-
<div className='composer' ref={ref}>
496+
<section
497+
className='composer'
498+
ref={ref}
499+
role='region'
500+
// Note that there are other `return`s in this component,
501+
// but this `aria-label` doesn't seem to apply to them.
502+
//
503+
// TODO a11y: when `isEditingModeActive`, we have an "Edit message"
504+
// text, which we can use as the label / header.
505+
aria-label={
506+
(messageEditing.isEditingModeActive
507+
? 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
513+
}
514+
>
497515
<div className='upper-bar'>
498516
{!messageEditing.isEditingModeActive ? (
499517
<>
@@ -598,7 +616,6 @@ const Composer = forwardRef<
598616
}
599617
}
600618
chatId={chatId}
601-
chatName={selectedChat.name}
602619
updateDraftText={updateDraftText}
603620
onPaste={handlePaste ?? undefined}
604621
onChange={setCurrentEditText}
@@ -612,7 +629,6 @@ const Composer = forwardRef<
612629
messageEditing.doSendEditRequest ?? (() => {})
613630
}
614631
chatId={chatId}
615-
chatName={selectedChat.name}
616632
// We don't store the edits as "drafts" anywhere except
617633
// inside the <ComposerMessageInput> component itself,
618634
// so this can be a no-op.
@@ -694,7 +710,7 @@ const Composer = forwardRef<
694710
hideStickerPicker={messageEditing.isEditingModeActive}
695711
/>
696712
)}
697-
</div>
713+
</section>
698714
)
699715
}
700716
})

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type ComposerMessageInputProps = {
1515
hidden?: boolean
1616
isMessageEditingMode: boolean
1717
chatId: number
18-
chatName: string
1918
sendMessageOrEditRequest: () => void
2019
enterKeySends: boolean
2120
onPaste?: (e: React.ClipboardEvent<HTMLTextAreaElement>) => void
@@ -284,15 +283,6 @@ export default class ComposerMessageInput extends React.Component<
284283
? window.static_translate('edit_message')
285284
: window.static_translate('write_message_desktop')
286285
}
287-
aria-label={
288-
(this.props.isMessageEditingMode
289-
? window.static_translate('edit_message')
290-
: window.static_translate('write_message_desktop')) +
291-
// Make it clear which chat we're in.
292-
// TODO probably need a proper string, with interpolation.
293-
': ' +
294-
this.props.chatName
295-
}
296286
disabled={this.state.loadingDraft}
297287
dir={
298288
writingDirection === 'rtl'

0 commit comments

Comments
 (0)