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

Commit 2df946b

Browse files
authored
Tooltip: Use AccessibleButton in RovingAccessibleTooltipButton (#12458)
* Use `AccessibleButton` in `RovingAccessibleTooltipButton` * Update snapshots * Update @vector-im/compound-web * Update playwright * Remove placement
1 parent 3634e66 commit 2df946b

File tree

9 files changed

+34
-49
lines changed

9 files changed

+34
-49
lines changed

package.json

Lines changed: 1 addition & 1 deletion
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.0.2",
79+
"@vector-im/compound-web": "^4.1.0",
8080
"@zxcvbn-ts/core": "^3.0.4",
8181
"@zxcvbn-ts/language-common": "^3.0.4",
8282
"@zxcvbn-ts/language-en": "^3.0.2",
-73 Bytes
Loading

src/accessibility/roving/RovingAccessibleTooltipButton.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,23 @@ limitations under the License.
1616

1717
import React, { ComponentProps } from "react";
1818

19-
import AccessibleTooltipButton from "../../components/views/elements/AccessibleTooltipButton";
2019
import { useRovingTabIndex } from "../RovingTabIndex";
2120
import { Ref } from "./types";
21+
import AccessibleButton from "../../components/views/elements/AccessibleButton";
2222

23-
type Props<T extends keyof JSX.IntrinsicElements> = Omit<
24-
ComponentProps<typeof AccessibleTooltipButton<T>>,
25-
"tabIndex"
26-
> & {
23+
type Props<T extends keyof JSX.IntrinsicElements> = Omit<ComponentProps<typeof AccessibleButton<T>>, "tabIndex"> & {
2724
inputRef?: Ref;
2825
};
2926

30-
// Wrapper to allow use of useRovingTabIndex for simple AccessibleTooltipButtons outside of React Functional Components.
27+
// Wrapper to allow use of useRovingTabIndex for simple AccessibleButtons outside of React Functional Components.
3128
export const RovingAccessibleTooltipButton = <T extends keyof JSX.IntrinsicElements>({
3229
inputRef,
3330
onFocus,
3431
...props
3532
}: Props<T>): JSX.Element => {
3633
const [onFocusInternal, isActive, ref] = useRovingTabIndex(inputRef);
3734
return (
38-
<AccessibleTooltipButton
35+
<AccessibleButton
3936
{...props}
4037
onFocus={(event: React.FocusEvent) => {
4138
onFocusInternal();

src/components/views/messages/MessageActionBar.tsx

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,16 @@ const ReplyInThreadButton: React.FC<IReplyInThreadButton> = ({ mxEvent }) => {
229229
}
230230
};
231231

232+
const title = !hasARelation ? _t("action|reply_in_thread") : _t("threads|error_start_thread_existing_relation");
233+
232234
return (
233235
<RovingAccessibleTooltipButton
234236
className="mx_MessageActionBar_iconButton mx_MessageActionBar_threadButton"
235237
disabled={hasARelation}
236-
tooltip={
237-
<>
238-
<div className="mx_Tooltip_title">
239-
{!hasARelation
240-
? _t("action|reply_in_thread")
241-
: _t("threads|error_start_thread_existing_relation")}
242-
</div>
243-
</>
244-
}
245-
title={!hasARelation ? _t("action|reply_in_thread") : _t("threads|error_start_thread_existing_relation")}
238+
title={title}
246239
onClick={onClick}
247240
onContextMenu={onClick}
241+
placement="left"
248242
>
249243
<ThreadIcon />
250244
</RovingAccessibleTooltipButton>
@@ -509,18 +503,7 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
509503
mx_MessageActionBar_iconButton: true,
510504
mx_MessageActionBar_expandCollapseMessageButton: true,
511505
});
512-
const tooltip = (
513-
<>
514-
<div className="mx_Tooltip_title">
515-
{this.props.isQuoteExpanded
516-
? _t("timeline|mab|collapse_reply_chain")
517-
: _t("timeline|mab|expand_reply_chain")}
518-
</div>
519-
<div className="mx_Tooltip_sub">
520-
{_t(ALTERNATE_KEY_NAME[Key.SHIFT]) + " + " + _t("action|click")}
521-
</div>
522-
</>
523-
);
506+
524507
toolbarOpts.push(
525508
<RovingAccessibleTooltipButton
526509
className={expandClassName}
@@ -529,9 +512,10 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
529512
? _t("timeline|mab|collapse_reply_chain")
530513
: _t("timeline|mab|expand_reply_chain")
531514
}
532-
tooltip={tooltip}
515+
caption={_t(ALTERNATE_KEY_NAME[Key.SHIFT]) + " + " + _t("action|click")}
533516
onClick={this.props.toggleThreadExpanded}
534517
key="expand"
518+
placement="left"
535519
>
536520
{this.props.isQuoteExpanded ? <CollapseMessageIcon /> : <ExpandMessageIcon />}
537521
</RovingAccessibleTooltipButton>,

src/components/views/pips/WidgetPip.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { WidgetType } from "../../../widgets/WidgetType";
3434
import { WidgetMessagingStore } from "../../../stores/widgets/WidgetMessagingStore";
3535
import WidgetUtils from "../../../utils/WidgetUtils";
3636
import { ElementWidgetActions } from "../../../stores/widgets/ElementWidgetActions";
37-
import { Alignment } from "../elements/Tooltip";
3837

3938
interface Props {
4039
widgetId: string;
@@ -128,9 +127,9 @@ export const WidgetPip: FC<Props> = ({ widgetId, room, viewingRoom, onStartMovin
128127
<Toolbar className="mx_WidgetPip_footer">
129128
<RovingAccessibleTooltipButton
130129
onClick={onLeaveClick}
131-
tooltip={_t("action|leave")}
130+
title={_t("action|leave")}
132131
aria-label={_t("action|leave")}
133-
alignment={Alignment.Top}
132+
placement="top"
134133
>
135134
<HangupIcon className="mx_Icon mx_Icon_24" />
136135
</RovingAccessibleTooltipButton>

src/components/views/rooms/MessageComposerFormatBar.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,6 @@ interface IFormatButtonProps {
127127
class FormatButton extends React.PureComponent<IFormatButtonProps> {
128128
public render(): React.ReactNode {
129129
const className = `mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIcon${this.props.icon}`;
130-
let shortcut;
131-
if (this.props.shortcut) {
132-
shortcut = <div className="mx_MessageComposerFormatBar_tooltipShortcut">{this.props.shortcut}</div>;
133-
}
134-
const tooltip = (
135-
<div>
136-
<div className="mx_Tooltip_title">{this.props.label}</div>
137-
<div className="mx_Tooltip_sub">{shortcut}</div>
138-
</div>
139-
);
140130

141131
// element="button" and type="button" are necessary for the buttons to work on WebKit,
142132
// otherwise the text is deselected before onClick can ever be called
@@ -145,8 +135,9 @@ class FormatButton extends React.PureComponent<IFormatButtonProps> {
145135
element="button"
146136
type="button"
147137
onClick={this.props.onClick}
138+
aria-label={this.props.label}
148139
title={this.props.label}
149-
tooltip={tooltip}
140+
caption={this.props.shortcut}
150141
className={className}
151142
/>
152143
);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,41 +397,47 @@ exports[`RoomView for a local room in state NEW should match the snapshot 1`] =
397397
<button
398398
aria-label="Bold"
399399
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconBold"
400+
data-state="closed"
400401
role="button"
401402
tabindex="0"
402403
type="button"
403404
/>
404405
<button
405406
aria-label="Italics"
406407
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconItalic"
408+
data-state="closed"
407409
role="button"
408410
tabindex="-1"
409411
type="button"
410412
/>
411413
<button
412414
aria-label="Strikethrough"
413415
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconStrikethrough"
416+
data-state="closed"
414417
role="button"
415418
tabindex="-1"
416419
type="button"
417420
/>
418421
<button
419422
aria-label="Code block"
420423
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconCode"
424+
data-state="closed"
421425
role="button"
422426
tabindex="-1"
423427
type="button"
424428
/>
425429
<button
426430
aria-label="Quote"
427431
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconQuote"
432+
data-state="closed"
428433
role="button"
429434
tabindex="-1"
430435
type="button"
431436
/>
432437
<button
433438
aria-label="Insert link"
434439
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconInsertLink"
440+
data-state="closed"
435441
role="button"
436442
tabindex="-1"
437443
type="button"
@@ -644,41 +650,47 @@ exports[`RoomView for a local room in state NEW that is encrypted should match t
644650
<button
645651
aria-label="Bold"
646652
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconBold"
653+
data-state="closed"
647654
role="button"
648655
tabindex="0"
649656
type="button"
650657
/>
651658
<button
652659
aria-label="Italics"
653660
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconItalic"
661+
data-state="closed"
654662
role="button"
655663
tabindex="-1"
656664
type="button"
657665
/>
658666
<button
659667
aria-label="Strikethrough"
660668
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconStrikethrough"
669+
data-state="closed"
661670
role="button"
662671
tabindex="-1"
663672
type="button"
664673
/>
665674
<button
666675
aria-label="Code block"
667676
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconCode"
677+
data-state="closed"
668678
role="button"
669679
tabindex="-1"
670680
type="button"
671681
/>
672682
<button
673683
aria-label="Quote"
674684
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconQuote"
685+
data-state="closed"
675686
role="button"
676687
tabindex="-1"
677688
type="button"
678689
/>
679690
<button
680691
aria-label="Insert link"
681692
class="mx_AccessibleButton mx_MessageComposerFormatBar_button mx_MessageComposerFormatBar_buttonIconInsertLink"
693+
data-state="closed"
682694
role="button"
683695
tabindex="-1"
684696
type="button"

test/components/views/rooms/EventTile/__snapshots__/EventTileThreadToolbar-test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ exports[`EventTileThreadToolbar renders 1`] = `
1111
<div
1212
aria-label="View in room"
1313
class="mx_AccessibleButton mx_MessageActionBar_iconButton"
14+
data-state="closed"
1415
role="button"
1516
tabindex="0"
1617
>
@@ -19,6 +20,7 @@ exports[`EventTileThreadToolbar renders 1`] = `
1920
<div
2021
aria-label="Copy link to thread"
2122
class="mx_AccessibleButton mx_MessageActionBar_iconButton"
23+
data-state="closed"
2224
role="button"
2325
tabindex="-1"
2426
>

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,10 +3060,10 @@
30603060
dependencies:
30613061
svg2vectordrawable "^2.9.1"
30623062

3063-
"@vector-im/compound-web@^4.0.2":
3064-
version "4.0.2"
3065-
resolved "https://registry.yarnpkg.com/@vector-im/compound-web/-/compound-web-4.0.2.tgz#cd89ca076b9b0528718e45110a4c8126e7556c63"
3066-
integrity sha512-MBqmSbtcWC6KJjuTWPZ6FYc83YrUJ9dOageUdbayjhVGZ/de/a+nl/vPIAX+5ic2QWUN7nn9hujfzQF69mbIeg==
3063+
"@vector-im/compound-web@^4.1.0":
3064+
version "4.1.0"
3065+
resolved "https://registry.yarnpkg.com/@vector-im/compound-web/-/compound-web-4.1.0.tgz#45fa22e4e91b5fd4c2f535e040072990d5a33712"
3066+
integrity sha512-FQSJK7PaJ3dR1c1Q3TYVSShJBl9TwlrhKadnTWsPIX6xE+rvCAeujE50QbcEWdDlWeaJ9Hi0bVPlEssJ+eRwtQ==
30673067
dependencies:
30683068
"@floating-ui/react" "^0.26.9"
30693069
"@floating-ui/react-dom" "^2.0.8"

0 commit comments

Comments
 (0)