diff --git a/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap b/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap
index 3f5723e21..c8fbc379c 100644
--- a/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap
+++ b/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap
@@ -686,7 +686,7 @@ exports[`RangePicker switch to corresponding month panel when click presetted ra
diff --git a/components/table/__tests__/__snapshots__/demo.test.js.snap b/components/table/__tests__/__snapshots__/demo.test.js.snap
index b965f9d88..c938503c7 100644
--- a/components/table/__tests__/__snapshots__/demo.test.js.snap
+++ b/components/table/__tests__/__snapshots__/demo.test.js.snap
@@ -86,7 +86,7 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = `
John Brown
32 |
New York No. 1 Lake Park |
- nice developer |
+ nice developer |
Invite 一 John Brown Delete
More actions |
@@ -95,7 +95,7 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = `
Jim Green
42 |
London No. 1 Lake Park |
- loser |
+ loser |
Invite 一 Jim Green Delete
More actions |
@@ -104,7 +104,7 @@ exports[`renders ./components/table/demo/basic.md correctly 1`] = `
Joe Black
32 |
Sidney No. 1 Lake Park |
- cool teacher |
+ cool teacher |
Invite 一 Joe Black Delete
More actions |
@@ -2903,7 +2903,7 @@ exports[`renders ./components/table/demo/template.md correctly 1`] = `
Brown |
32 |
New York No. 1 Lake Park |
- nice developer |
+ nice developer |
Action 一 John Delete |
@@ -2912,7 +2912,7 @@ exports[`renders ./components/table/demo/template.md correctly 1`] = `
Green |
42 |
London No. 1 Lake Park |
- loser |
+ loser |
Action 一 Jim Delete |
@@ -2921,7 +2921,7 @@ exports[`renders ./components/table/demo/template.md correctly 1`] = `
Black |
32 |
Sidney No. 1 Lake Park |
- cool teacher |
+ cool teacher |
Action 一 Joe Delete |
diff --git a/components/tag/Tag.jsx b/components/tag/Tag.jsx
index 6bfa106a7..7781950fc 100644
--- a/components/tag/Tag.jsx
+++ b/components/tag/Tag.jsx
@@ -12,7 +12,7 @@ export default {
props: {
prefixCls: PropTypes.string.def('ant-tag'),
color: PropTypes.string,
- closable: PropTypes.bool,
+ closable: PropTypes.bool.def(false),
visible: PropTypes.bool,
afterClose: PropTypes.func,
},
@@ -21,22 +21,13 @@ export default {
event: 'close.visible',
},
data () {
- const props = getOptionProps(this)
- let state = {}
- if ('visible' in props) {
- state = {
- _visible: props.visible,
- _closed: !props.visible,
- }
+ let _visible = true
+ if (hasProp(this, 'visible')) {
+ _visible = this.visible
}
- state = {
- _closing: false,
- _closed: false,
- _visible: true,
- ...state,
+ return {
+ _visible,
}
- this.pre_visible = state._visible
- return state
},
watch: {
visible (val) {
@@ -45,61 +36,26 @@ export default {
})
},
},
- updated () {
- this.$nextTick(() => {
- const preVisible = this.pre_visible
- this.pre_visible = this.$data._visible
- if (preVisible && !this.$data._visible) {
- this.close()
- } else if (!preVisible && this.$data._visible) {
- this.show()
- }
- })
- },
methods: {
- handleIconClick (e) {
+ setVisible (visible, e) {
this.$emit('close', e)
this.$emit('close.visible', false)
- if (e.defaultPrevented || hasProp(this, 'visible')) {
+ if (e.defaultPrevented) {
return
}
- this.setState({ _visible: false })
- this.$forceUpdate()
- },
- close () {
- if (this.$data._closing || this.$data._closed) {
- return
+ if (!hasProp(this, 'visible')) {
+ this.setState({ _visible: visible })
}
- const dom = this.$el
- dom.style.width = `${dom.getBoundingClientRect().width}px`
- // It's Magic Code, don't know why
- dom.style.width = `${dom.getBoundingClientRect().width}px`
- this.setState({
- _closing: true,
- })
},
- show () {
- this.setState({
- _closed: false,
- })
+ handleIconClick (e) {
+ this.setVisible(false, e)
},
- animationEnd (_, existed) {
- if (!existed && !this.$data._closed) {
- this.setState({
- _closed: true,
- _closing: false,
- })
-
- const afterClose = this.afterClose
- if (afterClose) {
- afterClose()
- }
- } else {
- this.setState({
- _closed: false,
- })
+ animationEnd () {
+ const afterClose = this.afterClose
+ if (afterClose) {
+ afterClose()
}
},
@@ -110,46 +66,51 @@ export default {
.test(color)
)
},
+ getTagStyle () {
+ const { color } = this.$props
+ const isPresetColor = this.isPresetColor(color)
+ return {
+ backgroundColor: color && !isPresetColor ? color : undefined,
+ }
+ },
+
+ getTagClassName () {
+ const { prefixCls, color } = this.$props
+ const isPresetColor = this.isPresetColor(color)
+ return {
+ [prefixCls]: true,
+ [`${prefixCls}-${color}`]: isPresetColor,
+ [`${prefixCls}-has-color`]: color && !isPresetColor,
+ }
+ },
+
+ renderCloseIcon () {
+ const { closable } = this.$props
+ return closable ? : null
+ },
},
render () {
- const { prefixCls, closable, color } = this.$props
- const closeIcon = closable ? : ''
- const isPresetColor = this.isPresetColor(color)
- const cls = {
- [`${prefixCls}`]: true,
- [`${prefixCls}-${color}`]: isPresetColor,
- [`${prefixCls}-has-color`]: (color && !isPresetColor),
- [`${prefixCls}-close`]: this.$data._closing,
- }
-
- const tagStyle = {
- backgroundColor: (color && !isPresetColor) ? color : null,
- }
- const tag =
+ const { prefixCls } = this.$props
+ const { _visible: visible } = this.$data
+ const tag = (
{this.$slots.default}
- {closeIcon}
+ {this.renderCloseIcon()}
+ )
const transitionProps = getTransitionProps(`${prefixCls}-zoom`, {
- afterLeave: () => this.animationEnd(undefined, false),
- afterEnter: () => this.animationEnd(undefined, true),
+ appear: false,
+ afterLeave: this.animationEnd,
})
return (
- {this.$data._closed ?
- :
- {tag}
-
- }
+ {tag}
)
},
diff --git a/components/tag/__tests__/__snapshots__/demo.test.js.snap b/components/tag/__tests__/__snapshots__/demo.test.js.snap
index 0626bdb2b..0a66151d0 100644
--- a/components/tag/__tests__/__snapshots__/demo.test.js.snap
+++ b/components/tag/__tests__/__snapshots__/demo.test.js.snap
@@ -2,12 +2,12 @@
exports[`renders ./components/tag/demo/basic.md correctly 1`] = `
-
Tag 1
-
-
Tag 2