Skip to content

Commit

Permalink
feat(input-phone): support onKeyDown and onKeyUp
Browse files Browse the repository at this point in the history
  • Loading branch information
clementprevot committed Aug 17, 2023
1 parent ff4c30f commit e209ae3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/fractal/src/components/InputPhone/InputPhone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const InputPhone = forwardRef<CombinedRefs, InputPhoneProps>(
label,
name,
onChange,
onKeyDown,
onKeyUp,
placeholder,
readOnly = false,
required = false,
Expand Down Expand Up @@ -327,6 +329,8 @@ export const InputPhone = forwardRef<CombinedRefs, InputPhoneProps>(
value={search}
onBlur={handleSearchBlur}
onChange={(_, newSearch) => handleSearch(newSearch, true)}
{...(isFunction(onKeyDown) ? { onKeyDown } : {})}
{...(isFunction(onKeyUp) ? { onKeyUp } : {})}
/>

{prefixes.map(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CountryCode } from 'libphonenumber-js'
import type { HTMLAttributes } from 'react'
import type { HTMLAttributes, KeyboardEvent } from 'react'

export type CountryDetails = {
countryCode: CountryCode
Expand Down Expand Up @@ -74,6 +74,11 @@ export interface InputPhoneProps
name?: string
/** Event handler called when the phone value is changed. */
onChange?: (newPhoneNumber: PhoneNumber, isValid?: boolean) => void
/** Event handler when a key is pressed down in one of the fields. */
onKeyDown: (event: KeyboardEvent<HTMLInputElement>) => void

/** Event handler when a key is released in one of the fields. */
onKeyUp: (event: KeyboardEvent<HTMLInputElement>) => void
/**
* A string to display when the text input is empty.
*
Expand Down

0 comments on commit e209ae3

Please sign in to comment.