Improve tooltip show/hide
This commit is contained in:
parent
d6beb03065
commit
559971c6da
@ -18,22 +18,31 @@ class Tooltip extends Component<TooltipProps, TooltipState> {
|
|||||||
this.state = {
|
this.state = {
|
||||||
active: false
|
active: false
|
||||||
};
|
};
|
||||||
this.handleClick = this.handleClick.bind(this);
|
|
||||||
|
this.toggleVisible = this.toggleVisible.bind(this);
|
||||||
|
this.handleBlur = this.handleBlur.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick(event) {
|
|
||||||
event.preventDefault();
|
toggleVisible() {
|
||||||
|
this.setState(state => ({
|
||||||
|
active: !state.active
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBlur(event) {
|
||||||
|
if(!event.currentTarget.contains(event.relatedTarget)) {
|
||||||
this.setState({
|
this.setState({
|
||||||
active: !this.state.active
|
active: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="tooltip-wrap">
|
<div className="tooltip-wrap" tabIndex={0} onBlur={this.handleBlur}>
|
||||||
<button className={(this.state.active? 'active ': '') + 'tooltip-hint icon-button'}
|
<button type="button" className={(this.state.active? 'active ': '') + 'tooltip-hint icon-button'}
|
||||||
title={this.props.text}
|
onClick={this.toggleVisible}>
|
||||||
onClick={this.handleClick}>
|
|
||||||
Hint
|
Hint
|
||||||
<InfoIcon />
|
<InfoIcon />
|
||||||
</button>
|
</button>
|
||||||
|
Loading…
Reference in New Issue
Block a user