From cd2304de17515f7f1e3da09c0e8dda6d9f027322 Mon Sep 17 00:00:00 2001 From: Avior Date: Wed, 28 Sep 2022 14:47:15 +0200 Subject: [PATCH] fix: Props event not updating internal value Signed-off-by: Avior --- src/Input/index.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Input/index.tsx b/src/Input/index.tsx index 7760a05..503bdcc 100644 --- a/src/Input/index.tsx +++ b/src/Input/index.tsx @@ -120,7 +120,11 @@ export default class Input extends React.PureComponent { } } - public async componentDidUpdate(_: Props, prevStates: States) { + + public async componentDidUpdate(prevProps: Props, prevStates: States) { + if (prevProps.value !== this.props.value) { + this.onChange(this.props.value?.toString() ?? '') + } if (prevStates.value !== this.state.value) { if (this.props.onValue) { this.props.onValue(this.state.value ?? '') @@ -354,16 +358,16 @@ export default class Input extends React.PureComponent { * handle the change event of the input * @param event the event */ - private onChange = async (event: React.ChangeEvent) => { + private onChange = async (event: React.ChangeEvent|string) => { // get the input - const value = event.currentTarget.value + const value = typeof event === 'string' ? event : event.currentTarget.value // console.log("onChange", value) if (typeof value !== 'string') { return } - if (this.props.onChange) { + if (this.props.onChange && typeof event !== 'string') { this.props.onChange(event) }