From 5d7c0f7ebc5ff6728b92143e3512c1ed29beb317 Mon Sep 17 00:00:00 2001 From: Chen Saranga Date: Wed, 10 Apr 2024 13:16:19 +0300 Subject: [PATCH 01/10] feat: add autoFocus to docgen --- .../playground/react-docgen-output.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/core/src/storybook/stand-alone-documentaion/playground/react-docgen-output.json b/packages/core/src/storybook/stand-alone-documentaion/playground/react-docgen-output.json index cf93f99156..61bd5735fd 100644 --- a/packages/core/src/storybook/stand-alone-documentaion/playground/react-docgen-output.json +++ b/packages/core/src/storybook/stand-alone-documentaion/playground/react-docgen-output.json @@ -12104,6 +12104,17 @@ "computed": false } }, + "autoFocus": { + "required": false, + "tsType": { + "name": "boolean" + }, + "description": "autoFocus when component mount", + "defaultValue": { + "value": "false", + "computed": false + } + }, "disabled": { "required": false, "tsType": { From dc6d90df821f490f3fa644eb0256ac9d79ae729d Mon Sep 17 00:00:00 2001 From: Chen Saranga Date: Wed, 10 Apr 2024 13:17:55 +0300 Subject: [PATCH 02/10] feat: ensure autoFocus works on RadioButton --- .../radioButton-snapshot-tests.jest.tsx.snap | 9 +++++++++ .../__tests__/radioButton-tests.jest.tsx | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) 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 44d8af9e62..dffcc7bee5 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 @@ -35,6 +35,7 @@ exports[`RadioButton renders correctly when checked 1`] = ` className="inputContainer" > { const formName = "myForm"; const radiosName = "radios"; - const option1Value = "1"; - const option1Text = "Option 1"; - const option2Value = "2"; - const option2Text = "Option 2"; - const option3Value = "3"; - const option3Text = "Option 3"; - let onChangeMock1: jest.Mock; let onChangeMock2: jest.Mock; let onChangeMock3: jest.Mock; + const option1Text = "Option 1"; + const option1Value = "1"; + const option2Text = "Option 2"; + const option2Value = "2"; + const option3Text = "Option 3"; + const option3Value = "3"; + describe("With one of the radio buttons is checked by default", () => { beforeEach(() => { onChangeMock1 = jest.fn(); From 594a606930f7e27e11b275e8983408ed2bc5d802 Mon Sep 17 00:00:00 2001 From: Chen Saranga Date: Wed, 10 Apr 2024 21:07:36 +0300 Subject: [PATCH 03/10] feat: add autoFocus to Checkbox --- packages/core/src/components/Checkbox/Checkbox.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/core/src/components/Checkbox/Checkbox.tsx b/packages/core/src/components/Checkbox/Checkbox.tsx index b1954d63ac..9836f9bc6e 100644 --- a/packages/core/src/components/Checkbox/Checkbox.tsx +++ b/packages/core/src/components/Checkbox/Checkbox.tsx @@ -36,6 +36,8 @@ export interface CheckBoxProps extends VibeComponentProps { checked?: boolean; /** An in between state to display a non selected */ indeterminate?: boolean; + /** is autoFocus */ + autoFocus?: boolean; /** Set the option to be disabled */ disabled?: boolean; /** the default value which the checkbox will start from */ @@ -63,6 +65,7 @@ const Checkbox: VibeComponent = forwardRef( ariaLabelledBy, onChange = NOOP, checked, + autoFocus, indeterminate = false, disabled = false, defaultChecked, @@ -127,6 +130,7 @@ const Checkbox: VibeComponent = forwardRef( value={value} name={name} type="checkbox" + autoFocus={autoFocus} onChange={onChange} defaultChecked={overrideDefaultChecked} disabled={disabled} From b43fc1bd49329ad7be0131af1d5896c3e794c884 Mon Sep 17 00:00:00 2001 From: Chen Saranga Date: Wed, 10 Apr 2024 21:11:14 +0300 Subject: [PATCH 04/10] test: make sure Checkbox can be autoFocused --- .../checkbox-snapshot-tests.jest.tsx.snap | 47 ++++++++ .../checkbox-snapshot-tests.jest.tsx | 5 + .../__tests__/checkbox-tests.jest.tsx | 102 ++++++++++++++---- 3 files changed, 132 insertions(+), 22 deletions(-) diff --git a/packages/core/src/components/Checkbox/__tests__/__snapshots__/checkbox-snapshot-tests.jest.tsx.snap b/packages/core/src/components/Checkbox/__tests__/__snapshots__/checkbox-snapshot-tests.jest.tsx.snap index c3d6b4bd7f..49a900db2a 100644 --- a/packages/core/src/components/Checkbox/__tests__/__snapshots__/checkbox-snapshot-tests.jest.tsx.snap +++ b/packages/core/src/components/Checkbox/__tests__/__snapshots__/checkbox-snapshot-tests.jest.tsx.snap @@ -1,5 +1,52 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Checkbox renders correctly when autoFocus 1`] = ` + +`; + exports[`Checkbox renders correctly when checked 1`] = `