Skip to content

Commit

Permalink
fix: preserve an existing "inputmode" attribute on the input element (c…
Browse files Browse the repository at this point in the history
…loses #372)
  • Loading branch information
dm4t2 committed Mar 24, 2023
1 parent 4e2c0b6 commit e9fb330
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/currencyInput.ts
Expand Up @@ -70,9 +70,9 @@ export class CurrencyInput {
}
if (this.options.autoDecimalDigits) {
this.options.hideNegligibleDecimalDigitsOnFocus = false
this.el.setAttribute('inputmode', 'numeric')
} else {
this.el.setAttribute('inputmode', 'decimal')
}
if (!this.el.getAttribute('inputmode')) {
this.el.setAttribute('inputmode', this.options.autoDecimalDigits ? 'numeric' : 'decimal')
}
this.currencyFormat = new CurrencyFormat(this.options)
this.numberMask = this.options.autoDecimalDigits ? new AutoDecimalDigitsInputMask(this.currencyFormat) : new DefaultInputMask(this.currencyFormat)
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/currencyInput.spec.ts
Expand Up @@ -23,6 +23,25 @@ describe('Currency Input', () => {
})
})

describe('init', () => {
it('should preserve an existing "inputmode" attribute on the input element', () => {
document.body.innerHTML = `<input type="text" inputmode="text">`
el = document.querySelector('input') as HTMLInputElement
options = {
locale: 'en',
currency: 'EUR',
autoDecimalDigits: true
}
currencyInput = new CurrencyInput({
el,
options,
onInput: vi.fn(),
onChange: vi.fn()
})
expect(el.getAttribute('inputmode')).toBe('text')
})
})

describe('setValue', () => {
it('should update the input value', () => {
currencyInput.setValue(1)
Expand Down

0 comments on commit e9fb330

Please sign in to comment.