Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-18 - Adding accessibility to Button loading states
**Learning:** Loading states inside accessible interactive elements (like custom buttons) should communicate properly using `aria-busy` and hiding decorative loading spin icons via `aria-hidden` to avoid repetitive screen reader announcements.
**Action:** When adding accessible loading states to buttons, always apply `aria-busy={true}` to the button element and `aria-hidden="true"` to any decorative icon rendering the loading animation.
6 changes: 3 additions & 3 deletions src/components/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { useHaptic } from '@/hooks/use-haptic'
import { buttonVariants } from './button-variants'

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
asChild?: boolean
isLoading?: boolean
}
Expand All @@ -33,7 +32,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(

const content = showLoader ? (
<>
<Loader2 className="animate-spin" />
<Loader2 className="animate-spin" aria-hidden="true" />
{children}
</>
) : (
Expand All @@ -46,6 +45,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
ref={ref}
disabled={isLoading || props.disabled}
onClick={handleClick}
aria-busy={isLoading ? 'true' : undefined}
{...props}
>
{content}
Expand Down
Loading