vue-draggable-resizable icon indicating copy to clipboard operation
vue-draggable-resizable copied to clipboard

Handle parent component width and height change

Open gsaada opened this issue 5 years ago • 6 comments

  <div v-bind:style="windowStyle">
    <vue-draggable-resizable
      v-if="true"
      :parent="true"
      :w="1120"
      :h="500"
    >
      <dashboard/>
    </vue-draggable-resizable>
 </div>

After changing windowStyle the drag is still blocked by the prev windowStyle size.

How can I sync the children with the new size? Thank you

gsaada avatar May 23 '19 08:05 gsaada

Parent costraints are calculated only during component mount. If you want to update them you can trigger a resize event.

See https://github.com/mauricius/vue-draggable-resizable/issues/133#issuecomment-446781986

mauricius avatar May 24 '19 15:05 mauricius

@mauricius Thank you for your answer. This will work only on the development branch? What can I do if I don't use dev branch?

gsaada avatar May 26 '19 14:05 gsaada

<div v-if="parentShow"  v-bind:style="windowStyle">
    <vue-draggable-resizable
      v-if="true"
      :parent="true"
      :w="1120"
      :h="500"
    >
      <dashboard/>
    </vue-draggable-resizable>
 </div>
watch: {
    windowStyle() {
       this.parentShow = false;
       this.parentShow = true;
    }
}

@gsaada it works for me. actually it makes component mount again, the parent element avoid re-render so everything looks normal

StreakingMan avatar Mar 12 '20 18:03 StreakingMan

@MaxYYYYY for me,it doesn't work,because re-mount the components need some time,so I change the code like this:

this.parentShow = false;
      let _this = this;
      setTimeout(() => {
        _this.parentShow = true;
      }, 100);

misland avatar Apr 27 '20 09:04 misland

Parent costraints are calculated only during component mount. If you want to update them you can trigger a resize event.

See #133 (comment)

Dear mauricius, I have met this parent size change problem recently ,. do you have other elegant way except 'window.dispatchEvent(new Event('resize'))' ?

Adhders avatar Mar 03 '21 11:03 Adhders

dispatching resize event is a hack and can cause problems (infinite loops) if you are already reacting in a resize handler

seekingtheoptimal avatar Jun 14 '23 13:06 seekingtheoptimal