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.
This commit is contained in:
Marc-André Bombeck committed 2026-05-21 21:45:58 +02:00
1 parent f2cd4f6d59
commit 6f16a5fc3e
1 file changed
+7 -1
+7 -1
View File
@@ -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}