Switch AccessibleButton and derivatives to using forwardRef (#12054)

* Prevent Cypress typechecking react-sdk components without strict mode

This prevented us from switching to `forwardRef` in a bunch of places
due to it behaving different with & without strict mode.

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Update global.d.ts

* Switch AccessibleButton and derivatives to using `forwardRef`

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Add missing ref={ref}

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Ensure RefObjects are used consistently

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Re-add WysiwygAutocomplete displayname

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Fix forwardRef types

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Add comments

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Remove unused export

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Readd comment

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate types & comments

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Apply suggestions from code review

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

* Add comment

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Iterate

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

* Improve comment

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>

---------

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
Michael Telatynski 2023-12-21 08:50:42 +00:00 committed by GitHub
parent 0a881e2123
commit f632e2124f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 102 additions and 95 deletions

View file

@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React, { ComponentProps } from "react"; import React, { ComponentProps, forwardRef, Ref } from "react";
import AccessibleButton from "../../components/views/elements/AccessibleButton"; import AccessibleButton from "../../components/views/elements/AccessibleButton";
@ -27,14 +27,10 @@ type Props<T extends keyof JSX.IntrinsicElements> = ComponentProps<typeof Access
}; };
// Semantic component for representing the AccessibleButton which launches a <ContextMenu /> // Semantic component for representing the AccessibleButton which launches a <ContextMenu />
export const ContextMenuButton = <T extends keyof JSX.IntrinsicElements>({ export const ContextMenuButton = forwardRef(function <T extends keyof JSX.IntrinsicElements>(
label, { label, isExpanded, children, onClick, onContextMenu, ...props }: Props<T>,
isExpanded, ref: Ref<HTMLElement>,
children, ) {
onClick,
onContextMenu,
...props
}: Props<T>): JSX.Element => {
return ( return (
<AccessibleButton <AccessibleButton
{...props} {...props}
@ -44,8 +40,9 @@ export const ContextMenuButton = <T extends keyof JSX.IntrinsicElements>({
aria-label={label} aria-label={label}
aria-haspopup={true} aria-haspopup={true}
aria-expanded={isExpanded} aria-expanded={isExpanded}
ref={ref}
> >
{children} {children}
</AccessibleButton> </AccessibleButton>
); );
}; });

View file

@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React, { ComponentProps } from "react"; import React, { ComponentProps, forwardRef, Ref } from "react";
import AccessibleTooltipButton from "../../components/views/elements/AccessibleTooltipButton"; import AccessibleTooltipButton from "../../components/views/elements/AccessibleTooltipButton";
@ -26,13 +26,10 @@ type Props<T extends keyof JSX.IntrinsicElements> = ComponentProps<typeof Access
}; };
// Semantic component for representing the AccessibleButton which launches a <ContextMenu /> // Semantic component for representing the AccessibleButton which launches a <ContextMenu />
export const ContextMenuTooltipButton = <T extends keyof JSX.IntrinsicElements>({ export const ContextMenuTooltipButton = forwardRef(function <T extends keyof JSX.IntrinsicElements>(
isExpanded, { isExpanded, children, onClick, onContextMenu, ...props }: Props<T>,
children, ref: Ref<HTMLElement>,
onClick, ) {
onContextMenu,
...props
}: Props<T>): JSX.Element => {
return ( return (
<AccessibleTooltipButton <AccessibleTooltipButton
{...props} {...props}
@ -41,8 +38,9 @@ export const ContextMenuTooltipButton = <T extends keyof JSX.IntrinsicElements>(
aria-haspopup={true} aria-haspopup={true}
aria-expanded={isExpanded} aria-expanded={isExpanded}
forceHide={isExpanded} forceHide={isExpanded}
ref={ref}
> >
{children} {children}
</AccessibleTooltipButton> </AccessibleTooltipButton>
); );
}; });

View file

@ -48,7 +48,7 @@ export const RovingAccessibleButton = <T extends keyof JSX.IntrinsicElements>({
if (focusOnMouseOver) onFocusInternal(); if (focusOnMouseOver) onFocusInternal();
onMouseOver?.(event); onMouseOver?.(event);
}} }}
inputRef={ref} ref={ref}
tabIndex={isActive ? 0 : -1} tabIndex={isActive ? 0 : -1}
/> />
); );

