Skip to content

Commit

Permalink
feat: 🎸 update a11y for loading status
Browse files Browse the repository at this point in the history
Signed-off-by: kodai3 <[email protected]>
  • Loading branch information
kodai3 committed May 3, 2024
1 parent 845a63c commit f6a380d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
type = 'button',
disabled = false,
loading = false,
onClick,
...props
},
ref,
Expand All @@ -36,8 +37,25 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
[styles.loading]: loading,
});

const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
if (loading) {
e.preventDefault();
return;
}

onClick?.(e);
};

return (
<button type={type} className={cls} ref={ref} disabled={disabled || loading} {...props}>
<button
type={type}
className={cls}
ref={ref}
disabled={disabled}
aria-disabled={loading}
onClick={handleClick}
{...props}
>
{fixedIcon && <span className={styles.fixedIcon}>{fixedIcon}</span>}
<span className={styles.label}>
{icon && <span className={styles.icon}>{icon}</span>}
Expand Down

0 comments on commit f6a380d

Please sign in to comment.