Skip to content

Commit 09da526

Browse files
committed
improvement: a11y: "View Profile" label for header
This is foremost a preparation for making the chat heading an h1-h6 element, so that it can act as a section header. Putting an h1-h6 element inside of a button is not allowed, and putting a button inside of a h1-h6 element is a bit awkward, so let's have a separate button for "View Profile" / "Edit Group".
1 parent d8a96de commit 09da526

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,15 +415,46 @@ function ChatHeading({ chat }: { chat: T.FullChat }) {
415415
}
416416
}
417417

418+
let buttonLabel: string
419+
switch (chat.chatType) {
420+
case C.DC_CHAT_TYPE_SINGLE: {
421+
buttonLabel = tx('menu_view_profile')
422+
break
423+
}
424+
case C.DC_CHAT_TYPE_GROUP: {
425+
// If you're no longer a member, editing the group is not possible,
426+
// but we don't have a better string.
427+
buttonLabel = tx('menu_edit_group')
428+
break
429+
}
430+
case C.DC_CHAT_TYPE_OUT_BROADCAST: {
431+
buttonLabel = tx('edit_channel')
432+
break
433+
}
434+
case C.DC_CHAT_TYPE_IN_BROADCAST: {
435+
// We don't have a more appropriate one
436+
buttonLabel = tx('menu_view_profile')
437+
break
438+
}
439+
case C.DC_CHAT_TYPE_MAILINGLIST: {
440+
// We don't have a more appropriate one
441+
buttonLabel = tx('menu_view_profile')
442+
break
443+
}
444+
case C.DC_CHAT_TYPE_UNDEFINED: {
445+
buttonLabel = tx('menu_view_profile')
446+
break
447+
}
448+
default: {
449+
buttonLabel = tx('menu_view_profile')
450+
log.warn(`Unknown chatType ${chat.chatType}`)
451+
}
452+
}
453+
418454
const subtitle = chatSubtitle(chat)
419455

420456
return (
421-
<button
422-
className='navbar-heading navbar-heading--button'
423-
data-no-drag-region
424-
onClick={onTitleClick}
425-
data-testid='chat-info-button'
426-
>
457+
<div className='navbar-heading' data-no-drag-region>
427458
<Avatar
428459
displayName={chat.name}
429460
color={chat.color}
@@ -451,7 +482,13 @@ function ChatHeading({ chat }: { chat: T.FullChat }) {
451482
<div className='navbar-chat-subtitle'>{subtitle}</div>
452483
)}
453484
</div>
454-
</button>
485+
<button
486+
onClick={onTitleClick}
487+
aria-label={buttonLabel}
488+
data-testid='chat-info-button'
489+
className='navbar-heading-chat-info-button'
490+
></button>
491+
</div>
455492
)
456493
}
457494

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@
7474
width: 0;
7575
flex-grow: 1;
7676
}
77-
:global(.navbar-heading--button) {
78-
@include mixins.button-reset;
79-
}
8077
:global(.navbar-heading) {
78+
position: relative;
79+
80+
width: fit-content;
8181
// See `.chatNavbarHeadingWrapper`.
8282
max-width: 100%;
8383

@@ -92,6 +92,13 @@
9292
font-weight: bold;
9393
overflow: hidden;
9494
}
95+
:global(.navbar-heading-chat-info-button) {
96+
// Fill the parent, overlay the siblings.
97+
position: absolute;
98+
inset: 0;
99+
background-color: transparent;
100+
border: none;
101+
}
95102

96103
:global(.views) {
97104
display: flex;

0 commit comments

Comments
 (0)