From 33400eee8f002dc88de54ca3a0f4fd030d81de58 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 30 Jun 2022 10:21:31 +0800 Subject: [PATCH 1/9] chore: reduce css bundle size (#36307) --- components/select/style/single.less | 7 ------- components/style/core/iconfont.less | 5 +---- components/style/mixins/compatibility.less | 6 ------ components/style/mixins/modal-mask.less | 1 - 4 files changed, 1 insertion(+), 18 deletions(-) diff --git a/components/select/style/single.less b/components/select/style/single.less index 500dd72988..7bf6b36aa1 100644 --- a/components/select/style/single.less +++ b/components/select/style/single.less @@ -25,13 +25,6 @@ padding: 0; line-height: @select-height-without-border; transition: all 0.3s; - - // Firefox inline-block position calculation is not same as Chrome & Safari. Patch this: - @supports (-moz-appearance: meterbar) { - & { - line-height: @select-height-without-border; - } - } } .@{select-prefix-cls}-selection-item { diff --git a/components/style/core/iconfont.less b/components/style/core/iconfont.less index f257f569c8..597b8549e9 100644 --- a/components/style/core/iconfont.less +++ b/components/style/core/iconfont.less @@ -15,11 +15,8 @@ } } +.@{iconfont-css-prefix}-spin, .@{iconfont-css-prefix}-spin::before { display: inline-block; animation: loadingCircle 1s infinite linear; } -.@{iconfont-css-prefix}-spin { - display: inline-block; - animation: loadingCircle 1s infinite linear; -} diff --git a/components/style/mixins/compatibility.less b/components/style/mixins/compatibility.less index c5fb0dbc29..9464a754a7 100644 --- a/components/style/mixins/compatibility.less +++ b/components/style/mixins/compatibility.less @@ -2,12 +2,6 @@ // Placeholder text .placeholder(@color: @input-placeholder-color) { - // Firefox - /* stylelint-disable-next-line selector-no-vendor-prefix */ - &::-moz-placeholder { - opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526 - } - &::placeholder { color: @color; user-select: none; // https://github.com/ant-design/ant-design/pull/32639 diff --git a/components/style/mixins/modal-mask.less b/components/style/mixins/modal-mask.less index 344bb020fc..b406bc1b41 100644 --- a/components/style/mixins/modal-mask.less +++ b/components/style/mixins/modal-mask.less @@ -26,6 +26,5 @@ .box(fixed); overflow: auto; outline: 0; - -webkit-overflow-scrolling: touch; } } From 42e030edd98cb7cb8c8effc67816c735139614df Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Thu, 30 Jun 2022 11:11:01 +0800 Subject: [PATCH 2/9] fix: arrow compatibility (#36266) * fix: arrow campatibility * chore: code clean * chore: rm useless style * chore: code clean * fix: use inset * chore: bundlesize optimization * chore: rm useless style * chore: rm useless style --- components/date-picker/style/index.less | 5 ----- components/dropdown/style/index.less | 5 ----- components/popover/style/index.less | 1 - components/style/mixins/rounded-arrow.less | 1 + components/tooltip/style/index.less | 1 - 5 files changed, 1 insertion(+), 12 deletions(-) diff --git a/components/date-picker/style/index.less b/components/date-picker/style/index.less index cfcdb62ebf..f428f299d6 100644 --- a/components/date-picker/style/index.less +++ b/components/date-picker/style/index.less @@ -322,11 +322,6 @@ width: @arrow-size; height: @arrow-size; margin-left: @input-padding-horizontal-base * 1.5; - background: linear-gradient( - 135deg, - transparent 40%, - @calendar-bg 40% - ); // Use linear-gradient to prevent arrow from covering text box-shadow: 2px 2px 6px -2px fade(@black, 10%); // use spread radius to hide shadow over popover transition: left @animation-duration-slow ease-out; .roundedArrow(@arrow-size, 5px, @calendar-bg); diff --git a/components/dropdown/style/index.less b/components/dropdown/style/index.less index c800c13a7c..10f8b9db11 100644 --- a/components/dropdown/style/index.less +++ b/components/dropdown/style/index.less @@ -70,11 +70,6 @@ display: block; width: @popover-arrow-width; height: @popover-arrow-width; - background: linear-gradient( - 135deg, - transparent 40%, - @popover-bg 40% - ); // Use linear-gradient to prevent arrow from covering text .roundedArrow(@popover-arrow-width, 5px, @popover-bg); } diff --git a/components/popover/style/index.less b/components/popover/style/index.less index 92f3e4d8fb..b256228c6c 100644 --- a/components/popover/style/index.less +++ b/components/popover/style/index.less @@ -139,7 +139,6 @@ width: @popover-arrow-width; height: @popover-arrow-width; margin: auto; - background-color: @popover-bg; content: ''; pointer-events: auto; .roundedArrow(@popover-arrow-width, 5px); diff --git a/components/style/mixins/rounded-arrow.less b/components/style/mixins/rounded-arrow.less index 96503d4b26..1c8264336d 100644 --- a/components/style/mixins/rounded-arrow.less +++ b/components/style/mixins/rounded-arrow.less @@ -36,6 +36,7 @@ background-repeat: no-repeat; background-position: ceil(-@width + 1px) ceil(-@width + 1px); content: ''; + clip-path: inset(33% 33%); // For browsers that do not support path() clip-path: path( 'M @{a-x} @{a-y} A @{outer-radius-without-unit} @{outer-radius-without-unit} 0 0 1 @{b-x} @{b-y} L @{c-x} @{c-y} A @{inner-radius-without-unit} @{inner-radius-without-unit} 0 0 0 @{d-x} @{d-y} L @{e-x} @{e-y} A @{outer-radius-without-unit} @{outer-radius-without-unit} 0 0 1 @{f-x} @{f-y} L @{g-x} @{g-y} L @{h-x} @{h-y} Z' ); diff --git a/components/tooltip/style/index.less b/components/tooltip/style/index.less index b24c2f7675..d2ad5e1263 100644 --- a/components/tooltip/style/index.less +++ b/components/tooltip/style/index.less @@ -97,7 +97,6 @@ width: @tooltip-arrow-width; height: @tooltip-arrow-width; margin: auto; - background-color: transparent; content: ''; pointer-events: auto; .roundedArrow(@tooltip-arrow-width, 5px); From 5f933ebd2bdd9e5b49c3526a564f1317aaba740a Mon Sep 17 00:00:00 2001 From: Jamki <13414367591@163.com> Date: Thu, 30 Jun 2022 13:25:47 +0800 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20Fixed=20an=20error=20when=20the=20lo?= =?UTF-8?q?ading=20property=20of=20the=20Button=20component=E2=80=A6=20(#3?= =?UTF-8?q?6288)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Fixed an error when the loading property of the Button component was passed into null * Update components/button/button.tsx Obviously, this suggestion is more concise , thanks a lot Co-authored-by: afc163 * Update components/button/button.tsx * Update components/button/button.tsx Co-authored-by: kejianfeng Co-authored-by: afc163 --- components/button/button.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/button/button.tsx b/components/button/button.tsx index 379980f479..b83e91dfe6 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -190,7 +190,7 @@ const InternalButton: React.ForwardRefRenderFunction = (pr // =============== Update Loading =============== const loadingOrDelay: Loading = - typeof loading === 'object' && loading.delay ? loading.delay || true : !!loading; + typeof loading === 'boolean' ? loading : (loading?.delay || true); React.useEffect(() => { let delayTimer: number | null = null; From 201a66793fb993ca7199223df0892af566dfbdf6 Mon Sep 17 00:00:00 2001 From: Yuki Zhang Date: Fri, 1 Jul 2022 11:53:49 +0800 Subject: [PATCH 4/9] test: move test cases to testing lib for Spin (#36317) * test: move test cases to testing lib for Spin * fix: types * fix: lint --- ...index.test.js.snap => index.test.tsx.snap} | 0 .../{delay.test.js => delay.test.tsx} | 27 ++++++++++++------- .../{index.test.js => index.test.tsx} | 25 ++++++++--------- 3 files changed, 30 insertions(+), 22 deletions(-) rename components/spin/__tests__/__snapshots__/{index.test.js.snap => index.test.tsx.snap} (100%) rename components/spin/__tests__/{delay.test.js => delay.test.tsx} (55%) rename components/spin/__tests__/{index.test.js => index.test.tsx} (63%) diff --git a/components/spin/__tests__/__snapshots__/index.test.js.snap b/components/spin/__tests__/__snapshots__/index.test.tsx.snap similarity index 100% rename from components/spin/__tests__/__snapshots__/index.test.js.snap rename to components/spin/__tests__/__snapshots__/index.test.tsx.snap diff --git a/components/spin/__tests__/delay.test.js b/components/spin/__tests__/delay.test.tsx similarity index 55% rename from components/spin/__tests__/delay.test.js rename to components/spin/__tests__/delay.test.tsx index cf362080de..64e2998e4f 100644 --- a/components/spin/__tests__/delay.test.js +++ b/components/spin/__tests__/delay.test.tsx @@ -1,4 +1,3 @@ -import { mount } from 'enzyme'; import React from 'react'; // eslint-disable-next-line import/no-named-as-default import { render } from '@testing-library/react'; @@ -7,33 +6,41 @@ import Spin from '..'; import { sleep } from '../../../tests/utils'; jest.mock('lodash/debounce'); -debounce.mockImplementation(jest.requireActual('lodash/debounce')); +(debounce as jest.Mock).mockImplementation((...args: any[]) => + jest.requireActual('lodash/debounce')(...args), +); describe('delay spinning', () => { it("should render with delay when it's mounted with spinning=true and delay", () => { - const wrapper = mount(); - expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(false); + const { container } = render(); + expect(container.querySelector('.ant-spin')?.classList.contains('ant-spin-spinning')).toEqual( + false, + ); }); it('should render when delay is init set', async () => { - const wrapper = mount(); + const { container } = render(); - expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(false); + expect(container.querySelector('.ant-spin')?.classList.contains('ant-spin-spinning')).toEqual( + false, + ); // use await not jest.runAllTimers() // because of https://github.com/facebook/jest/issues/3465 await sleep(500); - wrapper.update(); - expect(wrapper.find('.ant-spin').at(0).hasClass('ant-spin-spinning')).toEqual(true); + expect(container.querySelector('.ant-spin')?.classList.contains('ant-spin-spinning')).toEqual( + true, + ); }); it('should cancel debounce function when unmount', async () => { const debouncedFn = jest.fn(); const cancel = jest.fn(); - debouncedFn.cancel = cancel; - debounce.mockReturnValueOnce(debouncedFn); + (debouncedFn as any).cancel = cancel; + (debounce as jest.Mock).mockReturnValueOnce(debouncedFn); const { unmount } = render(); + expect(cancel).not.toHaveBeenCalled(); unmount(); expect(cancel).toHaveBeenCalled(); diff --git a/components/spin/__tests__/index.test.js b/components/spin/__tests__/index.test.tsx similarity index 63% rename from components/spin/__tests__/index.test.js rename to components/spin/__tests__/index.test.tsx index 1fa0aaf7f9..ca3a8646c8 100644 --- a/components/spin/__tests__/index.test.js +++ b/components/spin/__tests__/index.test.tsx @@ -1,4 +1,3 @@ -import { mount } from 'enzyme'; import React from 'react'; // eslint-disable-next-line import/no-named-as-default import { render } from '@testing-library/react'; @@ -11,19 +10,21 @@ describe('Spin', () => { rtlTest(Spin); it('should only affect the spin element when set style to a nested xx', () => { - const wrapper = mount( + const { container } = render(
content
, ); - expect(wrapper.find('.ant-spin-nested-loading').at(0).prop('style')).toBeFalsy(); - expect(wrapper.find('.ant-spin').at(0).prop('style').background).toBe('red'); + expect((container.querySelector('.ant-spin-nested-loading')! as HTMLElement).style.length).toBe( + 0, + ); + expect((container.querySelector('.ant-spin')! as HTMLElement).style.background).toBe('red'); }); it("should render custom indicator when it's set", () => { const customIndicator =
; - const wrapper = mount(); - expect(wrapper.render()).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment().firstChild).toMatchSnapshot(); }); it('should be controlled by spinning', () => { @@ -34,19 +35,19 @@ describe('Spin', () => { }); it('if indicator set null should not be render default indicator', () => { - const wrapper = mount(); - expect(wrapper.render()).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment().firstChild).toMatchSnapshot(); }); it('should support static method Spin.setDefaultIndicator', () => { Spin.setDefaultIndicator(); - const wrapper = mount(); - expect(wrapper.render()).toMatchSnapshot(); + const { asFragment } = render(); + expect(asFragment().firstChild).toMatchSnapshot(); Spin.setDefaultIndicator(null); }); it('should render 0', () => { - const wrapper = mount({0}); - expect(wrapper.find('.ant-spin-container').at(0).text()).toBe('0'); + const { container } = render({0}); + expect(container.querySelector('.ant-spin-container')?.textContent).toBe('0'); }); }); From efe6d7c8a186fb62ecefb811863cf1173cc0d1db Mon Sep 17 00:00:00 2001 From: Yuki Zhang Date: Fri, 1 Jul 2022 11:55:03 +0800 Subject: [PATCH 5/9] test: move test cases to testing lib for Switch (#36326) * add * test: wave * fix: type --- .../{demo.test.js.snap => demo.test.ts.snap} | 0 ...index.test.js.snap => index.test.tsx.snap} | 0 .../__tests__/{demo.test.js => demo.test.ts} | 0 .../{index.test.js => index.test.tsx} | 12 ++++----- components/switch/__tests__/wave.test.js | 27 ------------------- components/switch/__tests__/wave.test.tsx | 27 +++++++++++++++++++ components/switch/index.tsx | 7 +++-- typings/custom-typings.d.ts | 2 -- 8 files changed, 38 insertions(+), 37 deletions(-) rename components/switch/__tests__/__snapshots__/{demo.test.js.snap => demo.test.ts.snap} (100%) rename components/switch/__tests__/__snapshots__/{index.test.js.snap => index.test.tsx.snap} (100%) rename components/switch/__tests__/{demo.test.js => demo.test.ts} (100%) rename components/switch/__tests__/{index.test.js => index.test.tsx} (68%) delete mode 100644 components/switch/__tests__/wave.test.js create mode 100644 components/switch/__tests__/wave.test.tsx diff --git a/components/switch/__tests__/__snapshots__/demo.test.js.snap b/components/switch/__tests__/__snapshots__/demo.test.ts.snap similarity index 100% rename from components/switch/__tests__/__snapshots__/demo.test.js.snap rename to components/switch/__tests__/__snapshots__/demo.test.ts.snap diff --git a/components/switch/__tests__/__snapshots__/index.test.js.snap b/components/switch/__tests__/__snapshots__/index.test.tsx.snap similarity index 100% rename from components/switch/__tests__/__snapshots__/index.test.js.snap rename to components/switch/__tests__/__snapshots__/index.test.tsx.snap diff --git a/components/switch/__tests__/demo.test.js b/components/switch/__tests__/demo.test.ts similarity index 100% rename from components/switch/__tests__/demo.test.js rename to components/switch/__tests__/demo.test.ts diff --git a/components/switch/__tests__/index.test.js b/components/switch/__tests__/index.test.tsx similarity index 68% rename from components/switch/__tests__/index.test.js rename to components/switch/__tests__/index.test.tsx index 8f0ee630fa..f5b9835864 100644 --- a/components/switch/__tests__/index.test.js +++ b/components/switch/__tests__/index.test.tsx @@ -1,10 +1,9 @@ -import { mount } from 'enzyme'; import React from 'react'; import Switch from '..'; import focusTest from '../../../tests/shared/focusTest'; import mountTest from '../../../tests/shared/mountTest'; import rtlTest from '../../../tests/shared/rtlTest'; -import { sleep } from '../../../tests/utils'; +import { sleep, fireEvent, render } from '../../../tests/utils'; import { resetWarned } from '../../_util/warning'; describe('Switch', () => { @@ -13,17 +12,18 @@ describe('Switch', () => { rtlTest(Switch); it('should has click wave effect', async () => { - const wrapper = mount(); - wrapper.find('.ant-switch').getDOMNode().click(); + const { container } = render(); + fireEvent.click(container.querySelector('.ant-switch')!); await sleep(0); - expect(wrapper.find('button').getDOMNode().getAttribute('ant-click-animating')).toBe('true'); + expect(container.querySelector('button')!.getAttribute('ant-click-animating')).toBe('true'); }); it('warning if set `value`', () => { resetWarned(); const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - mount(); + const props = { value: true } as any; + render(); expect(errorSpy).toHaveBeenCalledWith( 'Warning: [antd: Switch] `value` is not a valid prop, do you mean `checked`?', ); diff --git a/components/switch/__tests__/wave.test.js b/components/switch/__tests__/wave.test.js deleted file mode 100644 index 79014d25cf..0000000000 --- a/components/switch/__tests__/wave.test.js +++ /dev/null @@ -1,27 +0,0 @@ -import { mount } from 'enzyme'; -import React from 'react'; -import Switch from '..'; -import { sleep } from '../../../tests/utils'; - -describe('click wave effect', () => { - async function click(wrapper) { - wrapper.find('.ant-switch').getDOMNode().click(); - wrapper.find('.ant-switch').getDOMNode().dispatchEvent(new Event('transitionstart')); - await sleep(20); - wrapper.find('.ant-switch').getDOMNode().dispatchEvent(new Event('animationend')); - await sleep(20); - } - - it('should have click wave effect', async () => { - const wrapper = mount(); - await click(wrapper); - const waveInstance = wrapper.find('InternalWave').instance(); - const resetEffect = jest.spyOn(waveInstance, 'resetEffect'); - await click(wrapper); - expect(resetEffect).toHaveBeenCalledTimes(1); - const event = new Event('animationend'); - Object.assign(event, { animationName: 'fadeEffect' }); - wrapper.find('.ant-switch').getDOMNode().dispatchEvent(event); - resetEffect.mockRestore(); - }); -}); diff --git a/components/switch/__tests__/wave.test.tsx b/components/switch/__tests__/wave.test.tsx new file mode 100644 index 0000000000..6d18ac3f74 --- /dev/null +++ b/components/switch/__tests__/wave.test.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import Switch from '..'; +import { sleep, render, fireEvent } from '../../../tests/utils'; + +describe('click wave effect', () => { + async function click(container: HTMLElement) { + fireEvent.click(container.querySelector('.ant-switch')!); + container.querySelector('.ant-switch')!.dispatchEvent(new Event('transitionstart')); + await sleep(20); + container.querySelector('.ant-switch')!.dispatchEvent(new Event('animationend')); + await sleep(20); + } + + it('should have click wave effect', async () => { + const { container } = render(); + await click(container); + await click(container); + + expect( + container.querySelector('.ant-switch')!.getAttribute('ant-switch-click-animating'), + ).toBeFalsy(); + + const event = new Event('animationend'); + Object.assign(event, { animationName: 'fadeEffect' }); + container.querySelector('.ant-switch')!.dispatchEvent(event); + }); +}); diff --git a/components/switch/index.tsx b/components/switch/index.tsx index 3bfa6ca364..c519de18e0 100755 --- a/components/switch/index.tsx +++ b/components/switch/index.tsx @@ -10,7 +10,10 @@ import warning from '../_util/warning'; import Wave from '../_util/wave'; export type SwitchSize = 'small' | 'default'; -export type SwitchChangeEventHandler = (checked: boolean, event: MouseEvent) => void; +export type SwitchChangeEventHandler = ( + checked: boolean, + event: React.MouseEvent, +) => void; export type SwitchClickEventHandler = SwitchChangeEventHandler; export interface SwitchProps { @@ -37,7 +40,7 @@ interface CompoundedComponent __ANT_SWITCH: boolean; } -const Switch = React.forwardRef( +const Switch = React.forwardRef( ( { prefixCls: customizePrefixCls, diff --git a/typings/custom-typings.d.ts b/typings/custom-typings.d.ts index 76112ff63a..e5c2274ab8 100644 --- a/typings/custom-typings.d.ts +++ b/typings/custom-typings.d.ts @@ -24,8 +24,6 @@ declare module 'rc-checkbox'; declare module 'rc-rate'; -declare module 'rc-switch'; - declare module '*.json' { const value: any; export const version: string; From 8ab7851870c8a9d24ac5341aafb7f1230314f5b5 Mon Sep 17 00:00:00 2001 From: MadCcc <1075746765@qq.com> Date: Fri, 1 Jul 2022 20:00:25 +0800 Subject: [PATCH 6/9] test: update snapshot (#36344) * test: update snapshot * test: update snapshot --- .../__snapshots__/demo-extend.test.ts.snap | 25 +++++++++++++++++++ .../__tests__/__snapshots__/demo.test.js.snap | 25 +++++++++++++++++++ .../__snapshots__/index.test.js.snap | 4 +++ .../__snapshots__/components.test.js.snap | 7 ++++++ 4 files changed, 61 insertions(+) diff --git a/components/collapse/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/collapse/__tests__/__snapshots__/demo-extend.test.ts.snap index 80eb733684..65d9848797 100644 --- a/components/collapse/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/collapse/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -9,6 +9,7 @@ exports[`renders ./components/collapse/demo/accordion.md extend context correctl class="ant-collapse-item" >