From d40b49efc63fe943a71bf9ba643b513cf5f66d97 Mon Sep 17 00:00:00 2001 From: chensara Date: Wed, 10 Apr 2024 15:28:01 +0300 Subject: [PATCH] feat: add autoFocus to RadioButton (#2057) --- .../components/RadioButton/RadioButton.tsx | 5 + .../radioButton-snapshot-tests.jest.tsx.snap | 26 ++++ .../radioButton-snapshot-tests.jest.tsx | 6 +- .../__tests__/radioButton-tests.jest.tsx | 119 ++++++++++-------- 4 files changed, 106 insertions(+), 50 deletions(-) diff --git a/packages/core/src/components/RadioButton/RadioButton.tsx b/packages/core/src/components/RadioButton/RadioButton.tsx index a845dd55bf..b4405ed854 100644 --- a/packages/core/src/components/RadioButton/RadioButton.tsx +++ b/packages/core/src/components/RadioButton/RadioButton.tsx @@ -27,6 +27,8 @@ export interface RadioButtonProps extends VibeComponentProps { value?: string; /** A string specifying a name for the input control. This name is submitted along with the control's value when the form data is submitted. */ name?: string; + /** is autoFocus */ + autoFocus?: boolean; /** is disabled */ disabled?: boolean; /** why the input is disabled */ @@ -64,6 +66,7 @@ const RadioButton: VibeComponent & object = forwa */ radioButtonClassName, disabled = false, + autoFocus, disabledReason, defaultChecked = false, children, @@ -80,6 +83,7 @@ const RadioButton: VibeComponent & object = forwa const inputRef = useRef(); const mergedRef = useMergeRef(ref, inputRef); const overrideClassName = backwardCompatibilityForProperties([className, componentClassName]); + const onChildClick = useCallback(() => { if (disabled || !retainChildClick) return; if (inputRef.current) { @@ -114,6 +118,7 @@ const RadioButton: VibeComponent & object = forwa type="radio" value={value} name={name} + autoFocus={autoFocus} disabled={disabled} {...checkedProps} onChange={onSelect} diff --git a/packages/core/src/components/RadioButton/__tests__/__snapshots__/radioButton-snapshot-tests.jest.tsx.snap b/packages/core/src/components/RadioButton/__tests__/__snapshots__/radioButton-snapshot-tests.jest.tsx.snap index afbe409e9c..44d8af9e62 100644 --- a/packages/core/src/components/RadioButton/__tests__/__snapshots__/radioButton-snapshot-tests.jest.tsx.snap +++ b/packages/core/src/components/RadioButton/__tests__/__snapshots__/radioButton-snapshot-tests.jest.tsx.snap @@ -1,5 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`RadioButton renders correctly when autoFocus 1`] = ` + +`; + exports[`RadioButton renders correctly when checked 1`] = `