From c9bfe6e3856aa306d36ced51b9cbdc63c5d10933 Mon Sep 17 00:00:00 2001 From: tate Date: Mon, 5 Sep 2022 15:36:29 +1000 Subject: [PATCH] allow date input type --- .../src/components/molecules/Input/Input.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/components/src/components/molecules/Input/Input.tsx b/components/src/components/molecules/Input/Input.tsx index 444eda4d..e217f8c2 100644 --- a/components/src/components/molecules/Input/Input.tsx +++ b/components/src/components/molecules/Input/Input.tsx @@ -41,7 +41,7 @@ type BaseProps = Omit & { /** The tabindex attribute of the input element. */ tabIndex?: NativeInputProps['tabIndex'] /** The data type the input. */ - type?: 'number' | 'text' | 'email' + type?: 'number' | 'text' | 'email' | 'date' | 'datetime-local' /** Inserts text after the input text. */ units?: string /** The value attribute of the input element. */ @@ -95,6 +95,13 @@ type WithTypeNumber = { min?: NativeInputProps['min'] } +type WithTypeDate = { + type?: 'date' | 'datetime-local' + max?: NativeInputProps['max'] + min?: NativeInputProps['min'] + step?: NativeInputProps['step'] +} + interface InputParentProps { $size: 'medium' | 'large' | 'extraLarge' $disabled?: boolean @@ -360,7 +367,8 @@ const Units = styled.span( `, ) -type Props = BaseProps & (WithTypeEmail | WithTypeText | WithTypeNumber) +type Props = BaseProps & + (WithTypeEmail | WithTypeText | WithTypeNumber | WithTypeDate) export const Input = React.forwardRef( ( @@ -417,7 +425,7 @@ export const Input = React.forwardRef( : undefined const hasError = error ? true : undefined - const inputType = type === 'number' ? 'number' : 'text' + const inputType = type === 'email' ? 'text' : type const handleInput = React.useCallback( (event: React.FormEvent) => {