From a6c539918a7cba4791fb51f72c61051d668377e1 Mon Sep 17 00:00:00 2001 From: Florian BOUILLON Date: Wed, 12 Jul 2023 14:55:58 +0200 Subject: [PATCH] fix: strict input not sending infos Signed-off-by: Florian BOUILLON --- src/Input/index.tsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Input/index.tsx b/src/Input/index.tsx index 5b6455b..b5f2d9c 100644 --- a/src/Input/index.tsx +++ b/src/Input/index.tsx @@ -320,11 +320,10 @@ export default class Input extends React.Component { } if (typeof newValue === 'string') { - this.setState({value: newValue, displayedValue: newValue, valueUpdate: true}) + this.onChange(newValue) return } - - this.setState({displayedValue: newValue.display, value: newValue.value, valueUpdate: true}) + this.onChange(newValue.value) } /** @@ -382,9 +381,17 @@ export default class Input extends React.Component { value = Math.min(max, Math.max(min, val)).toString() } - if (this.props.strictChoices) { - this.setState({ displayedValue: value, valueUpdate: true }) - return + let displayedValue = value + + if (this.props.choices) { + const item = this.props.choices.find((it) => typeof it === 'string' ? it === value : it.value === value) + if (this.props.strictChoices && !item) { + this.setState({ displayedValue: displayedValue, valueUpdate: true }) + return + } + if (item && typeof item !== 'string') { + displayedValue = item?.display + } } if (this.props.onChange && typeof event === 'object') { @@ -394,7 +401,7 @@ export default class Input extends React.Component { this.props.onValue?.(value) - this.setState({ value: value, displayedValue: value, valueUpdate: true }) + this.setState({ value: value, displayedValue: displayedValue, valueUpdate: true }) } }