Skip to content

Commit b77685f

Browse files
author
Benjamin Kniffler
committed
Improve tooltip behaviour
1 parent eca4072 commit b77685f

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

draft-js-toolbar-plugin/src/components/tooltip-portal.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ export default function (WrappedComponent) {
5656
const { group } = this.props;
5757
if (portalNodes[group]) {
5858

59+
// Other tooltip was active, switching
5960
if (portalNodes[group].tips.length > 1) {
6061
this.removeThisGroupTip();
61-
// Other tooltip was active, switching
6262
const item = portalNodes[group].tips[portalNodes[group].tips.length - 1];
6363
return item.renderPortal(item.props);
6464
}
@@ -68,11 +68,10 @@ export default function (WrappedComponent) {
6868

6969
// Timeout to switch to next tooltip if necessary
7070
portalNodes[group].timeout = setTimeout(() => {
71-
if (portalNodes[group].tips.length === 1) {
71+
if (portalNodes[group].tips.length === 0) {
7272
ReactDOM.unmountComponentAtNode(portalNodes[group].el);
7373
delete portalNodes[group];
7474
} else {
75-
this.removeThisGroupTip();
7675
const item = portalNodes[group].tips[portalNodes[group].tips.length - 1];
7776
item.renderPortal(item.props);
7877
}
@@ -100,10 +99,14 @@ export default function (WrappedComponent) {
10099
portalNodes[group].timeout = null;
101100
}
102101

103-
portalNodes[group].tips = clearAll ? [this] : [
104-
...this.removeThisGroupTip(),
105-
this,
106-
];
102+
if (props.active) {
103+
portalNodes[group].tips = clearAll ? [this] : [
104+
...this.removeThisGroupTip(),
105+
this,
106+
];
107+
} else {
108+
this.removeThisGroupTip();
109+
}
107110

108111
ReactDOM.render(<WrappedComponent {...other} />, portalNodes[group].el);
109112
}

0 commit comments

Comments
 (0)