@@ -5,14 +5,9 @@ import type { Matrix } from "transformation-matrix"
55interface Props {
66 transform ?: Matrix
77 children : React . ReactNode
8- focusOnHover ?: boolean
98}
109
11- export const DimensionOverlay : React . FC < Props > = ( {
12- children,
13- transform,
14- focusOnHover = false ,
15- } ) => {
10+ export const DimensionOverlay : React . FC < Props > = ( { children, transform } ) => {
1611 if ( ! transform ) transform = identity ( )
1712 const [ dimensionToolVisible , setDimensionToolVisible ] = useState ( false )
1813 const [ dimensionToolStretching , setDimensionToolStretching ] = useState ( false )
@@ -25,7 +20,7 @@ export const DimensionOverlay: React.FC<Props> = ({
2520 const container = containerRef . current !
2621 const containerBounds = container ?. getBoundingClientRect ( )
2722
28- useEffect ( ( ) => {
23+ const bindKeys = ( ) => {
2924 const container = containerRef . current
3025
3126 const down = ( e : KeyboardEvent ) => {
@@ -67,7 +62,9 @@ export const DimensionOverlay: React.FC<Props> = ({
6762 container . removeEventListener ( "mouseleave" , removeKeyListener )
6863 }
6964 }
70- } , [ containerRef ] )
65+ }
66+
67+ useEffect ( bindKeys , [ containerBounds ?. width , containerBounds ?. height ] )
7168
7269 const screenDStart = applyToPoint ( transform , dStart )
7370 const screenDEnd = applyToPoint ( transform , dEnd )
@@ -90,16 +87,6 @@ export const DimensionOverlay: React.FC<Props> = ({
9087 ref = { containerRef }
9188 tabIndex = { 0 }
9289 style = { { position : "relative" } }
93- onMouseEnter = { ( ) => {
94- if ( focusOnHover && containerRef . current ) {
95- containerRef . current . focus ( )
96- }
97- } }
98- onMouseLeave = { ( ) => {
99- if ( containerRef . current ) {
100- containerRef . current . blur ( )
101- }
102- } }
10390 onMouseMove = { ( e : React . MouseEvent < HTMLDivElement > ) => {
10491 const rect = e . currentTarget . getBoundingClientRect ( )
10592 const x = e . clientX - rect . left
@@ -119,6 +106,11 @@ export const DimensionOverlay: React.FC<Props> = ({
119106 setDimensionToolVisible ( false )
120107 }
121108 } }
109+ onMouseEnter = { ( ) => {
110+ if ( containerRef . current ) {
111+ bindKeys ( )
112+ }
113+ } }
122114 >
123115 { children }
124116 { dimensionToolVisible && (
0 commit comments