From 97a08423a1ac48f654e9c48af3131c4de457e98e Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sat, 19 Mar 2022 15:21:32 +0800 Subject: [PATCH] fix: button loading animate not work, close #5360 --- components/button/LoadingIcon.tsx | 68 +++++++++++++++++++ .../__tests__/__snapshots__/demo.test.js.snap | 10 +-- .../__snapshots__/index.test.js.snap | 4 +- components/button/button.tsx | 20 ++++-- .../__tests__/__snapshots__/demo.test.js.snap | 4 +- .../__tests__/__snapshots__/demo.test.js.snap | 2 +- .../__tests__/__snapshots__/demo.test.js.snap | 32 +++++++++ 7 files changed, 124 insertions(+), 16 deletions(-) create mode 100644 components/button/LoadingIcon.tsx diff --git a/components/button/LoadingIcon.tsx b/components/button/LoadingIcon.tsx new file mode 100644 index 000000000..938969688 --- /dev/null +++ b/components/button/LoadingIcon.tsx @@ -0,0 +1,68 @@ +import { defineComponent, nextTick } from 'vue'; +import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined'; +import Transition from '../_util/transition'; +const getCollapsedWidth = (node: HTMLSpanElement) => { + if (node) { + node.style.width = '0px'; + node.style.opacity = '0'; + node.style.transform = 'scale(0)'; + } +}; +const getRealWidth = (node: HTMLSpanElement) => { + nextTick(() => { + if (node) { + node.style.width = `${node.scrollWidth}px`; + node.style.opacity = '1'; + node.style.transform = 'scale(1)'; + } + }); +}; +const resetStyle = (node: HTMLSpanElement) => { + if (node && node.style) { + node.style.width = null; + node.style.opacity = null; + node.style.transform = null; + } +}; +export default defineComponent({ + name: 'LoadingIcon', + props: { + prefixCls: String, + loading: [Boolean, Object], + existIcon: Boolean, + }, + setup(props) { + return () => { + const { existIcon, prefixCls, loading } = props; + if (existIcon) { + return ( + + + + ); + } + const visible = !!loading; + return ( + { + setTimeout(() => { + getCollapsedWidth(node); + }); + }} + onAfterLeave={resetStyle} + > + {visible ? ( + + + + ) : null} + + ); + }; + }, +}); diff --git a/components/button/__tests__/__snapshots__/demo.test.js.snap b/components/button/__tests__/__snapshots__/demo.test.js.snap index 1753b8ede..7f48f7c3a 100644 --- a/components/button/__tests__/__snapshots__/demo.test.js.snap +++ b/components/button/__tests__/__snapshots__/demo.test.js.snap @@ -143,9 +143,9 @@ exports[`renders ./components/button/demo/icon.vue correctly 1`] = ` exports[`renders ./components/button/demo/loading.vue correctly 1`] = `
-
+
-
+
@@ -157,11 +157,11 @@ exports[`renders ./components/button/demo/loading.vue correctly 1`] = `
-
+
-
+
-
+
`; diff --git a/components/button/__tests__/__snapshots__/index.test.js.snap b/components/button/__tests__/__snapshots__/index.test.js.snap index 59584b43b..00b3398d8 100644 --- a/components/button/__tests__/__snapshots__/index.test.js.snap +++ b/components/button/__tests__/__snapshots__/index.test.js.snap @@ -36,9 +36,9 @@ exports[`Button renders Chinese characters correctly 3`] = ` `; -exports[`Button renders Chinese characters correctly 4`] = ``; +exports[`Button renders Chinese characters correctly 4`] = ``; -exports[`Button renders Chinese characters correctly 5`] = ``; +exports[`Button renders Chinese characters correctly 5`] = ``; exports[`Button renders Chinese characters correctly 6`] = ` +
-
+
diff --git a/components/input/__tests__/__snapshots__/demo.test.js.snap b/components/input/__tests__/__snapshots__/demo.test.js.snap index 43315f4b0..fca78a551 100644 --- a/components/input/__tests__/__snapshots__/demo.test.js.snap +++ b/components/input/__tests__/__snapshots__/demo.test.js.snap @@ -116,7 +116,7 @@ exports[`renders ./components/input/demo/search-input.vue correctly 1`] = `
`; -exports[`renders ./components/input/demo/search-input-loading.vue correctly 1`] = `


`; +exports[`renders ./components/input/demo/search-input-loading.vue correctly 1`] = `


`; exports[`renders ./components/input/demo/show-count.vue correctly 1`] = ` 10 / 20 diff --git a/components/page-header/__tests__/__snapshots__/demo.test.js.snap b/components/page-header/__tests__/__snapshots__/demo.test.js.snap index 3f19508aa..d2c9aa12b 100644 --- a/components/page-header/__tests__/__snapshots__/demo.test.js.snap +++ b/components/page-header/__tests__/__snapshots__/demo.test.js.snap @@ -70,8 +70,10 @@ exports[`renders ./components/page-header/demo/actions.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -81,8 +83,10 @@ exports[`renders ./components/page-header/demo/actions.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -92,8 +96,10 @@ exports[`renders ./components/page-header/demo/actions.vue correctly 1`] = ` class="ant-btn ant-btn-primary" type="button" > + + Primary @@ -325,8 +331,10 @@ exports[`renders ./components/page-header/demo/actions.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -336,8 +344,10 @@ exports[`renders ./components/page-header/demo/actions.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -347,8 +357,10 @@ exports[`renders ./components/page-header/demo/actions.vue correctly 1`] = ` class="ant-btn ant-btn-primary" type="button" > + + Primary @@ -749,8 +761,10 @@ exports[`renders ./components/page-header/demo/content.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -760,8 +774,10 @@ exports[`renders ./components/page-header/demo/content.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -771,8 +787,10 @@ exports[`renders ./components/page-header/demo/content.vue correctly 1`] = ` class="ant-btn ant-btn-primary" type="button" > + + Primary @@ -785,8 +803,10 @@ exports[`renders ./components/page-header/demo/content.vue correctly 1`] = ` style="padding: 0px;" type="button" > + + + + Operation @@ -967,8 +989,10 @@ exports[`renders ./components/page-header/demo/ghost.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -978,8 +1002,10 @@ exports[`renders ./components/page-header/demo/ghost.vue correctly 1`] = ` class="ant-btn ant-btn-primary" type="button" > + + Primary @@ -1205,8 +1231,10 @@ exports[`renders ./components/page-header/demo/responsive.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -1216,8 +1244,10 @@ exports[`renders ./components/page-header/demo/responsive.vue correctly 1`] = ` class="ant-btn" type="button" > + + Operation @@ -1227,8 +1257,10 @@ exports[`renders ./components/page-header/demo/responsive.vue correctly 1`] = ` class="ant-btn ant-btn-primary" type="button" > + + Primary