Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,21 +151,30 @@ import 'react-phone-input-2/lib/style.css'
```

### Contents
- [Style](#style)
- [Events](#events)
- [Regions](#regions)
- [Localization](#predefined-localization)
- [Local area codes](#local-area-codes)
- [Custom masks](#custom-masks)
- [Custom area codes](#custom-area-codes)
- [Other props](#other-props)
- [Custom localization](#custom-localization)
- [Guides](#guides)
- [Phone without dialCode](#phone-without-dialcode)
- [Check validity of the phone number](#check-validity-of-the-phone-number)
- [CDN](#cdn)
- [Contributing](#contributing)
- [Support](https://www.paypal.me/bloomber/20)
- [React-Phone-Input-2](#react-phone-input-2)
- [Installation](#installation)
- [Usage](#usage)
- [Demo 1 (UI) - [Demo 2 (CSS)](https://bl00mber.github.io/react-phone-input-2-css.html)](#demo-1-ui---demo-2-css)
- [Options](#options)
- [Contents](#contents)
- [Style](#style)
- [Events](#events)
- [Regions](#regions)
- [Predefined localization](#predefined-localization)
- [Local area codes](#local-area-codes)
- [Flexible mask](#flexible-mask)
- [Custom masks](#custom-masks)
- [Custom area codes](#custom-area-codes)
- [Other props](#other-props)
- [Custom localization](#custom-localization)
- [Preserve countries order](#preserve-countries-order)
- [Guides](#guides)
- [Phone without dialCode](#phone-without-dialcode)
- [Check validity of the phone number](#check-validity-of-the-phone-number)
- [Clear country](#clear-country)
- [CDN](#cdn)
- [Contributing](#contributing)
- [License](#license)

### Style
<table>
Expand Down Expand Up @@ -405,6 +414,10 @@ Example: `+61 (2), +61 (02)`
<td> disableCountryGuess </td>
<td> false </td>
</tr>
<tr>
<td> clearSearch </td>
<td> false </td>
</tr>
</table>

### Custom localization
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class PhoneInput extends React.Component {
disableSearchIcon: PropTypes.bool,
disableInitialCountryGuess: PropTypes.bool,
disableCountryGuess: PropTypes.bool,
clearSearch: PropTypes.bool,

regions: PropTypes.oneOfType([
PropTypes.string,
Expand Down Expand Up @@ -136,6 +137,7 @@ class PhoneInput extends React.Component {
disableSearchIcon: false,
disableInitialCountryGuess: false,
disableCountryGuess: false,
clearSearch: false,

regions: '',

Expand Down Expand Up @@ -616,6 +618,7 @@ class PhoneInput extends React.Component {
formattedNumber
}, () => {
this.cursorToEnd();
if(this.props.clearSearch) this.setState({searchValue: ''})
if (this.props.onChange) this.props.onChange(formattedNumber.replace(/[^0-9]+/g,''), this.getCountryData(), e, formattedNumber);
});
}
Expand Down
15 changes: 15 additions & 0 deletions test/ReactPhoneInput.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ describe('<PhoneInput /> other props', () => {
fireEvent.change(phoneInput.querySelector('.search-box'), {target: {value: 'undefined'}})
expect(phoneInput.querySelector('.no-entries-message')).toBeTruthy()
})

test('clear search value after country selection', () => {
const { container: phoneInput } = render(
<PhoneInput
enableSearch
clearSearch
/>)

fireEvent.click(phoneInput.querySelector('.selected-flag'))
fireEvent.change(phoneInput.querySelector('.search-box'), {target: {value: 'gb'}})
expect(phoneInput.querySelector('.country-list').children.length).toBe(2) // search field & 1 search result
fireEvent.click(phoneInput.querySelector('.country-list').children[1])
fireEvent.click(phoneInput.querySelector('.selected-flag'))
expect(phoneInput.querySelector('.search-box').value).toBe('')
})
})


Expand Down