From 1492f680268873567357197a3ba0613b6659d513 Mon Sep 17 00:00:00 2001 From: zombiej Date: Fri, 11 Mar 2022 16:44:09 +0800 Subject: [PATCH] fix: clone input should not replace customize props --- src/Selector/Input.tsx | 27 ++++++----- tests/Select.test.tsx | 108 +++++++++++++++++++++++------------------ 2 files changed, 76 insertions(+), 59 deletions(-) diff --git a/src/Selector/Input.tsx b/src/Selector/Input.tsx index 10d387bb2..841b74bdd 100644 --- a/src/Selector/Input.tsx +++ b/src/Selector/Input.tsx @@ -58,17 +58,16 @@ const Input: React.RefForwardingComponent = ( ) => { let inputNode: React.ComponentElement = inputElement || ; + const { ref: originRef, props: originProps } = inputNode; + const { - ref: originRef, - props: { - onKeyDown: onOriginKeyDown, - onChange: onOriginChange, - onMouseDown: onOriginMouseDown, - onCompositionStart: onOriginCompositionStart, - onCompositionEnd: onOriginCompositionEnd, - style, - }, - } = inputNode; + onKeyDown: onOriginKeyDown, + onChange: onOriginChange, + onMouseDown: onOriginMouseDown, + onCompositionStart: onOriginCompositionStart, + onCompositionEnd: onOriginCompositionEnd, + style, + } = originProps; inputNode = React.cloneElement(inputNode, { id, @@ -79,7 +78,7 @@ const Input: React.RefForwardingComponent = ( type: 'search', autoFocus, className: classNames(`${prefixCls}-selection-search-input`, inputNode?.props?.className), - style: { ...style, opacity: editable ? null : 0 }, + role: 'combobox', 'aria-expanded': open, 'aria-haspopup': 'listbox', @@ -92,6 +91,12 @@ const Input: React.RefForwardingComponent = ( maxLength, readOnly: !editable, unselectable: !editable ? 'on' : null, + + ...originProps, + + // Override over origin props + style: { ...style, opacity: editable ? null : 0 }, + onKeyDown: (event: React.KeyboardEvent) => { onKeyDown(event); if (onOriginKeyDown) { diff --git a/tests/Select.test.tsx b/tests/Select.test.tsx index 143535bdd..095d3207d 100644 --- a/tests/Select.test.tsx +++ b/tests/Select.test.tsx @@ -827,55 +827,68 @@ describe('Select.Basic', () => { expect(focusSpy).toHaveBeenCalled(); }); - it('combobox could customize input element', () => { - const onKeyDown = jest.fn(); - const onChange = jest.fn(); - const onMouseDown = jest.fn(); - const onCompositionStart = jest.fn(); - const onCompositionEnd = jest.fn(); - const textareaRef = jest.fn(); - const mouseDownPreventDefault = jest.fn(); - const wrapper = mount( -