Skip to content

Commit

Permalink
fix #107
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor de la Fouchardiere committed Feb 14, 2024
1 parent eadb9e5 commit 019613a
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
@@ -505,6 +505,16 @@ describe('components/MuiTelInput', () => {
expectButtonIsFlagOf('FR')
})

// https://github.com/viclafouch/mui-tel-input/issues/107
test('should reset clean correctly the value', async () => {
render(<MuiTelWrapper defaultCountry="FR" disableFormatting />)
const inputElement = getInputElement()
await userEvent.clear(inputElement)
await typeInInputElement('2')
await selectCountry('BE')
expect(getInputElement().value).toBe('+32')
})

/** Copy doesn't work in user-event@beta */
// test('should fire the onCopy prop', async () => {
// const user = userEvent.setup({
7 changes: 3 additions & 4 deletions src/shared/hooks/usePhoneDigits.ts
Original file line number Diff line number Diff line change
@@ -268,11 +268,10 @@ export default function usePhoneDigits({

if (isoCode) {
const callingCodeOfPreviousCountry = getCallingCodeOfCountry(isoCode)
const callingCodeWithPlus = `+${callingCodeOfPreviousCountry}`
// if the input value start with wrong calling code, set it to empty string
inputValueWithoutCallingCode = inputValue.startsWith(
`+${callingCodeOfPreviousCountry}`
)
? removeOccurrence(inputValue, `+${callingCodeOfPreviousCountry}`)
inputValueWithoutCallingCode = inputValue.startsWith(callingCodeWithPlus)
? removeOccurrence(inputValue, callingCodeWithPlus)
: ''
}

0 comments on commit 019613a

Please sign in to comment.