Bug Fix: Allows user to press 'Enter' to navigate through forms (#2840)

* Adding TextInput onKeyDown prop for detecting enter key on signup/login/onbaording forms

* Adding onKeyDown for password field
This commit is contained in:
Paula Perdomo
2023-12-05 08:28:12 -05:00
committed by GitHub
parent 6d4ad6ec18
commit 1616ea6c4f
3 changed files with 29 additions and 1 deletions

View File

@ -61,6 +61,21 @@ export const SignInUpForm = () => {
workspace, workspace,
} = useSignInUp(); } = useSignInUp();
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter') {
event.preventDefault();
if (signInUpStep === SignInUpStep.Init) {
continueWithEmail();
} else if (signInUpStep === SignInUpStep.Email) {
continueWithCredentials();
} else if (signInUpStep === SignInUpStep.Password) {
setShowErrors(true);
handleSubmit(submitCredentials)();
}
}
};
const buttonTitle = useMemo(() => { const buttonTitle = useMemo(() => {
if (signInUpStep === SignInUpStep.Init) { if (signInUpStep === SignInUpStep.Init) {
return 'Continue With Email'; return 'Continue With Email';
@ -139,6 +154,7 @@ export const SignInUpForm = () => {
} }
}} }}
error={showErrors ? error?.message : undefined} error={showErrors ? error?.message : undefined}
onKeyDown={handleKeyDown}
fullWidth fullWidth
disableHotkeys disableHotkeys
/> />
@ -172,6 +188,7 @@ export const SignInUpForm = () => {
placeholder="Password" placeholder="Password"
onBlur={onBlur} onBlur={onBlur}
onChange={onChange} onChange={onChange}
onKeyDown={handleKeyDown}
error={showErrors ? error?.message : undefined} error={showErrors ? error?.message : undefined}
fullWidth fullWidth
disableHotkeys disableHotkeys

View File

@ -22,7 +22,7 @@ import { InputHotkeyScope } from '../types/InputHotkeyScope';
export type TextInputComponentProps = Omit< export type TextInputComponentProps = Omit<
InputHTMLAttributes<HTMLInputElement>, InputHTMLAttributes<HTMLInputElement>,
'onChange' 'onChange' | 'onKeyDown'
> & { > & {
className?: string; className?: string;
label?: string; label?: string;
@ -31,6 +31,7 @@ export type TextInputComponentProps = Omit<
disableHotkeys?: boolean; disableHotkeys?: boolean;
error?: string; error?: string;
RightIcon?: IconComponent; RightIcon?: IconComponent;
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
}; };
const StyledContainer = styled.div<Pick<TextInputComponentProps, 'fullWidth'>>` const StyledContainer = styled.div<Pick<TextInputComponentProps, 'fullWidth'>>`
@ -118,6 +119,7 @@ const TextInputComponent = (
onChange, onChange,
onFocus, onFocus,
onBlur, onBlur,
onKeyDown,
fullWidth, fullWidth,
error, error,
required, required,
@ -184,6 +186,7 @@ const TextInputComponent = (
onChange={(event: ChangeEvent<HTMLInputElement>) => { onChange={(event: ChangeEvent<HTMLInputElement>) => {
onChange?.(event.target.value); onChange?.(event.target.value);
}} }}
onKeyDown={onKeyDown}
{...{ autoFocus, disabled, placeholder, required, value }} {...{ autoFocus, disabled, placeholder, required, value }}
/> />
<StyledTrailingIconContainer> <StyledTrailingIconContainer>

View File

@ -97,6 +97,13 @@ export const CreateWorkspace = () => {
[enqueueSnackBar, navigate, setCurrentWorkspace, updateWorkspace], [enqueueSnackBar, navigate, setCurrentWorkspace, updateWorkspace],
); );
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter') {
event.preventDefault();
handleSubmit(onSubmit)();
}
};
useScopedHotkeys( useScopedHotkeys(
'enter', 'enter',
() => { () => {
@ -141,6 +148,7 @@ export const CreateWorkspace = () => {
onBlur={onBlur} onBlur={onBlur}
onChange={onChange} onChange={onChange}
error={error?.message} error={error?.message}
onKeyDown={handleKeyDown}
fullWidth fullWidth
disableHotkeys disableHotkeys
/> />