diff --git a/README.md b/README.md index 035a014..abcfac2 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ I did try doing everything myself, but faced issues around updating the form sta
Cons? -- Some carousels like Alice behave unpredictably sometimes. So maybe don't use Alice. +- Alice behaves a little unpredictably sometimes.
@@ -53,3 +53,7 @@ I did try doing everything myself, but faced issues around updating the form sta Abso-fruitly!
+ +  + +Compare against Swiper carousel [here](https://github.com/CHR-onicles/animated-stepper-form/tree/18-swiper-carousel#faqs-for-future-me) diff --git a/src/components/CustomDatePicker/index.tsx b/src/components/CustomDatePicker/index.tsx index 22f0aba..8974404 100644 --- a/src/components/CustomDatePicker/index.tsx +++ b/src/components/CustomDatePicker/index.tsx @@ -21,6 +21,7 @@ interface CustomDatePickerProps { minDate?: Date; showYearDropdown?: boolean; required?: boolean; + tabIndex?: number; } export const CustomDatePicker = ({ @@ -36,18 +37,20 @@ export const CustomDatePicker = ({ minDate = new Date(1900, 0, 1), showYearDropdown = false, required = false, + tabIndex, }: CustomDatePickerProps) => { // console.log("[From Date picker]", startDate); return ( {isInline ? null : } { diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 1936690..c32a892 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -21,6 +21,12 @@ const responsive = { const TOTAL_STEPS = steps.length; +// Function to prevent users from tabbing into another step without finishing +// the current step +const getTabIndex = (currentStep: number, validStep: number) => { + return currentStep === validStep ? 0 : -1; +}; + export const Home = () => { const [dob, setDob] = useState(); const [step, setStep] = useState(1); @@ -67,6 +73,7 @@ export const Home = () => { id="fullName" value={formData.fullName ?? ""} onChange={handleOnChange} + tabIndex={getTabIndex(step, 1)} /> @@ -81,6 +88,7 @@ export const Home = () => { placeholder="Select a date" showYearDropdown required + tabIndex={getTabIndex(step, 1)} /> @@ -96,12 +104,13 @@ export const Home = () => { value={formData.email ?? ""} onChange={handleOnChange} required + tabIndex={getTabIndex(step, 1)} />
- Next + Next
,
@@ -117,6 +126,7 @@ export const Home = () => { name="country" value={formData.country ?? ""} onChange={handleOnChange} + tabIndex={getTabIndex(step, 2)} /> @@ -129,6 +139,7 @@ export const Home = () => { name="state" value={formData.state ?? ""} onChange={handleOnChange} + tabIndex={getTabIndex(step, 2)} /> @@ -141,6 +152,7 @@ export const Home = () => { name="city" value={formData.city ?? ""} onChange={handleOnChange} + tabIndex={getTabIndex(step, 2)} /> @@ -153,6 +165,7 @@ export const Home = () => { name="postal" value={formData.postal ?? ""} onChange={handleOnChange} + tabIndex={getTabIndex(step, 2)} /> @@ -160,13 +173,14 @@ export const Home = () => {
- Next + Next
,
@@ -182,6 +196,7 @@ export const Home = () => { name="occupation" value={formData.occupation ?? ""} onChange={handleOnChange} + tabIndex={getTabIndex(step, 3)} /> @@ -194,6 +209,7 @@ export const Home = () => { name="company" value={formData.company ?? ""} onChange={handleOnChange} + tabIndex={getTabIndex(step, 3)} /> @@ -206,6 +222,7 @@ export const Home = () => { name="industry" value={formData.industry ?? ""} onChange={handleOnChange} + tabIndex={getTabIndex(step, 3)} /> @@ -213,13 +230,14 @@ export const Home = () => {
- Submit + Submit
, ];