Skip to content

Commit

Permalink
allow date input type
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Sep 5, 2022
1 parent eebf585 commit c9bfe6e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions components/src/components/molecules/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type BaseProps = Omit<FieldBaseProps, 'inline'> & {
/** 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. */
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
(
Expand Down Expand Up @@ -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<HTMLInputElement>) => {
Expand Down

0 comments on commit c9bfe6e

Please sign in to comment.