diff --git a/packages/hotspot/src/hotspot/circle.jsx b/packages/hotspot/src/hotspot/circle.jsx index 82e0ca2d9b..aa2ae64d01 100644 --- a/packages/hotspot/src/hotspot/circle.jsx +++ b/packages/hotspot/src/hotspot/circle.jsx @@ -10,8 +10,28 @@ class CircleComponent extends React.Component { this.state = { hovered: false, }; + this.groupRef = React.createRef(); } + componentDidMount() { + if (this.props.focused) { + this.moveGroupToTop(); + } + } + + componentDidUpdate(prevProps) { + // `focused` (keyboard focus) can turn on the hovered style without going through handleMouseEnter + if (!prevProps.focused && this.props.focused) { + this.moveGroupToTop(); + } + } + + moveGroupToTop = () => { + if (this.groupRef.current) { + this.groupRef.current.moveToTop(); + } + }; + handleClick = (e) => { const { onClick, id, selected, disabled } = this.props; @@ -28,6 +48,7 @@ class CircleComponent extends React.Component { document.body.style.cursor = 'pointer'; } this.setState({ hovered: true }); + this.moveGroupToTop(); }; handleMouseLeave = () => { @@ -92,7 +113,13 @@ class CircleComponent extends React.Component { const useHoveredStyle = (hovered || focused) && hoverOutlineColor; return ( - + { + if (this.groupRef.current) { + this.groupRef.current.moveToTop(); + } + }; + getPolygonCenter = (points) => { const x = points.map(({ x }) => x); const y = points.map(({ y }) => y); @@ -47,6 +67,7 @@ class PolygonComponent extends React.Component { document.body.style.cursor = 'pointer'; } this.setState({ hovered: true }); + this.moveGroupToTop(); }; handleMouseLeave = () => { @@ -137,7 +158,13 @@ class PolygonComponent extends React.Component { const rectHeight = maxY - minY; return ( - + { + if (this.groupRef.current) { + this.groupRef.current.moveToTop(); + } + }; + handleClick = (e) => { const { onClick, id, selected, disabled } = this.props; @@ -28,6 +48,7 @@ class RectComponent extends React.Component { document.body.style.cursor = 'pointer'; } this.setState({ hovered: true }); + this.moveGroupToTop(); }; handleMouseLeave = () => { @@ -107,7 +128,13 @@ class RectComponent extends React.Component { const useHoveredStyle = (hovered || focused) && hoverOutlineColor; return ( - +