Moins de complexité dans lea saisie de somme monétaire
Si je comprends bien, ce code servait à obtenir [ €456] plutôt que [€
456]. Je pense que l'avantage n'est pas flagrant, et surtout, ça
provoque un gros 🐛 sur iOS : impossible de refermer le clavier quand
on est sur l'input. On ne peut même plus changer d'onglet du navigateur
!
pull/540/head
parent
3ec3311f12
commit
6c288a92ed
|
@ -1,7 +1,7 @@
|
|||
import classnames from 'classnames'
|
||||
import { omit } from 'ramda'
|
||||
import React, { Component } from 'react'
|
||||
import { debounce, isIE } from '../../utils'
|
||||
import { debounce } from '../../utils'
|
||||
import './CurrencyInput.css'
|
||||
|
||||
let isCurrencyPrefixed = language =>
|
||||
|
@ -21,39 +21,13 @@ class CurrencyInput extends Component {
|
|||
: this.props.onChange
|
||||
input = React.createRef()
|
||||
|
||||
getSnapshotBeforeUpdate = () => {
|
||||
if (!this.input.current) {
|
||||
return
|
||||
}
|
||||
return this.input.current.selectionStart
|
||||
}
|
||||
componentDidMount() {
|
||||
this.adaptInputSize()
|
||||
}
|
||||
adaptInputSize = () => {
|
||||
// Because ch mesurement in IE is not consistent with other browsers, we have to apply a multiplier
|
||||
// https://stackoverflow.com/questions/17825638/css3-ch-unit-inconsistent-between-ie9-and-other-browsers
|
||||
const widthMultiplier = isIE() ? 1.4 : 1
|
||||
|
||||
if (this.input.current && isCurrencyPrefixed(this.props.language))
|
||||
this.input.current.style.width =
|
||||
widthMultiplier * (this.input.current.value.length + 0.2) + 'ch'
|
||||
}
|
||||
componentDidUpdate = (_, __, cursorPosition) => {
|
||||
if (!this.input.current) {
|
||||
return
|
||||
}
|
||||
this.input.current.selectionStart = cursorPosition
|
||||
this.input.current.selectionEnd = cursorPosition
|
||||
this.adaptInputSize()
|
||||
}
|
||||
handleChange = event => {
|
||||
let value = event.target.value
|
||||
value = value
|
||||
.replace(/,/g, '.')
|
||||
.replace(/[^\d.]/g, '')
|
||||
.replace(/\.(.*)\.(.*)/g, '$1.$2')
|
||||
this.setState({ value }, this.adaptInputSize)
|
||||
this.setState({ value })
|
||||
|
||||
if (value.endsWith('.')) {
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue