mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
remove magic code, use getBoundingClientRect replace offsetWidth
This commit is contained in:
parent
970aa4f846
commit
75fca79313
@ -14,10 +14,6 @@ class AntTag extends React.Component {
|
|||||||
|
|
||||||
close(e) {
|
close(e) {
|
||||||
let dom = React.findDOMNode(this);
|
let dom = React.findDOMNode(this);
|
||||||
dom.style.width = dom.offsetWidth + 'px';
|
|
||||||
// Magic code
|
|
||||||
// 重复是去除浏览器渲染bug;
|
|
||||||
dom.style.width = dom.offsetWidth + 'px';
|
|
||||||
this.setState({
|
this.setState({
|
||||||
closing: true
|
closing: true
|
||||||
});
|
});
|
||||||
@ -30,6 +26,11 @@ class AntTag extends React.Component {
|
|||||||
this.props.onClose.call(this, e);
|
this.props.onClose.call(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
let dom = React.findDOMNode(this);
|
||||||
|
dom.style.width = (dom.getBoundingClientRect().width || dom.offsetWidth) + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let close = this.props.closable ?
|
let close = this.props.closable ?
|
||||||
<i className="anticon anticon-cross" onClick={this.close.bind(this)}></i> : '';
|
<i className="anticon anticon-cross" onClick={this.close.bind(this)}></i> : '';
|
||||||
@ -38,17 +39,18 @@ class AntTag extends React.Component {
|
|||||||
let className = this.props.prefixCls + ' ' + colorClass;
|
let className = this.props.prefixCls + ' ' + colorClass;
|
||||||
className = this.state.closing ? className + ' ' + this.props.prefixCls + '-close' : className;
|
className = this.state.closing ? className + ' ' + this.props.prefixCls + '-close' : className;
|
||||||
|
|
||||||
return (this.state.closed && !this.state.closing) ? null : <div className={className}>
|
return (this.state.closed && !this.state.closing) ? null
|
||||||
<a className={this.props.prefixCls + '-text'} {...this.props} />
|
: <div className={className}>
|
||||||
{close}
|
<a className={this.props.prefixCls + '-text'} {...this.props} />
|
||||||
</div>;
|
{close}
|
||||||
|
</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AntTag.defaultProps = {
|
AntTag.defaultProps = {
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
closable: false,
|
closable: false,
|
||||||
onClose: function () {}
|
onClose: function() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AntTag;
|
export default AntTag;
|
||||||
|
Loading…
Reference in New Issue
Block a user