From 0e007451d24ff7c00eb312544d9e052e79515054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Mon, 28 Sep 2026 10:35:56 +0800 Subject: [PATCH] fix: preserve zero-valued step handlers --- src/StepHandler.tsx | 8 ++++++-- tests/renderability.test.tsx | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/renderability.test.tsx diff --git a/src/StepHandler.tsx b/src/StepHandler.tsx index eccd003b..53cdb0f0 100644 --- a/src/StepHandler.tsx +++ b/src/StepHandler.tsx @@ -1,5 +1,5 @@ /* eslint-disable react/no-unknown-property */ -import { raf } from '@rc-component/util'; +import { isReactRenderable, raf } from '@rc-component/util'; import { clsx } from 'clsx'; import * as React from 'react'; @@ -104,7 +104,11 @@ export default function StepHandler({ className={mergedClassName} style={style} > - {children || } + {isReactRenderable(children) ? ( + children + ) : ( + + )} ); } diff --git a/tests/renderability.test.tsx b/tests/renderability.test.tsx new file mode 100644 index 00000000..fb6cad4c --- /dev/null +++ b/tests/renderability.test.tsx @@ -0,0 +1,20 @@ +import React from 'react'; +import { fireEvent, render } from '@testing-library/react'; +import InputNumber from '../src'; + +it('renders zero step handlers and keeps them interactive', () => { + const onChange = jest.fn(); + const { getByRole } = render( + , + ); + const up = getByRole('button', { name: 'Increase Value' }); + const down = getByRole('button', { name: 'Decrease Value' }); + expect(up.textContent).toBe('0'); + expect(down.textContent).toBe('0'); + fireEvent.mouseDown(up); + fireEvent.mouseUp(up); + expect(onChange).toHaveBeenLastCalledWith(3); + fireEvent.mouseDown(down); + fireEvent.mouseUp(down); + expect(onChange).toHaveBeenLastCalledWith(2); +});