Position editor on resize

This commit is contained in:
Rainer Simon 2020-05-12 20:17:37 +02:00
parent 2727b38c94
commit bc005087e0
1 changed files with 10 additions and 0 deletions

View File

@ -42,6 +42,16 @@ const Editor = props => {
setPosition(props.wrapperEl, element.current, props.selectedElement); setPosition(props.wrapperEl, element.current, props.selectedElement);
}, [ props.selectedElement.getBoundingClientRect() ]); }, [ props.selectedElement.getBoundingClientRect() ]);
// Attach resize listener on mount
useEffect(() => {
const resizeObserver = new ResizeObserver(() => {
setPosition(props.wrapperEl, element.current, props.selectedElement);
});
resizeObserver.observe(props.wrapperEl);
return () => resizeObserver.disconnect();
}, []);
const onAppendBody = body => setCurrentAnnotation( const onAppendBody = body => setCurrentAnnotation(
currentAnnotation.clone({ currentAnnotation.clone({
body: [ ...currentAnnotation.bodies, body ] body: [ ...currentAnnotation.bodies, body ]