Updated button component accessibility

This commit is contained in:
2026-02-06 19:45:58 -05:00
parent 0bc94be283
commit dd052b0557
2 changed files with 80 additions and 51 deletions

View File

@@ -1,24 +1,42 @@
import type { ButtonProps } from "$/types/ButtonTypes"; import type { ButtonProps } from "$/types/ButtonTypes";
import clsx from "clsx"; import clsx from "clsx";
import * as React from "react";
export default function Button(props: ButtonProps){
const { const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
(
{
className, className,
rounding = "lg", rounding = "lg",
shape = "rectangle", shape = "rectangle",
size = "md", size = "md",
variant = "standard", variant = "standard",
disabled, disabled,
ariaLabel,
ariaDescribedBy,
ariaControls,
role,
tabIndex,
children,
onClick,
...buttonProps ...buttonProps
} = props; },
ref
) => {
return ( return (
<button <button
ref={ref}
data-testid="mattrixwv-button" data-testid="mattrixwv-button"
{...buttonProps} {...buttonProps}
disabled={disabled} disabled={disabled}
aria-label={ariaLabel}
aria-describedby={ariaDescribedBy}
aria-controls={ariaControls}
role={role}
tabIndex={tabIndex}
className={clsx( className={clsx(
className, className,
//Rounding //Rounding
@@ -52,6 +70,11 @@ export default function Button(props: ButtonProps){
"cursor-pointer": !disabled "cursor-pointer": !disabled
} }
)} )}
/> >
{children}
</button>
); );
} }
);
export default Button;

View File

@@ -7,10 +7,16 @@ export type ButtonSize = "xs" | "sm" | "md" | "lg" | "xl";
export type ButtonVariant = "standard" | "outline" | "ghost" | "outline-ghost" | "icon"; export type ButtonVariant = "standard" | "outline" | "ghost" | "outline-ghost" | "icon";
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement>{ export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "size" | "type"> {
rounding?: ButtonRounding; rounding?: ButtonRounding;
shape?: ButtonShape; shape?: ButtonShape;
size?: ButtonSize; size?: ButtonSize;
variant?: ButtonVariant; variant?: ButtonVariant;
ref?: Ref<HTMLButtonElement>; ref?: Ref<HTMLButtonElement>;
ariaLabel?: string;
ariaDescribedBy?: string;
ariaControls?: string;
role?: string;
tabIndex?: number;
} }