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

Commit 77a7245

Browse files
authored
Tooltip: Improve the accessibility of the composer and the rich text editor (#12459)
* Use `AccessibleButton` in `RovingAccessibleTooltipButton` * Update snapshots * Update @vector-im/compound-web * Update composer * Update formating buttons * Update snapshots * Remove placement * Update snapshots * Use kbd * Update ``@vector-im/compound-web`
1 parent 6e31f69 commit 77a7245

File tree

9 files changed

+35
-62
lines changed

9 files changed

+35
-62
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"@sentry/browser": "^7.0.0",
7777
"@testing-library/react-hooks": "^8.0.1",
7878
"@vector-im/compound-design-tokens": "^1.2.0",
79-
"@vector-im/compound-web": "^4.1.2",
79+
"@vector-im/compound-web": "^4.2.0",
8080
"@zxcvbn-ts/core": "^3.0.4",
8181
"@zxcvbn-ts/language-common": "^3.0.4",
8282
"@zxcvbn-ts/language-en": "^3.0.2",

res/css/views/rooms/_MessageComposerFormatBar.pcss

-5
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,4 @@ limitations under the License.
102102
font-weight: var(--cpd-font-weight-semibold);
103103
min-width: 54px;
104104
text-align: center;
105-
106-
.mx_MessageComposerFormatBar_tooltipShortcut {
107-
font-size: $font-9px;
108-
opacity: 0.7;
109-
}
110105
}

res/css/views/rooms/wysiwyg_composer/components/_FormattingButtons.pcss

+6-14
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,11 @@ limitations under the License.
6464
}
6565
}
6666

67-
.mx_FormattingButtons_Tooltip {
68-
padding: 0 2px 0 2px;
69-
70-
.mx_FormattingButtons_Tooltip_KeyboardShortcut {
71-
color: $tertiary-content;
72-
73-
kbd {
74-
margin-top: 2px;
75-
text-align: center;
76-
display: inline-block;
77-
text-transform: capitalize;
78-
font-size: 12px;
79-
font-family: Inter, sans-serif;
80-
}
67+
.mx_FormattingButtons_Tooltip_KeyboardShortcut {
68+
kbd {
69+
text-align: center;
70+
display: inline-block;
71+
text-transform: capitalize;
72+
font-family: Inter, sans-serif;
8173
}
8274
}

src/components/views/elements/AccessibleButton.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ type Props<T extends keyof JSX.IntrinsicElements> = DynamicHtmlElementProps<T> &
9292
/**
9393
* The tooltip to show on hover or focus.
9494
*/
95-
title?: string;
95+
title?: TooltipProps["label"];
9696
/**
9797
* The caption is a secondary text displayed under the `title` of the tooltip.
9898
* Only valid when used in conjunction with `title`.
9999
*/
100-
caption?: string;
100+
caption?: TooltipProps["caption"];
101101
/**
102102
* The placement of the tooltip.
103103
*/

src/components/views/rooms/MessageComposer.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { makeRoomPermalink, RoomPermalinkCreator } from "../../../utils/permalin
3535
import E2EIcon from "./E2EIcon";
3636
import SettingsStore from "../../../settings/SettingsStore";
3737
import { aboveLeftOf, MenuProps } from "../../structures/ContextMenu";
38-
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
3938
import ReplyPreview from "./ReplyPreview";
4039
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
4140
import VoiceRecordComposerTile from "./VoiceRecordComposerTile";
@@ -52,7 +51,7 @@ import UIStore, { UI_EVENTS } from "../../../stores/UIStore";
5251
import RoomContext from "../../../contexts/RoomContext";
5352
import { SettingUpdatedPayload } from "../../../dispatcher/payloads/SettingUpdatedPayload";
5453
import MessageComposerButtons from "./MessageComposerButtons";
55-
import { ButtonEvent } from "../elements/AccessibleButton";
54+
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
5655
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
5756
import { isLocalRoom } from "../../../utils/localRoom/isLocalRoom";
5857
import { Features } from "../../../settings/Settings";
@@ -75,7 +74,7 @@ interface ISendButtonProps {
7574

7675
function SendButton(props: ISendButtonProps): JSX.Element {
7776
return (
78-
<AccessibleTooltipButton
77+
<AccessibleButton
7978
className="mx_MessageComposer_sendMessage"
8079
onClick={props.onClick}
8180
title={props.title ?? _t("composer|send_button_title")}

src/components/views/rooms/MessageComposerButtons.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { IEventRelation, Room, MatrixClient, THREAD_RELATION_TYPE, M_POLL_START
1919
import React, { createContext, ReactElement, ReactNode, useContext, useRef } from "react";
2020

2121
import { _t } from "../../../languageHandler";
22-
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
2322
import { CollapsibleButton } from "./CollapsibleButton";
2423
import { MenuProps } from "../../structures/ContextMenu";
2524
import dis from "../../../dispatcher/dispatcher";
@@ -37,7 +36,7 @@ import IconizedContextMenu, { IconizedContextMenuOptionList } from "../context_m
3736
import { EmojiButton } from "./EmojiButton";
3837
import { filterBoolean } from "../../../utils/arrays";
3938
import { useSettingValue } from "../../../hooks/useSettings";
40-
import { ButtonEvent } from "../elements/AccessibleButton";
39+
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
4140

4241
interface IProps {
4342
addEmoji: (emoji: string) => boolean;
@@ -128,7 +127,7 @@ const MessageComposerButtons: React.FC<IProps> = (props: IProps) => {
128127
<UploadButtonContextProvider roomId={room.roomId} relation={props.relation}>
129128
{mainButtons}
130129
{moreButtons.length > 0 && (
131-
<AccessibleTooltipButton
130+
<AccessibleButton
132131
className={moreOptionsClasses}
133132
onClick={props.toggleButtonMenu}
134133
title={_t("quick_settings|sidebar_settings")}

src/components/views/rooms/wysiwyg_composer/components/FormattingButtons.tsx

+16-28
Original file line numberDiff line numberDiff line change
@@ -30,54 +30,42 @@ import { Icon as NumberedListIcon } from "../../../../../../res/img/element-icon
3030
import { Icon as CodeBlockIcon } from "../../../../../../res/img/element-icons/room/composer/code_block.svg";
3131
import { Icon as IndentIcon } from "../../../../../../res/img/element-icons/room/composer/indent_increase.svg";
3232
import { Icon as UnIndentIcon } from "../../../../../../res/img/element-icons/room/composer/indent_decrease.svg";
33-
import AccessibleTooltipButton from "../../../elements/AccessibleTooltipButton";
34-
import { Alignment } from "../../../elements/Tooltip";
35-
import { KeyboardShortcut } from "../../../settings/KeyboardShortcut";
36-
import { KeyCombo } from "../../../../../KeyBindingsManager";
3733
import { _t } from "../../../../../languageHandler";
38-
import { ButtonEvent } from "../../../elements/AccessibleButton";
34+
import AccessibleButton, { ButtonEvent } from "../../../elements/AccessibleButton";
3935
import { openLinkModal } from "./LinkModal";
4036
import { useComposerContext } from "../ComposerContext";
37+
import { KeyboardShortcut } from "../../../settings/KeyboardShortcut";
38+
import { KeyCombo } from "../../../../../KeyBindingsManager";
4139

42-
interface TooltipProps {
43-
label: string;
44-
keyCombo?: KeyCombo;
45-
}
46-
47-
function Tooltip({ label, keyCombo }: TooltipProps): JSX.Element {
48-
return (
49-
<div className="mx_FormattingButtons_Tooltip">
50-
{label}
51-
{keyCombo && (
52-
<KeyboardShortcut value={keyCombo} className="mx_FormattingButtons_Tooltip_KeyboardShortcut" />
53-
)}
54-
</div>
55-
);
56-
}
57-
58-
interface ButtonProps extends TooltipProps {
40+
interface ButtonProps {
5941
icon: ReactNode;
6042
actionState: ActionState;
6143
onClick: MouseEventHandler<HTMLButtonElement>;
44+
label: string;
45+
keyCombo?: KeyCombo;
6246
}
6347

6448
function Button({ label, keyCombo, onClick, actionState, icon }: ButtonProps): JSX.Element {
6549
return (
66-
<AccessibleTooltipButton
50+
<AccessibleButton
6751
element="button"
6852
onClick={onClick as (e: ButtonEvent) => void}
69-
title={label}
53+
aria-label={label}
7054
className={classNames("mx_FormattingButtons_Button", {
7155
mx_FormattingButtons_active: actionState === "reversed",
7256
mx_FormattingButtons_Button_hover: actionState === "enabled",
7357
mx_FormattingButtons_disabled: actionState === "disabled",
7458
})}
75-
tooltip={keyCombo && <Tooltip label={label} keyCombo={keyCombo} />}
76-
forceHide={actionState === "disabled"}
77-
alignment={Alignment.Top}
59+
title={actionState === "disabled" ? undefined : label}
60+
caption={
61+
keyCombo && (
62+
<KeyboardShortcut value={keyCombo} className="mx_FormattingButtons_Tooltip_KeyboardShortcut" />
63+
)
64+
}
65+
placement="top"
7866
>
7967
{icon}
80-
</AccessibleTooltipButton>
68+
</AccessibleButton>
8169
);
8270
}
8371

test/components/views/rooms/wysiwyg_composer/components/FormattingButtons-test.tsx

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

1717
import React from "react";
18-
import { cleanup, render, screen } from "@testing-library/react";
18+
import { cleanup, render, screen, waitFor } from "@testing-library/react";
1919
import userEvent from "@testing-library/user-event";
2020
import { ActionState, ActionTypes, AllActionStates, FormattingFunctions } from "@matrix-org/matrix-wysiwyg";
2121

@@ -135,7 +135,7 @@ describe("FormattingButtons", () => {
135135
const { label } = testCase;
136136

137137
await userEvent.hover(screen.getByLabelText(label));
138-
expect(screen.getByText(label)).toBeInTheDocument();
138+
await waitFor(() => expect(screen.getByText(label)).toBeInTheDocument());
139139
}
140140
});
141141

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -3097,10 +3097,10 @@
30973097
dependencies:
30983098
svg2vectordrawable "^2.9.1"
30993099

3100-
"@vector-im/compound-web@^4.1.2":
3101-
version "4.1.2"
3102-
resolved "https://registry.yarnpkg.com/@vector-im/compound-web/-/compound-web-4.1.2.tgz#d8f9ba523700660942722a800c64406216bbbfea"
3103-
integrity sha512-u/jj8HF8qpX1NU+sh6f/S1B7HUMGcoAGYLH0wc5lVbf6x6elBsYKD0LSa+/8NDPuQqVWMztu76chUsM5slC49w==
3100+
"@vector-im/compound-web@^4.2.0":
3101+
version "4.2.0"
3102+
resolved "https://registry.yarnpkg.com/@vector-im/compound-web/-/compound-web-4.2.0.tgz#16915a5e64c405360fc049ddfa39b5185725f950"
3103+
integrity sha512-VSZxIFToDesjiiCGLOj+DrrKv1I0rtpzJbdylarJXY7REnHzVdgaBBtGm403iJ8KkZ2Rn16Mxe+P1/+VS4yiAA==
31043104
dependencies:
31053105
"@floating-ui/react" "^0.26.9"
31063106
"@floating-ui/react-dom" "^2.0.8"

0 commit comments

Comments
 (0)