From df5db65397941150ad9ba4a7f04cbaf95940231c Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Mon, 17 Sep 2018 10:20:23 +0800 Subject: [PATCH] update wave & tag & tag snapshots --- components/_util/wave.jsx | 60 ++++++++++------ .../__snapshots__/RangePicker.test.js.snap | 2 +- components/locale-provider/index.jsx | 2 +- .../__tests__/__snapshots__/demo.test.js.snap | 12 ++-- components/tag/Tag.jsx | 29 ++++---- .../__tests__/__snapshots__/demo.test.js.snap | 50 ++++++++------ .../__snapshots__/index.test.js.snap | 13 ++++ components/tag/__tests__/index.test.js | 69 +++++++++++++------ components/tag/demo/control.md | 4 +- components/tag/demo/controlled.md | 2 +- components/tag/index.en-US.md | 2 +- components/tag/index.zh-CN.md | 2 +- 12 files changed, 160 insertions(+), 87 deletions(-) create mode 100644 components/tag/__tests__/__snapshots__/index.test.js.snap diff --git a/components/_util/wave.jsx b/components/_util/wave.jsx index 849b0c24e..82d4c733f 100644 --- a/components/_util/wave.jsx +++ b/components/_util/wave.jsx @@ -24,22 +24,18 @@ export default { return true }, - onClick (node) { + onClick (node, waveColor) { if (node.className.indexOf('-leave') >= 0) { return } this.removeExtraStyleNode() const { insertExtraNode } = this.$props - const extraNode = document.createElement('div') + this.extraNode = document.createElement('div') + const extraNode = this.extraNode extraNode.className = 'ant-click-animating-node' - const attributeName = insertExtraNode ? 'ant-click-animating' : 'ant-click-animating-without-extra-node' + const attributeName = this.getAttributeName() node.removeAttribute(attributeName) node.setAttribute(attributeName, 'true') - // Get wave color from target - const waveColor = - getComputedStyle(node).getPropertyValue('border-top-color') || // Firefox Compatible - getComputedStyle(node).getPropertyValue('border-color') || - getComputedStyle(node).getPropertyValue('background-color') // Not white or transparnt or grey if (waveColor && waveColor !== '#ffffff' && @@ -56,20 +52,14 @@ export default { if (insertExtraNode) { node.appendChild(extraNode) } - const transitionEnd = () => { - node.removeAttribute(attributeName) - this.removeExtraStyleNode() - if (insertExtraNode) { - node.removeChild(extraNode) - } - TransitionEvents.removeEndEventListener(node, transitionEnd) - } - TransitionEvents.addEndEventListener(node, transitionEnd) + TransitionEvents.addEndEventListener(node, this.onTransitionEnd) }, bindAnimationEvent (node) { - if (node.getAttribute('disabled') || - node.className.indexOf('disabled') >= 0) { + if (!node || + !node.getAttribute || + node.getAttribute('disabled') || + node.className.indexOf('disabled') >= 0) { return } const onClick = (e) => { @@ -77,7 +67,13 @@ export default { if (e.target.tagName === 'INPUT') { return } - setTimeout(() => this.onClick(node), 0) + this.resetEffect(node) + // Get wave color from target + const waveColor = + getComputedStyle(node).getPropertyValue('border-top-color') || // Firefox Compatible + getComputedStyle(node).getPropertyValue('border-color') || + getComputedStyle(node).getPropertyValue('background-color') + this.clickWaveTimeoutId = window.setTimeout(() => this.onClick(node, waveColor), 0) } node.addEventListener('click', onClick, true) return { @@ -86,7 +82,31 @@ export default { }, } }, + getAttributeName () { + const { insertExtraNode } = this.$props + return insertExtraNode ? 'ant-click-animating' : 'ant-click-animating-without-extra-node' + }, + resetEffect (node) { + if (!node || node === this.extraNode) { + return + } + const { insertExtraNode } = this.$props + const attributeName = this.getAttributeName() + node.removeAttribute(attributeName) + this.removeExtraStyleNode() + if (insertExtraNode && this.extraNode && node.contains(this.extraNode)) { + node.removeChild(this.extraNode) + } + TransitionEvents.removeEndEventListener(node, this.onTransitionEnd) + }, + + onTransitionEnd (e) { + if (!e || e.animationName !== 'fadeEffect') { + return + } + this.resetEffect(e.target) + }, removeExtraStyleNode () { if (this.styleForPesudo && document.body.contains(this.styleForPesudo)) { document.body.removeChild(this.styleForPesudo) diff --git a/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap b/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap index 6baa54090..bba446b62 100644 --- a/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap +++ b/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap @@ -685,7 +685,7 @@ exports[`RangePicker switch to corresponding month panel when click presetted ra
diff --git a/components/locale-provider/index.jsx b/components/locale-provider/index.jsx index 4d39b1a23..db804ac3a 100644 --- a/components/locale-provider/index.jsx +++ b/components/locale-provider/index.jsx @@ -66,7 +66,7 @@ export default { changeConfirmLocale() }, render () { - return this.$slots.default[0] + return this.$slots.default ? this.$slots.default[0] : null }, } diff --git a/components/table/__tests__/__snapshots__/demo.test.js.snap b/components/table/__tests__/__snapshots__/demo.test.js.snap index 7d2df0b09..1db204cbc 100644 --- a/components/table/__tests__/__snapshots__/demo.test.js.snap +++ b/components/table/__tests__/__snapshots__/demo.test.js.snap @@ -67,7 +67,7 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = ` John Brown