优化 Tag 关闭的逻辑, #84

This commit is contained in:
afc163 2015-07-30 23:52:44 +08:00
parent 5c0fabe855
commit e00a562ca9

View File

@ -2,18 +2,25 @@ import React from 'react';
const prefixCls = 'ant-tag';
class AntTag extends React.Component {
destroy(e) {
let node = React.findDOMNode(this);
React.unmountComponentAtNode(node);
node.parentNode.removeChild(node);
constructor(props) {
super(props);
this.state = {
closed: false
};
}
close(e) {
this.setState({
closed: true
});
this.props.onClose.call(this, e);
}
render() {
let close = this.props.closable ?
<i className="anticon anticon-cross" onClick={this.destroy.bind(this)}></i> : '';
<i className="anticon anticon-cross" onClick={this.close.bind(this)}></i> : '';
let colorClass = this.props.prefixCls + '-' + this.props.color;
return <div className={this.props.prefixCls + ' ' + colorClass}>
return this.state.closed ? null : <div className={this.props.prefixCls + ' ' + colorClass}>
<a className={this.props.prefixCls + '-text'} {...this.props} />
{close}
</div>;