Open max-sym opened 3 years ago
Ok, it seems that I made it by removing the bounds="parent"
prop and adding maxWidth="100%"
.
Here's the code:
const Image = ({ element }) => {
const [size, setSize] = useState({ width: 100, height: 100 })
const containerRef = useRef()
const initialValues = useRef({
x: 0,
y: 0,
width: 100,
height: 100,
})
const onResize = (e, direction, ref, delta, position) => {
setSize({
width: ref.offsetWidth,
height: ref.offsetHeight,
})
}
return (
<div ref={containerRef} style={{ position: 'relative', width: '100%' }}>
<div contentEditable={false} style={{ userSelect: 'none' }}>
<Rnd
default={initialValues}
disableDragging
dragGrid={[50, 50]}
enableResizing={{ bottomRight: true }}
lockAspectRatio
maxWidth="100%"
onDragStart={onDragStart}
onResize={onResize}
resizeGrid={[50, 50]}
size={size}
style={{ position: 'relative', transform: 'none', display: 'block' }}
>
<img
alt=""
draggable="false"
src={element.url}
style={{ width: '100%', height: '100%', userSelect: 'none' }}
/>
</Rnd>
</div>
</div>
)
}
When resizing I need the parent to adjust its height as well. Currently, I'm trying the following and it doesn't work:
onResize
fires in the following example, we update thecontainerRef
element'sheight
;react-rnd
doesn't update the boundaries while resizing is happening, so it doesn't work.Is there any workaround for that? Thanks for this amazing library! 🎉🎉🎉