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

Commit

Permalink
Add extra attribute to AccessibleButton
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Apr 26, 2024
1 parent 8fcc04a commit fae6f50
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/components/views/elements/AccessibleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

import React, { forwardRef, FunctionComponent, HTMLAttributes, InputHTMLAttributes, Ref } from "react";
import React, { ComponentProps, forwardRef, FunctionComponent, HTMLAttributes, InputHTMLAttributes, Ref } from "react";
import classnames from "classnames";
import { Tooltip } from "@vector-im/compound-web";

Expand Down Expand Up @@ -61,6 +61,8 @@ type DynamicElementProps<T extends keyof JSX.IntrinsicElements> = Partial<
> &
Omit<InputHTMLAttributes<Element>, "onClick">;

type TooltipProps = ComponentProps<typeof Tooltip>;

/**
* Type of props accepted by {@link AccessibleButton}.
*
Expand Down Expand Up @@ -96,6 +98,14 @@ type Props<T extends keyof JSX.IntrinsicElements> = DynamicHtmlElementProps<T> &
* Only valid when used in conjunction with `title`.
*/
caption?: string;
/**
* The placement of the tooltip.
*/
placement?: TooltipProps["placement"];
/**
* Callback for when the tooltip is opened or closed.
*/
onTooltipOpenChange?: TooltipProps["onOpenChange"];
};

/**
Expand Down Expand Up @@ -128,6 +138,8 @@ const AccessibleButton = forwardRef(function <T extends keyof JSX.IntrinsicEleme
triggerOnMouseDown,
title,
caption,
placement,
onTooltipOpenChange,
...restProps
}: Props<T>,
ref: Ref<HTMLElement>,
Expand Down Expand Up @@ -199,7 +211,13 @@ const AccessibleButton = forwardRef(function <T extends keyof JSX.IntrinsicEleme

if (title) {
return (
<Tooltip label={title} caption={caption} isTriggerInteractive={!disabled}>
<Tooltip
label={title}
caption={caption}
isTriggerInteractive={true}
placement={placement}
onOpenChange={onTooltipOpenChange}
>
{button}
</Tooltip>
);
Expand Down

0 comments on commit fae6f50

Please sign in to comment.