Files
ThreadNet-Web/src/accessibility/context_menu/ContextMenuTooltipButton.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-07-17 16:43:24 +01:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
2020-07-17 16:43:24 +01:00
Copyright 2019 The Matrix.org Foundation C.I.C.
2024-09-09 14:57:16 +01:00
Copyright 2018 New Vector Ltd
Copyright 2015, 2016 OpenMarket Ltd
2020-07-17 16:43:24 +01:00
2024-09-09 14:57:16 +01:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
2020-07-17 16:43:24 +01:00
*/
import React, { ComponentProps, forwardRef, Ref } from "react";
2020-07-17 16:43:24 +01:00
import AccessibleButton from "../../components/views/elements/AccessibleButton";
2020-07-17 16:43:24 +01:00
type Props<T extends keyof JSX.IntrinsicElements> = ComponentProps<typeof AccessibleButton<T>> & {
// whether the context menu is currently open
2020-07-17 16:43:24 +01:00
isExpanded: boolean;
};
2020-07-17 16:43:24 +01:00
// Semantic component for representing the AccessibleButton which launches a <ContextMenu />
export const ContextMenuTooltipButton = forwardRef(function <T extends keyof JSX.IntrinsicElements>(
{ isExpanded, children, onClick, onContextMenu, element, ...props }: Props<T>,
ref: Ref<HTMLElement>,
) {
2020-07-17 16:43:24 +01:00
return (
<AccessibleButton
2020-07-17 16:43:24 +01:00
{...props}
element={element as keyof JSX.IntrinsicElements}
2020-07-17 16:43:24 +01:00
onClick={onClick}
onContextMenu={onContextMenu ?? onClick ?? undefined}
2020-07-17 16:43:24 +01:00
aria-haspopup={true}
aria-expanded={isExpanded}
disableTooltip={isExpanded}
ref={ref}
2020-07-17 16:43:24 +01:00
>
{children}
</AccessibleButton>
2020-07-17 16:43:24 +01:00
);
});