Skip to content

Commit

Permalink
feat: Add submit form on pressing enter, Closes #154
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Feb 25, 2020
1 parent 2a540f7 commit eb75c05
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/onboarding/screens/sign-in.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,6 +14,10 @@ import { selectAppName } from '@store/onboarding/selectors';
import { doStoreSeed } from '@store/wallet';
import { ErrorLabel } from '@components/error-label';

const textAreaRef = createRef<HTMLTextAreaElement>();

const hasLineReturn = (input: string) => input.includes('\n');

interface SignInProps {
next: () => void;
back: () => void;
Expand Down Expand Up @@ -72,9 +76,14 @@ export const SignIn: React.FC<SignInProps> = props => {
autoCapitalize="false"
spellCheck={false}
style={{ resize: 'none' }}
onChange={(evt: React.FormEvent<HTMLInputElement>) => {
ref={textAreaRef}
onChange={async (evt: React.FormEvent<HTMLInputElement>) => {
setSeedError(null);
setSeed(evt.currentTarget.value);
if (hasLineReturn(evt.currentTarget.value)) {
textAreaRef.current?.blur();
await onSubmit();
}
}}
/>
{seedError && (
Expand Down

0 comments on commit eb75c05

Please sign in to comment.