From 77070f9f7467feffaca1bee6a7ab141189568b55 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 9 Nov 2021 23:14:44 +0100 Subject: anastasis-webui: fix telephone input --- .../src/components/fields/NumberInput.tsx | 49 ++++++++++++---------- .../src/pages/home/AttributeEntryScreen.tsx | 4 +- .../src/pages/home/SecretSelectionScreen.tsx | 4 +- .../pages/home/authMethod/AuthMethodSmsSetup.tsx | 4 +- 4 files changed, 34 insertions(+), 27 deletions(-) (limited to 'packages') diff --git a/packages/anastasis-webui/src/components/fields/NumberInput.tsx b/packages/anastasis-webui/src/components/fields/NumberInput.tsx index 2afb242b8..e1489eafa 100644 --- a/packages/anastasis-webui/src/components/fields/NumberInput.tsx +++ b/packages/anastasis-webui/src/components/fields/NumberInput.tsx @@ -10,7 +10,7 @@ export interface TextInputProps { bind: [string, (x: string) => void]; } -export function NumberInput(props: TextInputProps): VNode { +export function PhoneNumberInput(props: TextInputProps): VNode { const inputRef = useRef(null); useLayoutEffect(() => { if (props.grabFocus) { @@ -18,26 +18,33 @@ export function NumberInput(props: TextInputProps): VNode { } }, [props.grabFocus]); const value = props.bind[0]; - const [dirty, setDirty] = useState(false) - const showError = dirty && props.error - return (
- -
- {setDirty(true); props.bind[1]((e.target as HTMLInputElement).value)}} - ref={inputRef} - style={{ display: "block" }} /> + const [dirty, setDirty] = useState(false); + const showError = dirty && props.error; + return ( +
+ +
+ { + setDirty(true); + props.bind[1]((e.target as HTMLInputElement).value); + }} + ref={inputRef} + style={{ display: "block" }} + /> +
+ {showError &&

{props.error}

}
- {showError &&

{props.error}

} -
); } diff --git a/packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx b/packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx index 86a2f08ee..557718458 100644 --- a/packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx +++ b/packages/anastasis-webui/src/pages/home/AttributeEntryScreen.tsx @@ -3,7 +3,7 @@ import { isAfter, parse } from "date-fns"; import { h, VNode } from "preact"; import { useState } from "preact/hooks"; import { DateInput } from "../../components/fields/DateInput"; -import { NumberInput } from "../../components/fields/NumberInput"; +import { PhoneNumberInput } from "../../components/fields/NumberInput"; import { TextInput } from "../../components/fields/TextInput"; import { useAnastasisContext } from "../../context/anastasis"; import { AnastasisClientFrame, withProcessLabel } from "./index"; @@ -95,7 +95,7 @@ function AttributeEntryField(props: AttributeEntryFieldProps): VNode { bind={[props.value, props.setValue]} />} {props.spec.type === 'number' && -
-
-