Skip to content

Commit b9afe24

Browse files
committed
fix: improve clear button logic
1 parent 3c7572d commit b9afe24

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/InputNumber.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -663,30 +663,27 @@ const InputNumber = React.forwardRef<InputNumberRef, InputNumberProps>((props, r
663663
if (allowClear) {
664664
const needClear = !disabled && !readOnly && !decimalValue.isEmpty();
665665
const clearIconCls = `${prefixCls}-clear-icon`;
666-
const iconNode =
667-
typeof allowClear === 'object' && allowClear.clearIcon ? allowClear.clearIcon : '✖';
666+
const clearOptions = typeof allowClear === 'object' ? allowClear : {};
667+
const { clearIcon = '✖', clearValue } = clearOptions;
668668

669669
const onInternalClear = () => {
670-
const value = getMiniDecimal(typeof allowClear === 'object' && allowClear.clearValue);
671-
670+
const value = getMiniDecimal(clearValue);
672671
triggerValueUpdate(value, false);
672+
onClear?.();
673673
};
674674

675675
clearButton = (
676676
<button
677677
type="button"
678678
tabIndex={-1}
679-
onClick={() => {
680-
onInternalClear();
681-
onClear?.();
682-
}}
679+
onClick={onInternalClear}
683680
onMouseDown={(e) => e.preventDefault()}
684681
className={clsx(`${prefixCls}-clear-icon`, {
685682
[`${clearIconCls}-hidden`]: !needClear,
686683
[`${clearIconCls}-has-suffix`]: !!suffix,
687684
})}
688685
>
689-
{iconNode}
686+
{clearIcon}
690687
</button>
691688
);
692689
}

0 commit comments

Comments
 (0)