diff --git a/components/sender/__tests__/index.test.tsx b/components/sender/__tests__/index.test.tsx index 1190aa60..64009ff6 100644 --- a/components/sender/__tests__/index.test.tsx +++ b/components/sender/__tests__/index.test.tsx @@ -109,4 +109,28 @@ describe('Sender Component', () => { expect(onSubmit).toHaveBeenCalledWith('bamboo'); }); }); + + it('Sender.Header can be focus', () => { + const { container } = render( + + + + } + />, + ); + + const inputEle = container.querySelector('.target')!; + inputEle.focus(); + expect(document.activeElement).toEqual(inputEle); + + // Click on the header + fireEvent.mouseDown(container.querySelector('.ant-sender-header')!); + expect(document.activeElement).toEqual(inputEle); + + // Click on the content + fireEvent.mouseDown(container.querySelector('.ant-sender-content')!); + expect(document.activeElement).toEqual(container.querySelector('textarea')); + }); }); diff --git a/components/sender/index.tsx b/components/sender/index.tsx index 565bb4de..29dcceaf 100644 --- a/components/sender/index.tsx +++ b/components/sender/index.tsx @@ -211,7 +211,7 @@ function Sender(props: SenderProps, ref: React.Ref) { }; // ============================ Focus ============================= - const onInternalMouseDown: React.MouseEventHandler = (e) => { + const onContentMouseDown: React.MouseEventHandler = (e) => { // If input focused but click on the container, // input will lose focus. // We call `preventDefault` to prevent this behavior @@ -250,14 +250,13 @@ function Sender(props: SenderProps, ref: React.Ref) { ref={mergedContainerRef} className={mergedCls} style={{ ...contextConfig.style, ...style }} - onMouseDown={onInternalMouseDown} > {/* Header */} {header && ( {header} )} -
+
{/* Prefix */} {prefix && (