From 6f16a5fc3e1238dbfee0272de2783e3a668867cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 21 May 2026 21:28:01 +0200 Subject: [PATCH] fix(switch): extend tap target to 44x44 via ::before pseudo-element WCAG 2.5.5 calls for a 44 px minimum interactive target. The Switch visual track stays at 18x32 px but a `::before` overlay with `inset-[-12px]` floats a transparent hit zone over the full 44x44 region. Mirrors the v1.4.34 IW-G treatment already applied to Input and auto-fixes every Switch call-site in one move. --- src/components/ui/switch.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/ui/switch.tsx b/src/components/ui/switch.tsx index 8353ebacd..e2941b446 100644 --- a/src/components/ui/switch.tsx +++ b/src/components/ui/switch.tsx @@ -17,7 +17,13 @@ function Switch({ data-slot="switch" data-size={size} className={cn( - "peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 group/switch inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6", + // v1.4.43 W5-H1 — extend the WCAG 2.5.5 hit target to 44×44 px via + // a `::before` pseudo-element while leaving the visual track at + // 18×32 px. The same trick is used on Input (v1.4.34 IW-G). The + // wrapping `relative` and `before:absolute … before:inset-[-12px]` + // pair guarantees pointer events bubble up from the larger zone + // without disturbing layout. + "peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 group/switch relative inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none before:absolute before:inset-[-12px] before:content-[''] focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6", className, )} {...props}