From eb75c05f801f45446aeca33d33f828d16b5bac06 Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Tue, 25 Feb 2020 12:25:23 +0100 Subject: [PATCH] feat: Add submit form on pressing enter, Closes #154 --- src/components/onboarding/screens/sign-in.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/onboarding/screens/sign-in.tsx b/src/components/onboarding/screens/sign-in.tsx index c4ef8e98fc2..ce299daa78c 100644 --- a/src/components/onboarding/screens/sign-in.tsx +++ b/src/components/onboarding/screens/sign-in.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useState, createRef } from 'react'; import { Screen, ScreenBody, ScreenActions, Title, PoweredBy, ScreenFooter } from '@blockstack/connect'; import { ScreenHeader } from '@components/connected-screen-header'; import { Box, Text, Input, Flex, Button } from '@blockstack/ui'; @@ -14,6 +14,10 @@ import { selectAppName } from '@store/onboarding/selectors'; import { doStoreSeed } from '@store/wallet'; import { ErrorLabel } from '@components/error-label'; +const textAreaRef = createRef(); + +const hasLineReturn = (input: string) => input.includes('\n'); + interface SignInProps { next: () => void; back: () => void; @@ -72,9 +76,14 @@ export const SignIn: React.FC = props => { autoCapitalize="false" spellCheck={false} style={{ resize: 'none' }} - onChange={(evt: React.FormEvent) => { + ref={textAreaRef} + onChange={async (evt: React.FormEvent) => { setSeedError(null); setSeed(evt.currentTarget.value); + if (hasLineReturn(evt.currentTarget.value)) { + textAreaRef.current?.blur(); + await onSubmit(); + } }} /> {seedError && (