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

Auto focus all CTA buttons #25

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion src/ui/pages/BackupWallet/BackupWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import CopyIcon from 'jsx:src/ui/assets/copy.svg';
import { ZStack } from 'src/ui/ui-kit/ZStack';
import { SecretInput } from 'src/ui/components/SecretInput';
import { UnstyledButton } from 'src/ui/ui-kit/UnstyledButton';
import { focusNode } from 'src/ui/shared/focusNode';
import { WithConfetti } from '../GetStarted/components/DecorativeMessage/DecorativeMessage';
import { DecorativeMessage } from '../GetStarted/components/DecorativeMessage';
import { clipboardWarning } from './clipboardWarning';
Expand Down Expand Up @@ -359,7 +360,12 @@ function VerifySuccess({ seedType }: { seedType: SeedType }) {
</UIText>
</VStack>
</FillView>
<Button style={{ marginTop: 'auto' }} as={Link} to="/overview">
<Button
ref={focusNode}
style={{ marginTop: 'auto' }}
as={Link}
to="/overview"
>
Finish
</Button>
<PageBottom />
Expand Down
2 changes: 2 additions & 0 deletions src/ui/pages/GetStarted/GenerateWallet/GenerateWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NavigationTitle } from 'src/ui/components/NavigationTitle';
import { getError } from 'src/shared/errors/getError';
import { WithPasswordSession } from 'src/ui/components/VerifyUser/WithPasswordSession';
import { PageBottom } from 'src/ui/components/PageBottom';
import { focusNode } from 'src/ui/shared/focusNode';
import {
DecorativeMessage,
DecorativeMessageDone,
Expand Down Expand Up @@ -125,6 +126,7 @@ function GenerateWalletView() {
</UIText>
) : null}
<Button
ref={focusNode}
disabled={finalizeMutation.isLoading}
onClick={async () => {
finalizeMutation.mutate(data.address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ function AddressImportMessagesView({ values }: { values: BareWallet[] }) {
trigger();
}
}, [ready, trigger]);
const autoFocusRef = useRef<HTMLButtonElement | null>(null);
useEffect(() => {
if (ready) {
autoFocusRef.current?.focus();
}
}, [ready]);
return (
<PageColumn>
<PageTop />
Expand All @@ -178,6 +184,7 @@ function AddressImportMessagesView({ values }: { values: BareWallet[] }) {
) : null}
<Button
as={animated.button}
ref={autoFocusRef}
disabled={!ready || finalizeMutation.isLoading}
style={style}
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useEffect, useRef } from 'react';
import { useMutation } from 'react-query';
import { useNavigate } from 'react-router-dom';
import { PageColumn } from 'src/ui/components/PageColumn';
Expand Down Expand Up @@ -29,6 +29,13 @@ function PrivateKeyImportFlow({
onSubmit: () => void;
isSubmitting: boolean;
}) {
const autoFocusRef = useRef<HTMLButtonElement | null>(null);
const isDonePreparing = !isSubmitting;
useEffect(() => {
if (isDonePreparing) {
autoFocusRef.current?.focus();
}
}, [isDonePreparing]);
return (
<>
<VStack gap={8}>
Expand All @@ -51,6 +58,7 @@ function PrivateKeyImportFlow({
</VStack>

<Button
ref={autoFocusRef}
style={{ marginTop: 'auto', marginBottom: 16 }}
onClick={onSubmit}
disabled={isSubmitting}
Expand Down
3 changes: 3 additions & 0 deletions src/ui/shared/focusNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function focusNode<T extends HTMLElement>(node: T | null) {
node?.focus();
}