From 407ccca8e9c55c5005c6ea16f20d3d00c2004cf9 Mon Sep 17 00:00:00 2001 From: Avior Date: Fri, 13 May 2022 12:11:57 +0200 Subject: [PATCH] fix: Allow to disable automatic icons Signed-off-by: Avior --- src/Input/index.tsx | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Input/index.tsx b/src/Input/index.tsx index 71d88eb..c5a6a3b 100644 --- a/src/Input/index.tsx +++ b/src/Input/index.tsx @@ -48,6 +48,11 @@ interface Props extends React.DetailedHTMLProps { break case 'number': baseProps.onWheel = (ev: React.WheelEvent) => ev.currentTarget.blur() - iconLeft = this.props.iconLeft ?? {icon: MinusSquare, transformer: (v) => { - let value = parseFloat(v) - if (isNaN(value)) { - value = 0 - } - return (value - this.ensureNumber(this.props.step, 1)).toString() - }} - iconRight = this.props.iconRight ?? {icon: PlusSquare, transformer: (v) => { - let value = parseFloat(v) - if (isNaN(value)) { - value = 0 - } - return (value + this.ensureNumber(this.props.step, 1)).toString() - }} + if (!this.props.disabled && !this.props.disableAutoIcons) { + iconLeft = this.props.iconLeft ?? {icon: MinusSquare, transformer: (v) => { + let value = parseFloat(v) + if (isNaN(value)) { + value = 0 + } + return (value - this.ensureNumber(this.props.step, 1)).toString() + }} + iconRight = this.props.iconRight ?? {icon: PlusSquare, transformer: (v) => { + let value = parseFloat(v) + if (isNaN(value)) { + value = 0 + } + return (value + this.ensureNumber(this.props.step, 1)).toString() + }} + } default: input = { {/* Right Icon */} {iconRight ? this.getIcon(iconRight, 'right') : - (this.props.choices && !this.props.disabled) && ( + (this.props.choices && !this.props.disabled && !this.props.disableAutoIcons) && ( ) } @@ -316,6 +323,7 @@ export default class Input extends React.PureComponent { if ('icon' in Icon) { return { + if (this.props.disabled) {return} const value = Icon.transformer(this.state.value ?? this.state.displayedValue ?? '') this.setState({ value: value, displayedValue: value, valueUpdate: true }) }} />