From b5150adee7e20772a62ba61f9d7404cb9f5e25fb Mon Sep 17 00:00:00 2001 From: Pedro Mendoza Date: Thu, 30 Dec 2021 18:03:11 -0600 Subject: [PATCH 1/2] The focus method was added to allow the developers to implement the focus action --- README.md | 1 + lib/index.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 1766ed2..31e3f90 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ export default App; - `getCallingCode`: () => string | undefined - `getNumberAfterPossiblyEliminatingZero`: () => {number: string , formattedNumber: string }; - `isValidNumber`: (number: string) => boolean +- `focus`: () => undefined ## FAQ diff --git a/lib/index.js b/lib/index.js index b89c388..c1cd982 100644 --- a/lib/index.js +++ b/lib/index.js @@ -66,6 +66,10 @@ export default class PhoneInput extends PureComponent { } }; + focus = () => { + this.input && this.input.focus(); + } + onSelect = (country) => { const { onChangeCountry } = this.props; this.setState( @@ -230,6 +234,9 @@ export default class PhoneInput extends PureComponent { keyboardType="number-pad" autoFocus={autoFocus} {...textInputProps} + ref={(input) => { + this.input = input; + }} /> From 6d5d0e7e8d4b49ebeb0dbd61e7d4dbc0432fd07b Mon Sep 17 00:00:00 2001 From: Pedro Mendoza Date: Fri, 12 Apr 2024 23:36:26 -0600 Subject: [PATCH 2/2] Adding focus method typing --- lib/index.d.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index cd625e5..7c48313 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -298,10 +298,17 @@ export default class PhoneInput extends Component< | "AX"; getCallingCode: () => string | undefined; isValidNumber: (number: string) => boolean; + focus: () => void; onSelect: (country: Country) => void; - getNumberAfterPossiblyEliminatingZero: () => {number: string , formattedNumber: string }; + getNumberAfterPossiblyEliminatingZero: () => { + number: string; + formattedNumber: string; + }; onChangeText: (text: string) => void; render(): JSX.Element; } -export function isValidNumber(number: string, countryCode: CountryCode ): boolean; \ No newline at end of file +export function isValidNumber( + number: string, + countryCode: CountryCode +): boolean;