From 1ce9a4922440d5047a2a1f63aa7d29cb16018070 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Tue, 23 Aug 2022 15:58:44 +1200 Subject: [PATCH] Focus name field when it's empty --- SetForm.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/SetForm.tsx b/SetForm.tsx index 06ed1f9..d5260ea 100644 --- a/SetForm.tsx +++ b/SetForm.tsx @@ -19,7 +19,9 @@ export default function SetForm({ end: set.reps.toString().length, }); const weightRef = useRef(null); + const repsRef = useRef(null); const handleSubmit = () => { + if (!name) return; save({ name, reps: Number(reps), @@ -40,6 +42,8 @@ export default function SetForm({ onChangeText={setName} autoCorrect={false} selectTextOnFocus + autoFocus={!name} + onSubmitEditing={() => repsRef.current?.focus()} /> weightRef.current?.focus()} selection={selection} onSelectionChange={e => setSelection(e.nativeEvent.selection)} - autoFocus + autoFocus={!!name} selectTextOnFocus blurOnSubmit={false} + ref={repsRef} /> {set.created?.replace('T', ' ')} -