From 6a5f53d6e69203b948576f65f79c33b7342ef015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=99=A8=E9=98=B3?= <59002875+ZZZCNY@users.noreply.github.com> Date: Mon, 14 Nov 2022 11:16:34 +0800 Subject: [PATCH 01/13] docs(Layout): update demo style to `sticky` (#38542) * Update fixed.md * Update demo.test.ts.snap * update snapshot --- .../layout/__tests__/__snapshots__/demo-extend.test.ts.snap | 4 ++-- components/layout/__tests__/__snapshots__/demo.test.ts.snap | 4 ++-- components/layout/demo/fixed.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap index 043613917f..b627325fb3 100644 --- a/components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -420,7 +420,7 @@ exports[`renders ./components/layout/demo/fixed.md extend context correctly 1`] >
} />); expect(errSpy).toHaveBeenCalledWith( @@ -139,7 +139,7 @@ describe('DropdownButton', () => { ); errSpy.mockRestore(); }); - it('should not console Error then `overlay` not in props', () => { + it('should not console Error when `overlay` not in props', () => { const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); render(); expect(errSpy).not.toHaveBeenCalled(); From 3c96997210f580bb8057948d3ce7d8cfdd3e0e59 Mon Sep 17 00:00:00 2001 From: JackLiR8 <45257542+JackLiR8@users.noreply.github.com> Date: Tue, 15 Nov 2022 18:40:04 +0800 Subject: [PATCH 08/13] fix(Input.Search): pressing enter key don't trigger `onSearch` while loading (#38575) (#38578) --- components/input/Search.tsx | 2 +- components/input/__tests__/Search.test.tsx | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/input/Search.tsx b/components/input/Search.tsx index 42e34abc43..aa247afef6 100644 --- a/components/input/Search.tsx +++ b/components/input/Search.tsx @@ -75,7 +75,7 @@ const Search = React.forwardRef((props, ref) => { }; const onPressEnter = (e: React.KeyboardEvent) => { - if (composedRef.current) { + if (composedRef.current || loading) { return; } onSearch(e); diff --git a/components/input/__tests__/Search.test.tsx b/components/input/__tests__/Search.test.tsx index a891512de4..bd771631c2 100644 --- a/components/input/__tests__/Search.test.tsx +++ b/components/input/__tests__/Search.test.tsx @@ -161,6 +161,15 @@ describe('Input.Search', () => { expect(asFragmentWithEnterButton().firstChild).toMatchSnapshot(); }); + it('should not trigger onSearch when press enter while loading', () => { + const onSearch = jest.fn(); + const { container } = render( + , + ); + fireEvent.keyDown(container.querySelector('input')!, { key: 'Enter', keyCode: 13 }); + expect(onSearch).not.toHaveBeenCalled(); + }); + it('should support addonAfter and suffix for loading', () => { const { asFragment } = render(); const { asFragment: asFragmentWithEnterButton } = render( From 1ca984a19ca8d6eebede1cc25bb7d9282048f4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kiner-tang=28=E6=96=87=E8=BE=89=29?= <1127031143@qq.com> Date: Tue, 15 Nov 2022 22:20:02 +0800 Subject: [PATCH 09/13] feat(modal): support pass mousePosition to control modal's animation origin position (#38584) * feat: support pass mousePosition to control modal's animation target position * feat: update test case * Update components/modal/demo/custom-mouse-position.md Co-authored-by: afc163 * docs: update docs Co-authored-by: afc163 --- components/modal/Modal.tsx | 7 ++- components/modal/__tests__/Modal.test.tsx | 15 +++++ .../__snapshots__/demo-extend.test.ts.snap | 11 ++++ .../__tests__/__snapshots__/demo.test.ts.snap | 11 ++++ .../modal/demo/custom-mouse-position.md | 57 +++++++++++++++++++ 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 components/modal/demo/custom-mouse-position.md diff --git a/components/modal/Modal.tsx b/components/modal/Modal.tsx index efc66a7e38..8ad9308d89 100644 --- a/components/modal/Modal.tsx +++ b/components/modal/Modal.tsx @@ -15,7 +15,9 @@ import { canUseDocElement } from '../_util/styleChecker'; import warning from '../_util/warning'; import { getConfirmLocale } from './locale'; -let mousePosition: { x: number; y: number } | null; +type MousePosition = { x: number; y: number } | null; + +let mousePosition: MousePosition; // ref: https://github.com/ant-design/ant-design/issues/15795 const getClickPosition = (e: MouseEvent) => { @@ -91,6 +93,7 @@ export interface ModalProps { modalRender?: (node: React.ReactNode) => React.ReactNode; focusTriggerAfterClose?: boolean; children?: React.ReactNode; + mousePosition?: MousePosition; } type getContainerFunc = () => HTMLElement; @@ -231,7 +234,7 @@ const Modal: React.FC = props => { wrapClassName={wrapClassNameExtended} footer={footer === undefined ? defaultFooter : footer} visible={open || visible} - mousePosition={mousePosition} + mousePosition={restProps.mousePosition ?? mousePosition} onClose={handleCancel} closeIcon={closeIconToRender} focusTriggerAfterClose={focusTriggerAfterClose} diff --git a/components/modal/__tests__/Modal.test.tsx b/components/modal/__tests__/Modal.test.tsx index 18a75da560..1bdd5945ab 100644 --- a/components/modal/__tests__/Modal.test.tsx +++ b/components/modal/__tests__/Modal.test.tsx @@ -92,6 +92,21 @@ describe('Modal', () => { ).toBeTruthy(); }); + it('custom mouse position', () => { + const Demo = () => { + const containerRef = React.useRef(null); + return ( +
+ containerRef.current!} mousePosition={{x: 100, y: 100}} /> +
+ ); + }; + const { container } = render(); + expect( + (container.querySelectorAll('.ant-modal')[0] as HTMLDivElement).style.transformOrigin, + ).toBe('100px 100px'); + }); + it('deprecated warning', () => { resetWarned(); const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); diff --git a/components/modal/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/modal/__tests__/__snapshots__/demo-extend.test.ts.snap index e542b889b3..ad20686acf 100644 --- a/components/modal/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/modal/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -104,6 +104,17 @@ exports[`renders ./components/modal/demo/confirm-router.md extend context correc `; +exports[`renders ./components/modal/demo/custom-mouse-position.md extend context correctly 1`] = ` + +`; + exports[`renders ./components/modal/demo/dark.md extend context correctly 1`] = ` +`; + exports[`renders ./components/modal/demo/dark.md correctly 1`] = ` + +

Some contents...

+

Some contents...

+

Some contents...

+
+ + ); +}; + +export default App; +``` From 08e4598baa0efa8a22ee0bf1e354dfce27247d33 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 15 Nov 2022 23:35:16 +0800 Subject: [PATCH 10/13] fix(Table): don't trigger sort when pressing enter in filter dropdown (#38585) close #38579 --- .../table/__tests__/Table.sorter.test.tsx | 34 ++++++++++++++++--- .../table/hooks/useFilter/FilterWrapper.tsx | 10 +++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/components/table/__tests__/Table.sorter.test.tsx b/components/table/__tests__/Table.sorter.test.tsx index 6238c4f38e..90ac8a63b3 100644 --- a/components/table/__tests__/Table.sorter.test.tsx +++ b/components/table/__tests__/Table.sorter.test.tsx @@ -39,7 +39,7 @@ describe('Table.sorter', () => { container ?.querySelector('.ant-table-tbody') ?.querySelectorAll('tr') - ?.forEach(tr => { + ?.forEach((tr) => { namesList.push(tr.querySelector('td')?.textContent); }); return namesList; @@ -129,7 +129,7 @@ describe('Table.sorter', () => { expect(getNameColumn()?.getAttribute('aria-sort')).toEqual('descending'); }); - it('sort records with keydown', () => { + it('sort records when press enter', () => { const { container } = render(createTable()); // ascend @@ -141,6 +141,30 @@ describe('Table.sorter', () => { expect(renderedNames(container)).toEqual(['Tom', 'Lucy', 'Jack', 'Jerry']); }); + // https://github.com/ant-design/ant-design/issues/38579 + it('should not sort records when press enter in filter dropdown', () => { + const { container } = render( + createTable({ + columns: [ + { + ...column, + filters: [{ text: 'J', value: 'J' }], + onFilter: (value: any, record: any) => record.name.includes(value), + filterDropdownOpen: true, + }, + ], + }), + ); + + // don't trigger ascend + fireEvent.keyDown(container.querySelector('.ant-table-filter-dropdown')!, { keyCode: 13 }); + expect(renderedNames(container)).toEqual(['Jack', 'Lucy', 'Tom', 'Jerry']); + + // don't trigger descend + fireEvent.keyDown(container.querySelector('.ant-table-filter-dropdown')!, { keyCode: 13 }); + expect(renderedNames(container)).toEqual(['Jack', 'Lucy', 'Tom', 'Jerry']); + }); + describe('can be controlled by sortOrder', () => { it('single', () => { const { container } = render( @@ -434,7 +458,7 @@ describe('Table.sorter', () => { class TableTest extends React.Component { state = { pagination: {} }; - onChange: TableProps['onChange'] = pagination => { + onChange: TableProps['onChange'] = (pagination) => { this.setState({ pagination }); }; @@ -494,7 +518,7 @@ describe('Table.sorter', () => { pagination: {}, }; - onChange: TableProps['onChange'] = pagination => { + onChange: TableProps['onChange'] = (pagination) => { this.setState({ pagination }); }; @@ -561,7 +585,7 @@ describe('Table.sorter', () => { pagination: {}, }; - onChange: TableProps['onChange'] = pagination => { + onChange: TableProps['onChange'] = (pagination) => { this.setState({ pagination }); }; diff --git a/components/table/hooks/useFilter/FilterWrapper.tsx b/components/table/hooks/useFilter/FilterWrapper.tsx index fc40a90971..d92a1d9fdf 100644 --- a/components/table/hooks/useFilter/FilterWrapper.tsx +++ b/components/table/hooks/useFilter/FilterWrapper.tsx @@ -1,12 +1,20 @@ import * as React from 'react'; +import KeyCode from 'rc-util/lib/KeyCode'; export interface FilterDropdownMenuWrapperProps { children?: React.ReactNode; className?: string; } +const onKeyDown: React.KeyboardEventHandler = (event) => { + const { keyCode } = event; + if (keyCode === KeyCode.ENTER) { + event.stopPropagation(); + } +}; + const FilterDropdownMenuWrapper = (props: FilterDropdownMenuWrapperProps) => ( -
e.stopPropagation()}> +
e.stopPropagation()} onKeyDown={onKeyDown}> {props.children}
); From 52dedca8ed7017a4f64072daa272161043e5a260 Mon Sep 17 00:00:00 2001 From: Matthew <50069872+SavelevMatthew@users.noreply.github.com> Date: Wed, 16 Nov 2022 07:23:51 +0500 Subject: [PATCH 11/13] fix: Pass custom prefixCls to Typography from Base (#38580) (#38586) * fix: Pass custom prefixCls to Typography from Base (#38580) * test: Added test for typography custom prefixCls --- components/typography/Base/index.tsx | 3 ++- .../typography/__tests__/prefixCls.test.tsx | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 components/typography/__tests__/prefixCls.test.tsx diff --git a/components/typography/Base/index.tsx b/components/typography/Base/index.tsx index ccff24bebb..7ef36168b5 100644 --- a/components/typography/Base/index.tsx +++ b/components/typography/Base/index.tsx @@ -277,7 +277,7 @@ const Base = React.forwardRef((props, ref) => { const cssLineClamp = mergedEnableEllipsis && rows > 1 && cssEllipsis; // >>>>> Expand - const onExpandClick: React.MouseEventHandler = e => { + const onExpandClick: React.MouseEventHandler = (e) => { setExpanded(true); ellipsisConfig.onExpand?.(e); }; @@ -510,6 +510,7 @@ const Base = React.forwardRef((props, ref) => { }, className, )} + prefixCls={customizePrefixCls} style={{ ...style, WebkitLineClamp: cssLineClamp ? rows : undefined, diff --git a/components/typography/__tests__/prefixCls.test.tsx b/components/typography/__tests__/prefixCls.test.tsx new file mode 100644 index 0000000000..5ab0c0dfa6 --- /dev/null +++ b/components/typography/__tests__/prefixCls.test.tsx @@ -0,0 +1,20 @@ +import React from 'react'; +import { render } from '../../../tests/utils'; + +import Base from '../Base'; + +describe('Typography keep prefixCls', () => { + describe('Base', () => { + it('should support className when has prefix', () => { + const { container: wrapper } = render( + + test prefixCls + , + ); + expect( + (wrapper.firstChild as HTMLElement)?.className.includes('custom-prefixCls'), + ).toBeTruthy(); + expect((wrapper.firstChild as HTMLElement)?.className.includes('custom-class')).toBeTruthy(); + }); + }); +}); From 1a4c69692676bc965cfe4301344ac4b93292b5fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Nov 2022 13:02:49 +0800 Subject: [PATCH 12/13] chore(deps-dev): bump typescript from 4.8.4 to 4.9.3 (#38604) * chore(deps-dev): bump typescript from 4.8.4 to 4.9.3 Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.8.4 to 4.9.3. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/commits) --- updated-dependencies: - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * chore: fix ts error in test case * Update Table.pagination.test.tsx Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: afc163 --- components/table/__tests__/Table.pagination.test.tsx | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/table/__tests__/Table.pagination.test.tsx b/components/table/__tests__/Table.pagination.test.tsx index 70a059d926..731dd6a6dc 100644 --- a/components/table/__tests__/Table.pagination.test.tsx +++ b/components/table/__tests__/Table.pagination.test.tsx @@ -418,7 +418,7 @@ describe('Table.pagination', () => { * to `pagination`, since they misunderstand that `pagination` can accept a boolean value. */ it('Accepts pagination as true', () => { - const { asFragment } = render(createTable({ pagination: true } as TableProps)); + const { asFragment } = render(createTable({ pagination: true as any } as TableProps)); expect(asFragment().firstChild).toMatchSnapshot(); }); diff --git a/package.json b/package.json index 4d996b867b..a9624d2f6f 100644 --- a/package.json +++ b/package.json @@ -293,7 +293,7 @@ "stylelint-declaration-block-no-ignored-properties": "^2.1.0", "stylelint-order": "^5.0.0", "theme-switcher": "^1.0.2", - "typescript": "~4.8.4", + "typescript": "~4.9.3", "webpack-bundle-analyzer": "^4.1.0", "xhr-mock": "^2.4.1", "yaml-front-matter": "^4.0.0" From f36a01a6474b5fd0d4d902b56931092844eaf657 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 17 Nov 2022 14:07:37 +0800 Subject: [PATCH 13/13] chore: update snapshot --- .../__tests__/__snapshots__/demo-extend.test.ts.snap | 2 +- .../layout/__tests__/__snapshots__/demo.test.ts.snap | 2 +- .../__tests__/__snapshots__/demo-extend.test.ts.snap | 11 +++++++++++ .../modal/__tests__/__snapshots__/demo.test.ts.snap | 11 +++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap index d915adaa47..4ccce9523e 100644 --- a/components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -656,7 +656,7 @@ exports[`renders ./components/layout/demo/fixed.tsx extend context correctly 1`]