Improve tooltip show/hide

This commit is contained in:
Maciej Ziarkowski 2020-03-23 23:31:33 +00:00
parent d6beb03065
commit 559971c6da

View File

@ -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>