From bd365a0f096e88705b31740e2fb12f3d8ff6951e Mon Sep 17 00:00:00 2001 From: Anujeet Chatterjee Date: Sat, 3 Oct 2020 21:57:49 +0530 Subject: [PATCH] Added Enter Submit functionality (#2170) * Added Enter Submit functionalit Signed-off-by: GitHub * Added Enter Submit functionalit Signed-off-by: Anujeet Chatterjee Author: Anujeet Chatterjee Date: Thu Oct 1 19:48:27 2020 +0000 * welcomemodel -> welcomModal Signed-off-by: GitHub Co-authored-by: Arkajyoti Mukherjee <32966391+arkajyotiMukherjee@users.noreply.github.com> --- .../public/locales/en/translation.yaml | 2 +- .../src/components/InputField/index.tsx | 12 +++++ .../src/components/WelcomeModal/Modalpage.tsx | 2 +- .../src/components/WelcomeModal/Stepper.tsx | 48 +++++++++++++------ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/litmus-portal/frontend/public/locales/en/translation.yaml b/litmus-portal/frontend/public/locales/en/translation.yaml index cc04aa514..393d4289a 100644 --- a/litmus-portal/frontend/public/locales/en/translation.yaml +++ b/litmus-portal/frontend/public/locales/en/translation.yaml @@ -1,4 +1,4 @@ -welcomeModel: +welcomeModal: title: Welcome to Litmus Portal, info: What do you want to name your project? button: diff --git a/litmus-portal/frontend/src/components/InputField/index.tsx b/litmus-portal/frontend/src/components/InputField/index.tsx index b660a55a4..6d1a89d8c 100644 --- a/litmus-portal/frontend/src/components/InputField/index.tsx +++ b/litmus-portal/frontend/src/components/InputField/index.tsx @@ -19,6 +19,7 @@ interface InputFieldProps { iconType?: string | undefined; styles?: Object; handleChange?: (event: React.ChangeEvent) => void; + onKeyPress?: (event: React.KeyboardEvent) => void; } const InputField: React.FC = ({ @@ -33,6 +34,7 @@ const InputField: React.FC = ({ required, iconType, handleChange, + onKeyPress, }) => { const LitmusTextFieldStylesExternal = useStyles(); @@ -63,6 +65,7 @@ const InputField: React.FC = ({ onChange={handleChange} variant="filled" style={styles} + onKeyPress={onKeyPress} InputProps={ { classes, @@ -86,6 +89,7 @@ const InputField: React.FC = ({ if (type === 'password' && validationError === true) { return ( = ({ if (iconType === 'iconLeft' && validationError === false) { return ( = ({ if (iconType === 'iconLeft' && validationError === true) { return ( = ({ if (iconType === 'iconRight' && validationError === false) { return ( = ({ ) { return ( = ({ if (iconType === 'iconRight' && validationError === true) { return ( = ({ if (iconType === 'iconLeftRight' && validationError === false) { return ( = ({ if (iconType === 'iconLeftRight' && validationError === true) { return ( = ({ return ( = ({
- {t('welcomeModel.title')} + {t('welcomeModal.title')}
{setName}
diff --git a/litmus-portal/frontend/src/components/WelcomeModal/Stepper.tsx b/litmus-portal/frontend/src/components/WelcomeModal/Stepper.tsx index 29e13caec..3cd056099 100644 --- a/litmus-portal/frontend/src/components/WelcomeModal/Stepper.tsx +++ b/litmus-portal/frontend/src/components/WelcomeModal/Stepper.tsx @@ -195,7 +195,7 @@ const CStepper: React.FC = ({ handleModal }) => { isDisabled={isError.current} handleClick={handleNext} > -
{t('welcomeModel.button.continue')}
+
{t('welcomeModal.button.continue')}
); @@ -205,7 +205,7 @@ const CStepper: React.FC = ({ handleModal }) => {
- <>{t('welcomeModel.button.back')} + <>{t('welcomeModal.button.back')}
@@ -215,7 +215,7 @@ const CStepper: React.FC = ({ handleModal }) => { handleClick={handleSubmit} data-cy="Start" > -
{t('welcomeModel.button.letsStart')}
+
{t('welcomeModal.button.letsStart')}
@@ -229,7 +229,7 @@ const CStepper: React.FC = ({ handleModal }) => { handleClick={handleBack} data-cy="Back" > - <>{t('welcomeModel.button.back')} + <>{t('welcomeModal.button.back')}
@@ -239,13 +239,28 @@ const CStepper: React.FC = ({ handleModal }) => { handleClick={handleNext} data-cy="Continue" > -
{t('welcomeModel.button.continue')}
+
{t('welcomeModal.button.continue')}
); }; + // Submit on Enter Key-press + const keyPress = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + if (activeStep === 0) { + handleNext(); + return; + } + if (activeStep === 3) { + handleSubmit(); + return; + } + handleNext(); + } + }; + // Content of the steps based on active step count const getStepContent = (step: number) => { switch (step) { @@ -256,7 +271,7 @@ const CStepper: React.FC = ({ handleModal }) => {
= ({ handleModal }) => { handleChange={(event) => { setData('project_name', event.target.value); }} + onKeyPress={keyPress} />
{selectiveButtons()} @@ -281,7 +297,7 @@ const CStepper: React.FC = ({ handleModal }) => { ? 'Administrator' : userData.username } - setText={t('welcomeModel.case-0.info')} + setText={t('welcomeModal.case-0.info')} /> ); case 1: @@ -291,7 +307,7 @@ const CStepper: React.FC = ({ handleModal }) => {
= ({ handleModal }) => { handleChange={(event) => { setData('name', event.target.value); }} + onKeyPress={keyPress} />
{selectiveButtons()}
} setName={info.name} - setText={t('welcomeModel.case-1.info')} + setText={t('welcomeModal.case-1.info')} /> ); case 2: @@ -322,7 +339,7 @@ const CStepper: React.FC = ({ handleModal }) => { >
= ({ handleModal }) => { confirmPassword: values.confirmPassword, }) } + onKeyPress={keyPress} />
= ({ handleModal }) => { confirmPassword: event.target.value, }) } + onKeyPress={keyPress} />
{selectiveButtons()}
} setName={info.name} - setText={t('welcomeModel.case-2.info')} + setText={t('welcomeModal.case-2.info')} /> ); case 3: @@ -380,7 +399,7 @@ const CStepper: React.FC = ({ handleModal }) => {
= ({ handleModal }) => { handleChange={(event) => { setData('email', event.target.value); }} + onKeyPress={keyPress} />
{selectiveButtons()} @@ -397,7 +417,7 @@ const CStepper: React.FC = ({ handleModal }) => { } // pass here corresponding name of user setName={info.name} - setText={t('welcomeModel.case-3.info')} + setText={t('welcomeModal.case-3.info')} /> );