diff --git a/.yarn/cache/@next-swc-darwin-arm64-npm-12.1.4-8bc9a59090-8.zip b/.yarn/cache/@next-swc-darwin-arm64-npm-12.1.4-8bc9a59090-8.zip new file mode 100644 index 000000000000..87eb23228206 Binary files /dev/null and b/.yarn/cache/@next-swc-darwin-arm64-npm-12.1.4-8bc9a59090-8.zip differ diff --git a/.yarn/cache/@next-swc-linux-arm64-gnu-npm-12.1.4-5ce5b29d4d-8.zip b/.yarn/cache/@next-swc-linux-arm64-gnu-npm-12.1.4-5ce5b29d4d-8.zip new file mode 100644 index 000000000000..b29a136eee29 Binary files /dev/null and b/.yarn/cache/@next-swc-linux-arm64-gnu-npm-12.1.4-5ce5b29d4d-8.zip differ diff --git a/.yarn/cache/@next-swc-win32-arm64-msvc-npm-12.1.4-b5b707823d-8.zip b/.yarn/cache/@next-swc-win32-arm64-msvc-npm-12.1.4-b5b707823d-8.zip new file mode 100644 index 000000000000..90394d00bc2d Binary files /dev/null and b/.yarn/cache/@next-swc-win32-arm64-msvc-npm-12.1.4-b5b707823d-8.zip differ diff --git a/.yarn/cache/esbuild-darwin-arm64-npm-0.14.38-b37de966bb-8.zip b/.yarn/cache/esbuild-darwin-arm64-npm-0.14.38-b37de966bb-8.zip new file mode 100644 index 000000000000..d991ac385800 Binary files /dev/null and b/.yarn/cache/esbuild-darwin-arm64-npm-0.14.38-b37de966bb-8.zip differ diff --git a/.yarn/cache/esbuild-darwin-arm64-npm-0.15.3-3640e6bc55-8.zip b/.yarn/cache/esbuild-darwin-arm64-npm-0.15.3-3640e6bc55-8.zip new file mode 100644 index 000000000000..86f29015e47d Binary files /dev/null and b/.yarn/cache/esbuild-darwin-arm64-npm-0.15.3-3640e6bc55-8.zip differ diff --git a/.yarn/cache/esbuild-linux-arm64-npm-0.14.38-cef31fba53-8.zip b/.yarn/cache/esbuild-linux-arm64-npm-0.14.38-cef31fba53-8.zip new file mode 100644 index 000000000000..16e3d3396887 Binary files /dev/null and b/.yarn/cache/esbuild-linux-arm64-npm-0.14.38-cef31fba53-8.zip differ diff --git a/.yarn/cache/esbuild-linux-arm64-npm-0.15.3-5ce6ddd928-8.zip b/.yarn/cache/esbuild-linux-arm64-npm-0.15.3-5ce6ddd928-8.zip new file mode 100644 index 000000000000..b7820748fab3 Binary files /dev/null and b/.yarn/cache/esbuild-linux-arm64-npm-0.15.3-5ce6ddd928-8.zip differ diff --git a/.yarn/cache/esbuild-windows-arm64-npm-0.14.38-9693d16298-8.zip b/.yarn/cache/esbuild-windows-arm64-npm-0.14.38-9693d16298-8.zip new file mode 100644 index 000000000000..9ad725f42e62 Binary files /dev/null and b/.yarn/cache/esbuild-windows-arm64-npm-0.14.38-9693d16298-8.zip differ diff --git a/.yarn/cache/esbuild-windows-arm64-npm-0.15.3-6777f0a5aa-8.zip b/.yarn/cache/esbuild-windows-arm64-npm-0.15.3-6777f0a5aa-8.zip new file mode 100644 index 000000000000..8bcc7deac358 Binary files /dev/null and b/.yarn/cache/esbuild-windows-arm64-npm-0.15.3-6777f0a5aa-8.zip differ diff --git a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap index 876180ab74cc..49fba4df5557 100644 --- a/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap +++ b/packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap @@ -475,6 +475,9 @@ Map { "onChange": Object { "type": "func", }, + "readOnly": Object { + "type": "bool", + }, "title": Object { "type": "string", }, diff --git a/packages/react/src/components/Checkbox/Checkbox.tsx b/packages/react/src/components/Checkbox/Checkbox.tsx index 6c2e55defebd..025029a939bd 100644 --- a/packages/react/src/components/Checkbox/Checkbox.tsx +++ b/packages/react/src/components/Checkbox/Checkbox.tsx @@ -58,6 +58,11 @@ export interface CheckboxProps evt: React.ChangeEvent, data: { checked: boolean; id: string } ) => void; + + /** + * Provide an optional onClick handler that is called on click + */ + onClick?: (evt: React.MouseEvent) => void; } const Checkbox = React.forwardRef( @@ -67,8 +72,10 @@ const Checkbox = React.forwardRef( id, labelText, onChange, + onClick, indeterminate, hideLabel, + readOnly, title = '', ...other }: CheckboxProps, @@ -78,7 +85,10 @@ const Checkbox = React.forwardRef( const wrapperClasses = classNames( `${prefix}--form-item`, `${prefix}--checkbox-wrapper`, - [className] + className, + { + [`${prefix}--checkbox-wrapper--readonly`]: readOnly, + } ); const innerLabelClasses = classNames(`${prefix}--checkbox-label-text`, { [`${prefix}--visually-hidden`]: hideLabel, @@ -90,7 +100,9 @@ const Checkbox = React.forwardRef( {...other} type="checkbox" onChange={(evt) => { - onChange && onChange(evt, { checked: evt.target.checked, id }); + if (!readOnly && onChange) { + onChange(evt, { checked: evt.target.checked, id }); + } }} className={`${prefix}--checkbox`} id={id} @@ -104,6 +116,19 @@ const Checkbox = React.forwardRef( ref.current = el; } }} + // readonly attribute not applicable to type="checkbox" + // see - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox + aria-readonly={readOnly} + onClick={(evt) => { + if (readOnly) { + // prevent default stops the checkbox being updated + evt.preventDefault(); + } + // pass onClick event on to the user even if readonly + if (onClick) { + onClick(evt); + } + }} />