From 6c288a92ed6ed46e7d309cc773092205bfef75a7 Mon Sep 17 00:00:00 2001 From: Mael Date: Fri, 17 May 2019 11:34:09 +0200 Subject: [PATCH] =?UTF-8?q?Moins=20de=20complexit=C3=A9=20dans=20lea=20sai?= =?UTF-8?q?sie=20de=20somme=20mon=C3=A9taire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 :bug: sur iOS : impossible de refermer le clavier quand on est sur l'input. On ne peut même plus changer d'onglet du navigateur ! --- .../components/CurrencyInput/CurrencyInput.js | 30 ++----------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/source/components/CurrencyInput/CurrencyInput.js b/source/components/CurrencyInput/CurrencyInput.js index f9fd66eb3..36b216a0f 100644 --- a/source/components/CurrencyInput/CurrencyInput.js +++ b/source/components/CurrencyInput/CurrencyInput.js @@ -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