Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AC-6675::When the button create an account is pressed by the keyboard… #3978

Merged
merged 6 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Object {
"createAccountQuery" => undefined,
"signInMutation" => undefined,
},
"handleEnterKeyPress": [Function],
"handleSubmit": [Function],
"initialValues": Object {
"customer": Object {
Expand All @@ -37,6 +38,7 @@ Object {
"createAccountQuery" => undefined,
"signInMutation" => undefined,
},
"handleEnterKeyPress": [Function],
"handleSubmit": [Function],
"initialValues": Object {
"customer": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useEventingContext } from '../../../context/eventing';
* @returns {{
* errors: Map,
* handleSubmit: function,
* handleEnterKeyPress: function,
* isDisabled: boolean,
* initialValues: object,
* recaptchaWidgetProps: { containerElement: function, shouldRender: boolean }
Expand Down Expand Up @@ -161,6 +162,14 @@ export const useCreateAccount = props => {
]
);

const handleEnterKeyPress = useCallback(() => {
event => {
if (event.key === 'Enter') {
handleSubmit();
}
};
}, [handleSubmit]);

const sanitizedInitialValues = useMemo(() => {
const { email, firstName, lastName, ...rest } = initialValues;

Expand All @@ -182,6 +191,7 @@ export const useCreateAccount = props => {
return {
errors,
handleSubmit,
handleEnterKeyPress,
isDisabled: isSubmitting || isGettingDetails || recaptchaLoading,
initialValues: sanitizedInitialValues,
recaptchaWidgetProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ test('returns correct shape', () => {
"signInMutation" => undefined,
},
"handleCreateAccount": [Function],
"handleEnterKeyPress": [Function],
"handleForgotPassword": [Function],
"handleSubmit": [Function],
"isBusy": true,
Expand Down
9 changes: 9 additions & 0 deletions packages/peregrine/lib/talons/SignIn/useSignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ export const useSignIn = props => {
showCreateAccount();
}, [setDefaultUsername, showCreateAccount]);

const handleEnterKeyPress = useCallback(() => {
event => {
if (event.key === 'Enter') {
handleCreateAccount();
}
};
}, [handleCreateAccount]);

const errors = useMemo(
() =>
new Map([
Expand All @@ -177,6 +185,7 @@ export const useSignIn = props => {
return {
errors,
handleCreateAccount,
handleEnterKeyPress,
handleForgotPassword,
handleSubmit,
isBusy: isGettingDetails || isSigningIn || recaptchaLoading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ exports[`renders the correct tree 1`] = `
disabled={false}
onClick={[Function]}
onDragStart={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseEnter={[Function]}
Expand Down Expand Up @@ -453,7 +452,6 @@ exports[`should not render cancel button if isCancelButtonHidden is true 1`] = `
disabled={false}
onClick={[Function]}
onDragStart={[Function]}
onKeyDown={[Function]}
onKeyUp={[Function]}
onMouseDown={[Function]}
onMouseEnter={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const CreateAccount = props => {
errors,
handleCancel,
handleSubmit,
handleEnterKeyPress,
isDisabled,
initialValues,
recaptchaWidgetProps
Expand Down Expand Up @@ -60,6 +61,7 @@ const CreateAccount = props => {
disabled={isDisabled}
type="submit"
priority="high"
onKeyDown={handleEnterKeyPress}
data-cy="CreateAccount-submitButton"
>
<FormattedMessage
Expand Down
2 changes: 2 additions & 0 deletions packages/venia-ui/lib/components/SignIn/signIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const SignIn = props => {
const {
errors,
handleCreateAccount,
handleEnterKeyPress,
handleForgotPassword,
handleSubmit,
isBusy,
Expand Down Expand Up @@ -123,6 +124,7 @@ const SignIn = props => {
type="button"
onClick={handleCreateAccount}
data-cy="CreateAccount-initiateButton"
onKeyDown={handleEnterKeyPress}
>
<FormattedMessage
id={'signIn.createAccountText'}
Expand Down