Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Improve interactive tooltip hover behaviour
Browse files Browse the repository at this point in the history
This gives the interactive tooltip a more natural hover behaviour by removing
the full screen div behind it. This allows the target button to keep its hover
state, for example.

This also removes the click to close behavior, which was too easy to trigger
accidentally.

Fixes element-hq/element-web#10179
Fixes element-hq/element-web#10222
Fixes element-hq/element-web#10225
  • Loading branch information
jryans committed Jul 1, 2019
1 parent 38bfe8b commit 3acdf27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
10 changes: 0 additions & 10 deletions res/css/views/elements/_InteractiveTooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,6 @@ limitations under the License.
z-index: 5000;
}

.mx_InteractiveTooltip_background {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 1.0;
z-index: 5000;
}

.mx_InteractiveTooltip {
border-radius: 3px;
background-color: $interactive-tooltip-bg-color;
Expand Down
16 changes: 7 additions & 9 deletions src/components/views/elements/InteractiveTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ export default class InteractiveTooltip extends React.Component {
this.renderTooltip();
}

componentWillUnmount() {
document.removeEventListener("mousemove", this.onMouseMove);
}

collectContentRect = (element) => {
// We don't need to clean up when unmounting, so ignore
if (!element) return;
Expand All @@ -87,11 +91,7 @@ export default class InteractiveTooltip extends React.Component {
this.target = element;
}

onBackgroundClick = (ev) => {
this.hideTooltip();
}

onBackgroundMouseMove = (ev) => {
onMouseMove = (ev) => {
const { clientX: x, clientY: y } = ev;
const { contentRect } = this.state;
const targetRect = this.target.getBoundingClientRect();
Expand All @@ -113,6 +113,7 @@ export default class InteractiveTooltip extends React.Component {
if (this.props.onVisibilityChange) {
this.props.onVisibilityChange(true);
}
document.addEventListener("mousemove", this.onMouseMove);
}

hideTooltip() {
Expand All @@ -122,6 +123,7 @@ export default class InteractiveTooltip extends React.Component {
if (this.props.onVisibilityChange) {
this.props.onVisibilityChange(false);
}
document.removeEventListener("mousemove", this.onMouseMove);
}

renderTooltip() {
Expand Down Expand Up @@ -168,10 +170,6 @@ export default class InteractiveTooltip extends React.Component {
}

const tooltip = <div className="mx_InteractiveTooltip_wrapper" style={{...position}}>
<div className="mx_ContextualMenu_background"
onMouseMove={this.onBackgroundMouseMove}
onClick={this.onBackgroundClick}
/>
<div className={menuClasses}
style={menuStyle}
ref={this.collectContentRect}
Expand Down

0 comments on commit 3acdf27

Please sign in to comment.