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

Commit bec8fdb

Browse files
authored
Tooltip: Improve accessibility for context menus (#12462)
* Update `ContextMenuTooltipButton.tsx` * Fix placement * Update tests * Update space panel snapshot * Remove default placement * Update snapshots * Fix tooltip child rerender * Remove useless props title
1 parent 580bc87 commit bec8fdb

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/accessibility/context_menu/ContextMenuTooltipButton.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ limitations under the License.
1818

1919
import React, { ComponentProps, forwardRef, Ref } from "react";
2020

21-
import AccessibleTooltipButton from "../../components/views/elements/AccessibleTooltipButton";
21+
import AccessibleButton from "../../components/views/elements/AccessibleButton";
2222

23-
type Props<T extends keyof JSX.IntrinsicElements> = ComponentProps<typeof AccessibleTooltipButton<T>> & {
23+
type Props<T extends keyof JSX.IntrinsicElements> = ComponentProps<typeof AccessibleButton<T>> & {
2424
// whether the context menu is currently open
2525
isExpanded: boolean;
2626
};
@@ -31,17 +31,17 @@ export const ContextMenuTooltipButton = forwardRef(function <T extends keyof JSX
3131
ref: Ref<HTMLElement>,
3232
) {
3333
return (
34-
<AccessibleTooltipButton
34+
<AccessibleButton
3535
{...props}
3636
element={element as keyof JSX.IntrinsicElements}
3737
onClick={onClick}
3838
onContextMenu={onContextMenu ?? onClick ?? undefined}
3939
aria-haspopup={true}
4040
aria-expanded={isExpanded}
41-
forceHide={isExpanded}
41+
disableTooltip={isExpanded}
4242
ref={ref}
4343
>
4444
{children}
45-
</AccessibleTooltipButton>
45+
</AccessibleButton>
4646
);
4747
});

src/components/views/elements/AccessibleButton.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ type Props<T extends keyof JSX.IntrinsicElements> = DynamicHtmlElementProps<T> &
106106
* Callback for when the tooltip is opened or closed.
107107
*/
108108
onTooltipOpenChange?: TooltipProps["onOpenChange"];
109+
110+
/**
111+
* Whether the tooltip should be disabled.
112+
*/
113+
disableTooltip?: TooltipProps["disabled"];
109114
};
110115

111116
/**
@@ -140,6 +145,7 @@ const AccessibleButton = forwardRef(function <T extends keyof JSX.IntrinsicEleme
140145
caption,
141146
placement = "right",
142147
onTooltipOpenChange,
148+
disableTooltip,
143149
...restProps
144150
}: Props<T>,
145151
ref: Ref<HTMLElement>,
@@ -217,6 +223,7 @@ const AccessibleButton = forwardRef(function <T extends keyof JSX.IntrinsicEleme
217223
isTriggerInteractive={true}
218224
placement={placement}
219225
onOpenChange={onTooltipOpenChange}
226+
disabled={disableTooltip}
220227
>
221228
{button}
222229
</Tooltip>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ exports[`<SpacePanel /> should show all activated MetaSpaces in the correct orde
229229
class="mx_ThreadsActivityCentre_container"
230230
>
231231
<button
232-
aria-controls="floating-ui-35"
233-
aria-describedby="floating-ui-35"
232+
aria-controls="floating-ui-39"
233+
aria-describedby="floating-ui-39"
234234
aria-expanded="true"
235235
aria-haspopup="dialog"
236236
aria-label="Threads"

0 commit comments

Comments
 (0)