From 1b6a7a466485b65f582352cb14b223310c6bfc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E8=89=B3=E5=85=B5?= Date: Thu, 26 Feb 2026 11:14:27 +0800 Subject: [PATCH] fix(select): merge raw trigger element event handlers --- src/SelectInput/index.tsx | 19 +++++++++++++++++-- tests/Custom.test.tsx | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/SelectInput/index.tsx b/src/SelectInput/index.tsx index 4c22a537..abd8f089 100644 --- a/src/SelectInput/index.tsx +++ b/src/SelectInput/index.tsx @@ -219,14 +219,29 @@ export default React.forwardRef(function Selec }; if (RootComponent) { + const originProps = (RootComponent as any).props || {}; + const mergedProps = { ...originProps, ...domProps }; + + Object.keys(originProps).forEach((key) => { + const originVal = originProps[key]; + const domVal = domProps[key]; + + if (typeof originVal === 'function' && typeof domVal === 'function') { + mergedProps[key] = (...args: any[]) => { + domVal(...args); + originVal(...args); + }; + } + }); + if (React.isValidElement(RootComponent)) { return React.cloneElement(RootComponent, { - ...domProps, + ...mergedProps, ref: composeRef((RootComponent as any).ref, rootRef), }); } - return ; + return ; } return ( diff --git a/tests/Custom.test.tsx b/tests/Custom.test.tsx index 387bc81a..1e7e2e36 100644 --- a/tests/Custom.test.tsx +++ b/tests/Custom.test.tsx @@ -27,4 +27,25 @@ describe('Select.Custom', () => { expect(onPopupVisibleChange).toHaveBeenCalledWith(true); }); + + it('should not override raw input element event handlers', () => { + const onFocus = jest.fn(); + const onBlur = jest.fn(); + + const { getByPlaceholderText } = render( + + )} + />, + ); + + fireEvent.focus(getByPlaceholderText('focus me')); + fireEvent.blur(getByPlaceholderText('focus me')); + + expect(onFocus).toHaveBeenCalled(); + expect(onBlur).toHaveBeenCalled(); + }); });