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

Commit 2f3c84f

Browse files
authored
Tooltip: improve accessibility of spaces (#12497)
* Migrate to `AccessibleButtons` * Update snapshots
1 parent 050f617 commit 2f3c84f

File tree

9 files changed

+52
-58
lines changed

9 files changed

+52
-58
lines changed

src/components/structures/LeftPanel.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { HEADER_HEIGHT } from "../views/rooms/RoomSublist";
2626
import { Action } from "../../dispatcher/actions";
2727
import RoomSearch from "./RoomSearch";
2828
import ResizeNotifier from "../../utils/ResizeNotifier";
29-
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
3029
import SpaceStore from "../../stores/spaces/SpaceStore";
3130
import { MetaSpace, SpaceKey, UPDATE_SELECTED_SPACE } from "../../stores/spaces";
3231
import { getKeyBindingsManager } from "../../KeyBindingsManager";
@@ -41,7 +40,7 @@ import RoomBreadcrumbs from "../views/rooms/RoomBreadcrumbs";
4140
import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts";
4241
import { shouldShowComponent } from "../../customisations/helpers/UIComponents";
4342
import { UIComponent } from "../../settings/UIFeature";
44-
import { ButtonEvent } from "../views/elements/AccessibleButton";
43+
import AccessibleButton, { ButtonEvent } from "../views/elements/AccessibleButton";
4544
import PosthogTrackers from "../../PosthogTrackers";
4645
import PageType from "../../PageTypes";
4746
import { UserOnboardingButton } from "../views/user-onboarding/UserOnboardingButton";
@@ -333,7 +332,7 @@ export default class LeftPanel extends React.Component<IProps, IState> {
333332
// to start a new call
334333
if (LegacyCallHandler.instance.getSupportsPstnProtocol()) {
335334
dialPadButton = (
336-
<AccessibleTooltipButton
335+
<AccessibleButton
337336
className={classNames("mx_LeftPanel_dialPadButton", {})}
338337
onClick={this.onDialPad}
339338
title={_t("left_panel|open_dial_pad")}
@@ -344,7 +343,7 @@ export default class LeftPanel extends React.Component<IProps, IState> {
344343
let rightButton: JSX.Element | undefined;
345344
if (this.state.activeSpace === MetaSpace.Home && shouldShowComponent(UIComponent.ExploreRooms)) {
346345
rightButton = (
347-
<AccessibleTooltipButton
346+
<AccessibleButton
348347
className="mx_LeftPanel_exploreButton"
349348
onClick={this.onExplore}
350349
title={_t("action|explore_rooms")}

src/components/structures/SpaceHierarchy.tsx

+14-21
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ limitations under the License.
1515
*/
1616

1717
import React, {
18-
ComponentProps,
1918
Dispatch,
2019
KeyboardEvent,
2120
KeyboardEventHandler,
@@ -62,7 +61,6 @@ import InfoTooltip from "../views/elements/InfoTooltip";
6261
import TextWithTooltip from "../views/elements/TextWithTooltip";
6362
import { useStateToggle } from "../../hooks/useStateToggle";
6463
import { getChildOrder } from "../../stores/spaces/SpaceStore";
65-
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
6664
import { Linkify, topicToHtml } from "../../HtmlUtils";
6765
import { useDispatcher } from "../../hooks/useDispatcher";
6866
import { Action } from "../../dispatcher/actions";
@@ -75,7 +73,6 @@ import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
7573
import { JoinRoomReadyPayload } from "../../dispatcher/payloads/JoinRoomReadyPayload";
7674
import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts";
7775
import { getKeyBindingsManager } from "../../KeyBindingsManager";
78-
import { Alignment } from "../views/elements/Tooltip";
7976
import { getTopic } from "../../hooks/room/useTopic";
8077
import { SdkContextClass } from "../../contexts/SDKContext";
8178
import { getDisplayAliasForAliasSet } from "../../Rooms";
@@ -148,7 +145,7 @@ const Tile: React.FC<ITileProps> = ({
148145
let button: ReactElement;
149146
if (busy) {
150147
button = (
151-
<AccessibleTooltipButton
148+
<AccessibleButton
152149
disabled={true}
153150
onClick={onJoinClick}
154151
kind="primary_outline"
@@ -157,7 +154,7 @@ const Tile: React.FC<ITileProps> = ({
157154
title={_t("space|joining_space")}
158155
>
159156
<Spinner w={24} h={24} />
160-
</AccessibleTooltipButton>
157+
</AccessibleButton>
161158
);
162159
} else if (joinedRoom || room.join_rule === JoinRule.Knock) {
163160
// If the room is knockable, show the "View" button even if we are not a member; that
@@ -670,25 +667,16 @@ const ManageButtons: React.FC<IManageButtonsProps> = ({ hierarchy, selected, set
670667

671668
const disabled = !selectedRelations.length || removing || saving;
672669

673-
let Button: React.ComponentType<React.ComponentProps<typeof AccessibleButton>> = AccessibleButton;
674-
let props: Partial<ComponentProps<typeof AccessibleTooltipButton>> = {};
675-
if (!selectedRelations.length) {
676-
Button = AccessibleTooltipButton;
677-
props = {
678-
tooltip: _t("space|select_room_below"),
679-
alignment: Alignment.Top,
680-
};
681-
}
682-
683670
let buttonText = _t("common|saving");
684671
if (!saving) {
685672
buttonText = selectionAllSuggested ? _t("space|unmark_suggested") : _t("space|mark_suggested");
686673
}
687674

675+
const title = !selectedRelations.length ? _t("space|select_room_below") : undefined;
676+
688677
return (
689678
<>
690-
<Button
691-
{...props}
679+
<AccessibleButton
692680
onClick={async (): Promise<void> => {
693681
setRemoving(true);
694682
try {
@@ -719,11 +707,13 @@ const ManageButtons: React.FC<IManageButtonsProps> = ({ hierarchy, selected, set
719707
}}
720708
kind="danger_outline"
721709
disabled={disabled}
710+
aria-label={removing ? _t("redact|ongoing") : _t("action|remove")}
711+
title={title}
712+
placement="top"
722713
>
723714
{removing ? _t("redact|ongoing") : _t("action|remove")}
724-
</Button>
725-
<Button
726-
{...props}
715+
</AccessibleButton>
716+
<AccessibleButton
727717
onClick={async (): Promise<void> => {
728718
setSaving(true);
729719
try {
@@ -750,9 +740,12 @@ const ManageButtons: React.FC<IManageButtonsProps> = ({ hierarchy, selected, set
750740
}}
751741
kind="primary_outline"
752742
disabled={disabled}
743+
aria-label={buttonText}
744+
title={title}
745+
placement="top"
753746
>
754747
{buttonText}
755-
</Button>
748+
</AccessibleButton>
756749
</>
757750
);
758751
};

src/components/structures/SpaceRoomView.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import {
6060
defaultRoomsRenderer,
6161
} from "../views/dialogs/AddExistingToSpaceDialog";
6262
import AccessibleButton, { ButtonEvent } from "../views/elements/AccessibleButton";
63-
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
6463
import ErrorBoundary from "../views/elements/ErrorBoundary";
6564
import Field from "../views/elements/Field";
6665
import RoomFacePile from "../views/elements/RoomFacePile";
@@ -248,7 +247,7 @@ const SpaceLanding: React.FC<{ space: Room }> = ({ space }) => {
248247
let settingsButton;
249248
if (shouldShowSpaceSettings(space)) {
250249
settingsButton = (
251-
<AccessibleTooltipButton
250+
<AccessibleButton
252251
className="mx_SpaceRoomView_landing_settingsButton"
253252
onClick={() => {
254253
showSpaceSettings(space);

src/components/views/spaces/QuickSettingsButton.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import React from "react";
1818
import classNames from "classnames";
1919

2020
import { _t } from "../../../languageHandler";
21-
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
2221
import ContextMenu, { alwaysAboveRightOf, ChevronFace, useContextMenu } from "../../structures/ContextMenu";
2322
import AccessibleButton from "../elements/AccessibleButton";
2423
import StyledCheckbox from "../elements/StyledCheckbox";
@@ -130,16 +129,16 @@ const QuickSettingsButton: React.FC<{
130129

131130
return (
132131
<>
133-
<AccessibleTooltipButton
132+
<AccessibleButton
134133
className={classNames("mx_QuickSettingsButton", { expanded: !isPanelCollapsed })}
135134
onClick={openMenu}
136-
title={_t("quick_settings|title")}
135+
aria-label={_t("quick_settings|title")}
136+
title={isPanelCollapsed ? _t("quick_settings|title") : undefined}
137137
ref={handle}
138-
forceHide={!isPanelCollapsed}
139138
aria-expanded={!isPanelCollapsed}
140139
>
141140
{!isPanelCollapsed ? _t("common|settings") : null}
142-
</AccessibleTooltipButton>
141+
</AccessibleButton>
143142

144143
{contextMenu}
145144
</>

src/components/views/spaces/SpaceCreateMenu.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
import { logger } from "matrix-js-sdk/src/logger";
3939

4040
import { _t } from "../../../languageHandler";
41-
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
4241
import ContextMenu, { ChevronFace } from "../../structures/ContextMenu";
4342
import createRoom, { IOpts as ICreateOpts } from "../../../createRoom";
4443
import MatrixClientContext, { useMatrixClientContext } from "../../../contexts/MatrixClientContext";
@@ -310,7 +309,7 @@ const SpaceCreateMenu: React.FC<{
310309
} else {
311310
body = (
312311
<React.Fragment>
313-
<AccessibleTooltipButton
312+
<AccessibleButton
314313
className="mx_SpaceCreateMenu_back"
315314
onClick={() => setVisibility(null)}
316315
title={_t("action|go_back")}

src/components/views/spaces/SpacePanel.tsx

+10-16
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { _t } from "../../../languageHandler";
3434
import { useContextMenu } from "../../structures/ContextMenu";
3535
import SpaceCreateMenu from "./SpaceCreateMenu";
3636
import { SpaceButton, SpaceItem } from "./SpaceTreeLevel";
37-
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
3837
import { useEventEmitter, useEventEmitterState } from "../../../hooks/useEventEmitter";
3938
import SpaceStore from "../../../stores/spaces/SpaceStore";
4039
import {
@@ -73,6 +72,7 @@ import { ALTERNATE_KEY_NAME } from "../../../accessibility/KeyboardShortcuts";
7372
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
7473
import { UIComponent } from "../../../settings/UIFeature";
7574
import { ThreadsActivityCentre } from "./threads-activity-centre/";
75+
import AccessibleButton from "../elements/AccessibleButton";
7676

7777
const useSpaces = (): [Room[], MetaSpace[], Room[], SpaceKey] => {
7878
const invites = useEventEmitterState<Room[]>(SpaceStore.instance, UPDATE_INVITED_SPACES, () => {
@@ -389,24 +389,18 @@ const SpacePanel: React.FC = () => {
389389
aria-label={_t("common|spaces")}
390390
>
391391
<UserMenu isPanelCollapsed={isPanelCollapsed}>
392-
<AccessibleTooltipButton
392+
<AccessibleButton
393393
className={classNames("mx_SpacePanel_toggleCollapse", { expanded: !isPanelCollapsed })}
394394
onClick={() => setPanelCollapsed(!isPanelCollapsed)}
395395
title={isPanelCollapsed ? _t("action|expand") : _t("action|collapse")}
396-
tooltip={
397-
<div>
398-
<div className="mx_Tooltip_title">
399-
{isPanelCollapsed ? _t("action|expand") : _t("action|collapse")}
400-
</div>
401-
<div className="mx_Tooltip_sub">
402-
{IS_MAC
403-
? "⌘ + ⇧ + D"
404-
: _t(ALTERNATE_KEY_NAME[Key.CONTROL]) +
405-
" + " +
406-
_t(ALTERNATE_KEY_NAME[Key.SHIFT]) +
407-
" + D"}
408-
</div>
409-
</div>
396+
// TODO should use a kbd element for accessibility https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd
397+
caption={
398+
IS_MAC
399+
? "⌘ + ⇧ + D"
400+
: _t(ALTERNATE_KEY_NAME[Key.CONTROL]) +
401+
" + " +
402+
_t(ALTERNATE_KEY_NAME[Key.SHIFT]) +
403+
" + D"
410404
}
411405
/>
412406
</UserMenu>

src/components/views/spaces/SpaceTreeLevel.tsx

+5-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ import { NotificationLevel } from "../../../stores/notifications/NotificationLev
4545
import { getKeyBindingsManager } from "../../../KeyBindingsManager";
4646
import { NotificationState } from "../../../stores/notifications/NotificationState";
4747
import SpaceContextMenu from "../context_menus/SpaceContextMenu";
48-
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
4948
import { useRovingTabIndex } from "../../../accessibility/RovingTabIndex";
5049
import { KeyBindingAction } from "../../../accessibility/KeyboardShortcuts";
5150

5251
type ButtonProps<T extends keyof JSX.IntrinsicElements> = Omit<
53-
ComponentProps<typeof AccessibleTooltipButton<T>>,
52+
ComponentProps<typeof AccessibleButton<T>>,
5453
"title" | "onClick" | "size" | "element"
5554
> & {
5655
space?: Room;
@@ -143,17 +142,17 @@ export const SpaceButton = <T extends keyof JSX.IntrinsicElements>({
143142
const onClick = props.onClick ?? (selected && space ? viewSpaceHome : activateSpace);
144143

145144
return (
146-
<AccessibleTooltipButton
145+
<AccessibleButton
147146
{...props}
148147
className={classNames("mx_SpaceButton", className, {
149148
mx_SpaceButton_active: selected,
150149
mx_SpaceButton_hasMenuOpen: menuDisplayed,
151150
mx_SpaceButton_narrow: isNarrow,
152151
})}
153-
title={label}
152+
aria-label={label}
153+
title={!isNarrow || menuDisplayed ? undefined : label}
154154
onClick={onClick}
155155
onContextMenu={openMenu}
156-
forceHide={!isNarrow || menuDisplayed}
157156
ref={handle}
158157
tabIndex={tabIndex}
159158
onFocus={onFocus}
@@ -177,7 +176,7 @@ export const SpaceButton = <T extends keyof JSX.IntrinsicElements>({
177176

178177
{contextMenu}
179178
</div>
180-
</AccessibleTooltipButton>
179+
</AccessibleButton>
181180
);
182181
};
183182

test/components/structures/__snapshots__/SpaceHierarchy-test.tsx.snap

+4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
3232
>
3333
<div
3434
aria-disabled="true"
35+
aria-label="Remove"
3536
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_danger_outline mx_AccessibleButton_disabled"
37+
data-state="closed"
3638
disabled=""
3739
role="button"
3840
tabindex="0"
@@ -41,7 +43,9 @@ exports[`SpaceHierarchy <SpaceHierarchy /> renders 1`] = `
4143
</div>
4244
<div
4345
aria-disabled="true"
46+
aria-label="Mark as not suggested"
4447
class="mx_AccessibleButton mx_AccessibleButton_hasKind mx_AccessibleButton_kind_primary_outline mx_AccessibleButton_disabled"
48+
data-state="closed"
4549
disabled=""
4650
role="button"
4751
tabindex="0"

test/components/views/spaces/__snapshots__/SpacePanel-test.tsx.snap

+10-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
3535
<div
3636
aria-label="Expand"
3737
class="mx_AccessibleButton mx_SpacePanel_toggleCollapse"
38+
data-state="closed"
3839
role="button"
3940
tabindex="0"
4041
/>
@@ -55,6 +56,7 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
5556
<div
5657
aria-label="Home"
5758
class="mx_AccessibleButton mx_SpaceButton mx_SpaceButton_home mx_SpaceButton_narrow"
59+
data-state="closed"
5860
role="button"
5961
tabindex="0"
6062
>
@@ -91,6 +93,7 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
9193
<div
9294
aria-label="Favourites"
9395
class="mx_AccessibleButton mx_SpaceButton mx_SpaceButton_favourites mx_SpaceButton_narrow"
96+
data-state="closed"
9497
role="button"
9598
tabindex="-1"
9699
>
@@ -119,6 +122,7 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
119122
<div
120123
aria-label="People"
121124
class="mx_AccessibleButton mx_SpaceButton mx_SpaceButton_people mx_SpaceButton_narrow"
125+
data-state="closed"
122126
role="button"
123127
tabindex="-1"
124128
>
@@ -147,6 +151,7 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
147151
<div
148152
aria-label="Other rooms"
149153
class="mx_AccessibleButton mx_SpaceButton mx_SpaceButton_orphans mx_SpaceButton_narrow"
154+
data-state="closed"
150155
role="button"
151156
tabindex="-1"
152157
>
@@ -175,6 +180,7 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
175180
<div
176181
aria-label="Conferences"
177182
class="mx_AccessibleButton mx_SpaceButton mx_SpaceButton_videoRooms mx_SpaceButton_narrow"
183+
data-state="closed"
178184
role="button"
179185
tabindex="-1"
180186
>
@@ -203,6 +209,7 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
203209
<div
204210
aria-label="Create a space"
205211
class="mx_AccessibleButton mx_SpaceButton mx_SpaceButton_new mx_SpaceButton_narrow"
212+
data-state="closed"
206213
data-testid="create-space-button"
207214
role="button"
208215
tabindex="-1"
@@ -229,8 +236,8 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
229236
class="mx_ThreadsActivityCentre_container"
230237
>
231238
<button
232-
aria-controls="floating-ui-7"
233-
aria-describedby="floating-ui-7"
239+
aria-controls="floating-ui-35"
240+
aria-describedby="floating-ui-35"
234241
aria-expanded="true"
235242
aria-haspopup="dialog"
236243
aria-label="Threads"
@@ -272,6 +279,7 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
272279
aria-expanded="false"
273280
aria-label="Quick settings"
274281
class="mx_AccessibleButton mx_QuickSettingsButton"
282+
data-state="closed"
275283
role="button"
276284
tabindex="0"
277285
/>

0 commit comments

Comments
 (0)