An open source design system that's fully customizable and agent ready
TypeScript
fix(core): a disabled CheckboxInput no longer runs a caller's handlers (#10092)
Parinith7aaf2a1b979c
diff --git a/.changeset/checkboxinput-disabled-caller-handlers.md b/.changeset/checkboxinput-disabled-caller-handlers.mdnew file mode 100644index 0000000000..5c1efd4f9a--- /dev/null+++ b/.changeset/checkboxinput-disabled-caller-handlers.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] A disabled `CheckboxInput` no longer runs a caller's `onKeyDown`, `onKeyUp`, `onPointerDown`, `onMouseDown` or any other `on*` prop except `onFocus` and `onBlur`. Before, a disabled checkbox stayed focusable and clickable, so a key or pointer press on it still reached them; only `onClick` was withheld. Now a disabled `CheckboxInput` runs no caller handler other than `onFocus` and `onBlur`, as a disabled `Slider`, `TextInput` and `TextArea` do (`spec:AST-085` FR2). An enabled `CheckboxInput` is unchanged. No API changes.++@parinith-webdiff --git a/packages/core/src/CheckboxInput/CheckboxInput.test.tsx b/packages/core/src/CheckboxInput/CheckboxInput.test.tsxindex 28eaecd9ba..1778661223 100644--- a/packages/core/src/CheckboxInput/CheckboxInput.test.tsx+++ b/packages/core/src/CheckboxInput/CheckboxInput.test.tsx@@ -455,6 +455,65 @@ describe('CheckboxInput', () => {});});+ describe('caller handlers', () => {+ const h = {hidden: true} as const;++ it('does not run a disabled checkbox’s caller handlers other than focus and blur', () => {+ const onKeyDown = vi.fn();+ const onKeyUp = vi.fn();+ const onPointerDown = vi.fn();+ const onMouseDown = vi.fn();+ const onFocus = vi.fn();+ const onBlur = vi.fn();+ render(+ <CheckboxInput+ label="Accept terms"+ value={false}+ onChange={() => {}}+ isDisabled+ onKeyDown={onKeyDown}+ onKeyUp={onKeyUp}+ onPointerDown={onPointerDown}+ onMouseDown={onMouseDown}+ onFocus={onFocus}+ onBlur={onBlur}+ />,+ );+ const checkbox = screen.getByRole('checkbox', h);+ fireEvent.pointerDown(checkbox);+ fireEvent.mouseDown(checkbox);+ fireEvent.keyDown(checkbox, {key: 'x'});+ fireEvent.keyUp(checkbox, {key: 'x'});+ expect(onPointerDown).not.toHaveBeenCalled();+ expect(onMouseDown).not.toHaveBeenCalled();+ expect(onKeyDown).not.toHaveBeenCalled();+ expect(onKeyUp).not.toHaveBeenCalled();+ fireEvent.focus(checkbox);+ fireEvent.blur(checkbox);+ expect(onFocus).toHaveBeenCalledTimes(1);+ expect(onBlur).toHaveBeenCalledTimes(1);+ });++ it('still runs an enabled checkbox’s caller handlers', () => {+ const onKeyDown = vi.fn();+ const onPointerDown = vi.fn();+ render(+ <CheckboxInput+ label="Accept terms"+ value={false}+ onChange={() => {}}+ onKeyDown={onKeyDown}+ onPointerDown={onPointerDown}+ />,+ );+ const checkbox = screen.getByRole('checkbox', h);+ fireEvent.pointerDown(checkbox);+ fireEvent.keyDown(checkbox, {key: 'x'});+ expect(onPointerDown).toHaveBeenCalledTimes(1);+ expect(onKeyDown).toHaveBeenCalledTimes(1);+ });+ });+describe('disabledMessage', () => {const h = {hidden: true} as const;diff --git a/packages/core/src/CheckboxInput/CheckboxInput.tsx b/packages/core/src/CheckboxInput/CheckboxInput.tsxindex a7f1596aa0..9c7b3d6f46 100644--- a/packages/core/src/CheckboxInput/CheckboxInput.tsx+++ b/packages/core/src/CheckboxInput/CheckboxInput.tsx@@ -49,6 +49,7 @@ import {Spinner} from '../Spinner/Spinner';import {useTooltip} from '../Tooltip/useTooltip';import {mergeProps} from '../utils/mergeProps';import {rtlStyles} from '../utils/rtlStyles';+import {withholdCallerHandlers} from '../utils/disabledInteraction';import {indicatorScope} from '../Indicator/indicator.markers.stylex';import {indicatorPressScope} from '../internal/indicatorPress.stylex';import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';@@ -569,7 +570,10 @@ export function CheckboxInput({)}{...focusProps}><input- {...rest}+ // A disabled checkbox stays focusable, so it still receives key and+ // pointer events. It runs no caller handler except `onFocus` and+ // `onBlur`.+ {...withholdCallerHandlers(rest, isDisabled)}ref={useMergedRefs(ref,indeterminateRef,