View file

@ -41,7 +41,7 @@ export const RovingAccessibleTooltipButton = <T extends keyof JSX.IntrinsicEleme
onFocusInternal(); onFocusInternal();
onFocus?.(event); onFocus?.(event);
}} }}
inputRef={ref} ref={ref}
tabIndex={isActive ? 0 : -1} tabIndex={isActive ? 0 : -1}
/> />
); );

View file

@ -195,7 +195,7 @@ export function GenericDropdownMenu<T>({
<> <>
<ContextMenuButton <ContextMenuButton
className="mx_GenericDropdownMenu_button" className="mx_GenericDropdownMenu_button"
inputRef={button} ref={button}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
onClick={(ev: ButtonEvent) => { onClick={(ev: ButtonEvent) => {
openMenu(); openMenu();

View file

@ -15,6 +15,7 @@ limitations under the License.
*/ */
import React, { import React, {
ComponentProps,
Dispatch, Dispatch,
KeyboardEvent, KeyboardEvent,
KeyboardEventHandler, KeyboardEventHandler,
@ -349,7 +350,7 @@ const Tile: React.FC<ITileProps> = ({
})} })}
onClick={hasPermissions && onToggleClick ? onToggleClick : onPreviewClick} onClick={hasPermissions && onToggleClick ? onToggleClick : onPreviewClick}
onKeyDown={onKeyDown} onKeyDown={onKeyDown}
inputRef={ref} ref={ref}
onFocus={onFocus} onFocus={onFocus}
tabIndex={isActive ? 0 : -1} tabIndex={isActive ? 0 : -1}
> >
@ -664,7 +665,7 @@ const ManageButtons: React.FC<IManageButtonsProps> = ({ hierarchy, selected, set
const disabled = !selectedRelations.length || removing || saving; const disabled = !selectedRelations.length || removing || saving;
let Button: React.ComponentType<React.ComponentProps<typeof AccessibleButton>> = AccessibleButton; let Button: React.ComponentType<React.ComponentProps<typeof AccessibleButton>> = AccessibleButton;
let props = {}; let props: Partial<ComponentProps<typeof AccessibleTooltipButton>> = {};
if (!selectedRelations.length) { if (!selectedRelations.length) {
Button = AccessibleTooltipButton; Button = AccessibleTooltipButton;
props = { props = {

View file

@ -196,7 +196,7 @@ const SpaceLandingAddButton: React.FC<{ space: Room }> = ({ space }) => {
<> <>
<ContextMenuButton <ContextMenuButton
kind="primary" kind="primary"
inputRef={handle} ref={handle}
onClick={openMenu} onClick={openMenu}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
label={_t("action|add")} label={_t("action|add")}

View file

@ -118,7 +118,7 @@ export const ThreadPanelHeader: React.FC<{
<> <>
<ContextMenuButton <ContextMenuButton
className="mx_ThreadPanel_dropdown" className="mx_ThreadPanel_dropdown"
inputRef={button} ref={button}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
onClick={(ev: ButtonEvent) => { onClick={(ev: ButtonEvent) => {
openMenu(); openMenu();

View file

@ -453,7 +453,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
<ContextMenuButton <ContextMenuButton
className="mx_UserMenu_contextMenuButton" className="mx_UserMenu_contextMenuButton"
onClick={this.onOpenMenuClick} onClick={this.onOpenMenuClick}
inputRef={this.buttonRef} ref={this.buttonRef}
label={_t("a11y|user_menu")} label={_t("a11y|user_menu")}
isExpanded={!!this.state.contextMenuPosition} isExpanded={!!this.state.contextMenuPosition}
onContextMenu={this.onContextMenu} onContextMenu={this.onContextMenu}

View file

@ -21,7 +21,10 @@ import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
import { _t } from "../../../languageHandler"; import { _t } from "../../../languageHandler";
import { Playback, PlaybackState } from "../../../audio/Playback"; import { Playback, PlaybackState } from "../../../audio/Playback";
type Props = Omit<ComponentProps<typeof AccessibleTooltipButton>, "title" | "onClick" | "disabled" | "element"> & { type Props = Omit<
ComponentProps<typeof AccessibleTooltipButton>,
"title" | "onClick" | "disabled" | "element" | "ref"
> & {
// Playback instance to manipulate. Cannot change during the component lifecycle. // Playback instance to manipulate. Cannot change during the component lifecycle.
playback: Playback; playback: Playback;

View file

@ -974,7 +974,7 @@ export class FallbackAuthEntry extends React.Component<IAuthEntryProps> {
} }
return ( return (
<div> <div>
<AccessibleButton kind="link" inputRef={this.fallbackButton} onClick={this.onShowFallbackClick}> <AccessibleButton kind="link" ref={this.fallbackButton} onClick={this.onShowFallbackClick}>
{_t("auth|uia|fallback_button")} {_t("auth|uia|fallback_button")}
</AccessibleButton> </AccessibleButton>
{errorSection} {errorSection}

View file

@ -39,7 +39,7 @@ export const KebabContextMenu: React.FC<KebabContextMenuProps> = ({ options, tit
return ( return (
<> <>
<ContextMenuButton {...props} onClick={openMenu} title={title} isExpanded={menuDisplayed} inputRef={button}> <ContextMenuButton {...props} onClick={openMenu} title={title} isExpanded={menuDisplayed} ref={button}>
<ContextMenuIcon className="mx_KebabContextMenu_icon" /> <ContextMenuIcon className="mx_KebabContextMenu_icon" />
</ContextMenuButton> </ContextMenuButton>
{menuDisplayed && ( {menuDisplayed && (

View file

@ -94,7 +94,7 @@ const ThreadListContextMenu: React.FC<ThreadListContextMenuProps> = ({
onClick={openMenu} onClick={openMenu}
title={_t("right_panel|thread_list|context_menu_label")} title={_t("right_panel|thread_list|context_menu_label")}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
inputRef={button} ref={button}
data-testid="threadlist-dropdown-button" data-testid="threadlist-dropdown-button"
/> />
{menuDisplayed && ( {menuDisplayed && (

View file

@ -35,7 +35,7 @@ export const Option: React.FC<OptionProps> = ({ inputRef, children, endAdornment
{...props} {...props}
className={classNames(className, "mx_SpotlightDialog_option")} className={classNames(className, "mx_SpotlightDialog_option")}
onFocus={onFocus} onFocus={onFocus}
inputRef={ref} ref={ref}
tabIndex={-1} tabIndex={-1}
aria-selected={isActive} aria-selected={isActive}
role="option" role="option"

View file

@ -32,7 +32,7 @@ export const TooltipOption: React.FC<TooltipOptionProps> = ({ inputRef, classNam
{...props} {...props}
className={classNames(className, "mx_SpotlightDialog_option")} className={classNames(className, "mx_SpotlightDialog_option")}
onFocus={onFocus} onFocus={onFocus}
inputRef={ref} ref={ref}
tabIndex={-1} tabIndex={-1}
aria-selected={isActive} aria-selected={isActive}
role="option" role="option"

View file

@ -14,7 +14,7 @@
limitations under the License. limitations under the License.
*/ */
import React, { HTMLAttributes, InputHTMLAttributes } from "react"; import React, { forwardRef, FunctionComponent, HTMLAttributes, InputHTMLAttributes, Ref } from "react";
import classnames from "classnames"; import classnames from "classnames";
import { getKeyBindingsManager } from "../../../KeyBindingsManager"; import { getKeyBindingsManager } from "../../../KeyBindingsManager";
@ -66,7 +66,6 @@ type DynamicElementProps<T extends keyof JSX.IntrinsicElements> = Partial<
* Extends props accepted by the underlying element specified using the `element` prop. * Extends props accepted by the underlying element specified using the `element` prop.
*/ */
type Props<T extends keyof JSX.IntrinsicElements> = DynamicHtmlElementProps<T> & { type Props<T extends keyof JSX.IntrinsicElements> = DynamicHtmlElementProps<T> & {
inputRef?: React.Ref<Element>;
/** /**
* The base element type. "div" by default. * The base element type. "div" by default.
*/ */
@ -101,22 +100,26 @@ interface RenderedElementProps extends React.InputHTMLAttributes<Element> {
* as a button. Identifies the element as a button, setting proper tab * as a button. Identifies the element as a button, setting proper tab
* indexing and keyboard activation behavior. * indexing and keyboard activation behavior.
* *
* If a ref is passed, it will be forwarded to the rendered element as specified using the `element` prop.
*
* @param {Object} props react element properties * @param {Object} props react element properties
* @returns {Object} rendered react * @returns {Object} rendered react
*/ */
export default function AccessibleButton<T extends keyof JSX.IntrinsicElements>({ const AccessibleButton = forwardRef(function <T extends keyof JSX.IntrinsicElements>(
element = "div" as T, {
onClick, element = "div" as T,
children, onClick,
kind, children,
disabled, kind,
inputRef, disabled,
className, className,
onKeyDown, onKeyDown,
onKeyUp, onKeyUp,
triggerOnMouseDown, triggerOnMouseDown,
...restProps ...restProps
}: Props<T>): JSX.Element { }: Props<T>,
ref: Ref<HTMLElement>,
): JSX.Element {
const newProps: RenderedElementProps = restProps; const newProps: RenderedElementProps = restProps;
if (disabled) { if (disabled) {
newProps["aria-disabled"] = true; newProps["aria-disabled"] = true;
@ -170,7 +173,7 @@ export default function AccessibleButton<T extends keyof JSX.IntrinsicElements>(
} }
// Pass through the ref - used for keyboard shortcut access to some buttons // Pass through the ref - used for keyboard shortcut access to some buttons
newProps.ref = inputRef; newProps.ref = ref;
newProps.className = classnames("mx_AccessibleButton", className, { newProps.className = classnames("mx_AccessibleButton", className, {
mx_AccessibleButton_hasKind: kind, mx_AccessibleButton_hasKind: kind,
@ -180,11 +183,13 @@ export default function AccessibleButton<T extends keyof JSX.IntrinsicElements>(
// React.createElement expects InputHTMLAttributes // React.createElement expects InputHTMLAttributes
return React.createElement(element, newProps, children); return React.createElement(element, newProps, children);
} });
AccessibleButton.defaultProps = { // Type assertion required due to forwardRef type workaround in react.d.ts
(AccessibleButton as FunctionComponent).defaultProps = {
role: "button", role: "button",
tabIndex: 0, tabIndex: 0,
}; };
(AccessibleButton as FunctionComponent).displayName = "AccessibleButton";
AccessibleButton.displayName = "AccessibleButton"; export default AccessibleButton;

View file

@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React, { SyntheticEvent, FocusEvent, useEffect, useState } from "react"; import React, { SyntheticEvent, FocusEvent, forwardRef, useEffect, Ref, useState, ComponentProps } from "react";
import AccessibleButton from "./AccessibleButton"; import AccessibleButton from "./AccessibleButton";
import Tooltip, { Alignment } from "./Tooltip"; import Tooltip, { Alignment } from "./Tooltip";
@ -25,7 +25,7 @@ import Tooltip, { Alignment } from "./Tooltip";
* *
* Extends that of {@link AccessibleButton}. * Extends that of {@link AccessibleButton}.
*/ */
type Props<T extends keyof JSX.IntrinsicElements> = React.ComponentProps<typeof AccessibleButton<T>> & { type Props<T extends keyof JSX.IntrinsicElements> = ComponentProps<typeof AccessibleButton<T>> & {
/** /**
* Title to show in the tooltip and use as aria-label * Title to show in the tooltip and use as aria-label
*/ */
@ -60,16 +60,10 @@ type Props<T extends keyof JSX.IntrinsicElements> = React.ComponentProps<typeof
onHideTooltip?(ev: SyntheticEvent): void; onHideTooltip?(ev: SyntheticEvent): void;
}; };
function AccessibleTooltipButton<T extends keyof JSX.IntrinsicElements>({ const AccessibleTooltipButton = forwardRef(function <T extends keyof JSX.IntrinsicElements>(
title, { title, tooltip, children, forceHide, alignment, onHideTooltip, tooltipClassName, ...props }: Props<T>,
tooltip, ref: Ref<HTMLElement>,
children, ) {
forceHide,
alignment,
onHideTooltip,
tooltipClassName,
...props
}: Props<T>): JSX.Element {
const [hover, setHover] = useState(false); const [hover, setHover] = useState(false);
useEffect(() => { useEffect(() => {
@ -108,12 +102,13 @@ function AccessibleTooltipButton<T extends keyof JSX.IntrinsicElements>({
onFocus={onFocus} onFocus={onFocus}
onBlur={hideTooltip} onBlur={hideTooltip}
aria-label={title || props["aria-label"]} aria-label={title || props["aria-label"]}
ref={ref}
> >
{children} {children}
{props.label} {props.label}
{(tooltip || title) && tip} {(tooltip || title) && tip}
</AccessibleButton> </AccessibleButton>
); );
} });
export default AccessibleTooltipButton; export default AccessibleTooltipButton;

View file

@ -789,7 +789,7 @@ export default class AppTile extends React.Component<IProps, IState> {
className="mx_AppTileMenuBar_widgets_button" className="mx_AppTileMenuBar_widgets_button"
label={_t("common|options")} label={_t("common|options")}
isExpanded={this.state.menuDisplayed} isExpanded={this.state.menuDisplayed}
inputRef={this.contextMenuButton} ref={this.contextMenuButton}
onClick={this.onContextMenuClick} onClick={this.onContextMenuClick}
> >
<MenuIcon className="mx_Icon mx_Icon_12" /> <MenuIcon className="mx_Icon mx_Icon_12" />

View file

@ -392,7 +392,7 @@ export default class Dropdown extends React.Component<DropdownProps, IState> {
aria-haspopup="listbox" aria-haspopup="listbox"
aria-expanded={this.state.expanded} aria-expanded={this.state.expanded}
disabled={this.props.disabled} disabled={this.props.disabled}
inputRef={this.buttonRef} ref={this.buttonRef}
aria-label={this.props.label} aria-label={this.props.label}
aria-describedby={`${this.props.id}_value`} aria-describedby={`${this.props.id}_value`}
aria-owns={`${this.props.id}_input`} aria-owns={`${this.props.id}_input`}

View file

@ -506,7 +506,7 @@ export default class ImageView extends React.Component<IProps, IState> {
className="mx_ImageView_button mx_ImageView_button_more" className="mx_ImageView_button mx_ImageView_button_more"
title={_t("common|options")} title={_t("common|options")}
onClick={this.onOpenContextMenu} onClick={this.onOpenContextMenu}
inputRef={this.contextMenuButton} ref={this.contextMenuButton}
isExpanded={this.state.contextMenuDisplayed} isExpanded={this.state.contextMenuDisplayed}
/> />
); );

View file

@ -248,7 +248,7 @@ export default class PollCreateDialog extends ScrollableBaseModal<IProps, IState
disabled={this.state.busy || this.state.options.length >= MAX_OPTIONS} disabled={this.state.busy || this.state.options.length >= MAX_OPTIONS}
kind="secondary" kind="secondary"
className="mx_PollCreateDialog_addOption" className="mx_PollCreateDialog_addOption"
inputRef={this.addOptionRef} ref={this.addOptionRef}
> >
{_t("poll|options_add_button")} {_t("poll|options_add_button")}
</AccessibleButton> </AccessibleButton>

View file

@ -28,7 +28,7 @@ import {
import defaultDispatcher from "../../../dispatcher/dispatcher"; import defaultDispatcher from "../../../dispatcher/dispatcher";
import type { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; import type { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
import { Action } from "../../../dispatcher/actions"; import { Action } from "../../../dispatcher/actions";
import { AccessibleButtonKind, ButtonEvent } from "../elements/AccessibleButton"; import type { AccessibleButtonKind, ButtonEvent } from "../elements/AccessibleButton";
import MemberAvatar from "../avatars/MemberAvatar"; import MemberAvatar from "../avatars/MemberAvatar";
import { LiveContentSummary, LiveContentType } from "../rooms/LiveContentSummary"; import { LiveContentSummary, LiveContentType } from "../rooms/LiveContentSummary";
import FacePile from "../elements/FacePile"; import FacePile from "../elements/FacePile";

View file

@ -126,7 +126,7 @@ const OptionsButton: React.FC<IOptionsButtonProps> = ({
onClick={onOptionsClick} onClick={onOptionsClick}
onContextMenu={onOptionsClick} onContextMenu={onOptionsClick}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
inputRef={button} ref={button}
onFocus={onFocus} onFocus={onFocus}
tabIndex={isActive ? 0 : -1} tabIndex={isActive ? 0 : -1}
> >
@ -183,7 +183,7 @@ const ReactButton: React.FC<IReactButtonProps> = ({ mxEvent, reactions, onFocusC
onClick={onClick} onClick={onClick}
onContextMenu={onClick} onContextMenu={onClick}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
inputRef={button} ref={button}
onFocus={onFocus} onFocus={onFocus}
tabIndex={isActive ? 0 : -1} tabIndex={isActive ? 0 : -1}
> >

View file

@ -61,7 +61,7 @@ const ReactButton: React.FC<IProps> = ({ mxEvent, reactions }) => {
openMenu(); openMenu();
}} }}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
inputRef={button} ref={button}
/> />
{contextMenu} {contextMenu}

View file

@ -78,7 +78,7 @@ const WidgetCard: React.FC<IProps> = ({ room, widgetId, onClose }) => {
</Heading> </Heading>
<ContextMenuButton <ContextMenuButton
className="mx_BaseCard_header_title_button--option" className="mx_BaseCard_header_title_button--option"
inputRef={handle} ref={handle}
onClick={openMenu} onClick={openMenu}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
label={_t("common|options")} label={_t("common|options")}

View file

@ -17,30 +17,38 @@ limitations under the License.
import React, { ComponentProps, useContext } from "react"; import React, { ComponentProps, useContext } from "react";
import classNames from "classnames"; import classNames from "classnames";
import AccessibleButton from "../elements/AccessibleButton";
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
import { MenuItem } from "../../structures/ContextMenu";
import { OverflowMenuContext } from "./MessageComposerButtons"; import { OverflowMenuContext } from "./MessageComposerButtons";
import { IconizedContextMenuOption } from "../context_menus/IconizedContextMenu"; import { IconizedContextMenuOption } from "../context_menus/IconizedContextMenu";
import { Ref } from "../../../accessibility/roving/types";
interface ICollapsibleButtonProps extends ComponentProps<typeof MenuItem> { interface Props extends Omit<ComponentProps<typeof AccessibleButton>, "element"> {
inputRef?: Ref;
title: string; title: string;
iconClassName: string; iconClassName: string;
} }
export const CollapsibleButton: React.FC<ICollapsibleButtonProps> = ({ export const CollapsibleButton: React.FC<Props> = ({
title, title,
children, children,
className, className,
iconClassName, iconClassName,
inputRef,
...props ...props
}) => { }) => {
const inOverflowMenu = !!useContext(OverflowMenuContext); const inOverflowMenu = !!useContext(OverflowMenuContext);
if (inOverflowMenu) { if (inOverflowMenu) {
return <IconizedContextMenuOption {...props} iconClassName={iconClassName} label={title} />; return <IconizedContextMenuOption {...props} iconClassName={iconClassName} label={title} inputRef={inputRef} />;
} }
return ( return (
<AccessibleTooltipButton {...props} title={title} className={classNames(className, iconClassName)}> <AccessibleTooltipButton
{...props}
title={title}
className={classNames(className, iconClassName)}
ref={inputRef}
>
{children} {children}
</AccessibleTooltipButton> </AccessibleTooltipButton>
); );

View file

@ -234,7 +234,7 @@ const VideoCallButton: FC<VideoCallButtonProps> = ({ room, busy, setBusy, behavi
return ( return (
<> <>
<AccessibleTooltipButton <AccessibleTooltipButton
inputRef={buttonRef} ref={buttonRef}
className="mx_LegacyRoomHeader_button mx_LegacyRoomHeader_videoCallButton" className="mx_LegacyRoomHeader_button mx_LegacyRoomHeader_videoCallButton"
onClick={onClick} onClick={onClick}
title={_t("voip|video_call")} title={_t("voip|video_call")}
@ -439,7 +439,7 @@ const CallLayoutSelector: FC<CallLayoutSelectorProps> = ({ call }) => {
return ( return (
<> <>
<AccessibleTooltipButton <AccessibleTooltipButton
inputRef={buttonRef} ref={buttonRef}
className={classNames("mx_LegacyRoomHeader_button", { className={classNames("mx_LegacyRoomHeader_button", {
"mx_LegacyRoomHeader_layoutButton--freedom": layout === Layout.Tile, "mx_LegacyRoomHeader_layoutButton--freedom": layout === Layout.Tile,
"mx_LegacyRoomHeader_layoutButton--spotlight": layout === Layout.Spotlight, "mx_LegacyRoomHeader_layoutButton--spotlight": layout === Layout.Spotlight,

View file

@ -188,7 +188,7 @@ export function ReadReceiptGroup({
<div className="mx_ReadReceiptGroup" role="group" aria-label={_t("timeline|read_receipts_label")}> <div className="mx_ReadReceiptGroup" role="group" aria-label={_t("timeline|read_receipts_label")}>
<AccessibleButton <AccessibleButton
className="mx_ReadReceiptGroup_button" className="mx_ReadReceiptGroup_button"
inputRef={button} ref={button}
aria-label={tooltipText} aria-label={tooltipText}
aria-haspopup="true" aria-haspopup="true"
onClick={openMenu} onClick={openMenu}

View file

@ -54,7 +54,7 @@ const RoomBreadcrumbTile: React.FC<{ room: Room; onClick: (ev: ButtonEvent) => v
title={room.name} title={room.name}
tooltipClassName="mx_RoomBreadcrumbs_Tooltip" tooltipClassName="mx_RoomBreadcrumbs_Tooltip"
onFocus={onFocus} onFocus={onFocus}
inputRef={ref} ref={ref}
tabIndex={isActive ? 0 : -1} tabIndex={isActive ? 0 : -1}
> >
<DecoratedRoomAvatar <DecoratedRoomAvatar

View file

@ -173,7 +173,7 @@ const DmAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex, dispatcher = default
aria-label={_t("action|add_people")} aria-label={_t("action|add_people")}
title={_t("action|add_people")} title={_t("action|add_people")}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
inputRef={handle} ref={handle}
/> />
{contextMenu} {contextMenu}
@ -356,7 +356,7 @@ const UntaggedAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex }) => {
aria-label={_t("room_list|add_room_label")} aria-label={_t("room_list|add_room_label")}
title={_t("room_list|add_room_label")} title={_t("room_list|add_room_label")}
isExpanded={menuDisplayed} isExpanded={menuDisplayed}
inputRef={handle} ref={handle}
/> />
{contextMenu} {contextMenu}

View file

@ -389,7 +389,7 @@ const RoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
let contextMenuButton: JSX.Element = <div className="mx_RoomListHeader_contextLessTitle">{title}</div>; let contextMenuButton: JSX.Element = <div className="mx_RoomListHeader_contextLessTitle">{title}</div>;
if (canShowMainMenu) { if (canShowMainMenu) {
const commonProps = { const commonProps = {
inputRef: mainMenuHandle, ref: mainMenuHandle,
onClick: openMainMenu, onClick: openMainMenu,
isExpanded: mainMenuDisplayed, isExpanded: mainMenuDisplayed,
className: "mx_RoomListHeader_contextMenuButton", className: "mx_RoomListHeader_contextMenuButton",
@ -418,7 +418,7 @@ const RoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
) : null} ) : null}
{canShowPlusMenu && ( {canShowPlusMenu && (
<ContextMenuTooltipButton <ContextMenuTooltipButton
inputRef={plusMenuHandle} ref={plusMenuHandle}
onClick={openPlusMenu} onClick={openPlusMenu}
isExpanded={plusMenuDisplayed} isExpanded={plusMenuDisplayed}
className="mx_RoomListHeader_plusButton" className="mx_RoomListHeader_plusButton"

View file

@ -709,7 +709,7 @@ export default class RoomSublist extends React.Component<IProps, IState> {
<div className="mx_RoomSublist_stickable"> <div className="mx_RoomSublist_stickable">
<Button <Button
onFocus={onFocus} onFocus={onFocus}
inputRef={ref} ref={ref}
tabIndex={tabIndex} tabIndex={tabIndex}
className="mx_RoomSublist_headerText" className="mx_RoomSublist_headerText"
aria-expanded={this.state.isExpanded} aria-expanded={this.state.isExpanded}

View file

@ -478,7 +478,7 @@ export class RoomTile extends React.PureComponent<ClassProps, State> {
{...props} {...props}
onFocus={onFocus} onFocus={onFocus}
tabIndex={isActive ? 0 : -1} tabIndex={isActive ? 0 : -1}
inputRef={ref} ref={ref}
className={classes} className={classes}
onClick={this.onTileClick} onClick={this.onTileClick}
onContextMenu={this.onContextMenu} onContextMenu={this.onContextMenu}

View file

@ -134,7 +134,7 @@ const QuickSettingsButton: React.FC<{
className={classNames("mx_QuickSettingsButton", { expanded: !isPanelCollapsed })} className={classNames("mx_QuickSettingsButton", { expanded: !isPanelCollapsed })}
onClick={openMenu} onClick={openMenu}
title={_t("quick_settings|title")} title={_t("quick_settings|title")}
inputRef={handle} ref={handle}
forceHide={!isPanelCollapsed} forceHide={!isPanelCollapsed}
aria-expanded={!isPanelCollapsed} aria-expanded={!isPanelCollapsed}
> >

View file

@ -154,7 +154,7 @@ export const SpaceButton = <T extends keyof JSX.IntrinsicElements>({
onClick={onClick} onClick={onClick}
onContextMenu={openMenu} onContextMenu={openMenu}
forceHide={!isNarrow || menuDisplayed} forceHide={!isNarrow || menuDisplayed}
inputRef={handle} ref={handle}
tabIndex={tabIndex} tabIndex={tabIndex}
onFocus={onFocus} onFocus={onFocus}
> >

View file

@ -101,7 +101,7 @@ const DeviceButton: FC<DeviceButtonProps> = ({
> >
<AccessibleTooltipButton <AccessibleTooltipButton
className={`mx_CallView_deviceButton mx_CallView_deviceButton_${kind}`} className={`mx_CallView_deviceButton mx_CallView_deviceButton_${kind}`}
inputRef={buttonRef} ref={buttonRef}
title={muted ? mutedTitle : unmutedTitle} title={muted ? mutedTitle : unmutedTitle}
alignment={Alignment.Top} alignment={Alignment.Top}
onClick={toggle} onClick={toggle}

View file

@ -92,7 +92,7 @@ const LegacyCallViewDropdownButton: React.FC<IDropdownButtonProps> = ({ state, d
return ( return (
<LegacyCallViewToggleButton <LegacyCallViewToggleButton
inputRef={buttonRef} ref={buttonRef}
forceHide={menuDisplayed || hoveringDropdown} forceHide={menuDisplayed || hoveringDropdown}
state={state} state={state}
{...props} {...props}
@ -265,7 +265,7 @@ export default class LegacyCallViewButtons extends React.Component<IProps, IStat
{this.props.buttonsVisibility.dialpad && ( {this.props.buttonsVisibility.dialpad && (
<ContextMenuTooltipButton <ContextMenuTooltipButton
className="mx_LegacyCallViewButtons_button mx_LegacyCallViewButtons_dialpad" className="mx_LegacyCallViewButtons_button mx_LegacyCallViewButtons_dialpad"
inputRef={this.dialpadButton} ref={this.dialpadButton}
onClick={this.onDialpadClick} onClick={this.onDialpadClick}
isExpanded={this.state.showDialpad} isExpanded={this.state.showDialpad}
title={_t("voip|dialpad")} title={_t("voip|dialpad")}
@ -312,7 +312,7 @@ export default class LegacyCallViewButtons extends React.Component<IProps, IStat
<ContextMenuTooltipButton <ContextMenuTooltipButton
className="mx_LegacyCallViewButtons_button mx_LegacyCallViewButtons_button_more" className="mx_LegacyCallViewButtons_button mx_LegacyCallViewButtons_button_more"
onClick={this.onMoreClick} onClick={this.onMoreClick}
inputRef={this.contextMenuButton} ref={this.contextMenuButton}
isExpanded={this.state.showMoreMenu} isExpanded={this.state.showMoreMenu}
title={_t("voip|more_button")} title={_t("voip|more_button")}
alignment={Alignment.Top} alignment={Alignment.Top}