Issue #1355πŸ’¬ AnsweredOpened August 10, 2018by david-polak0 reactions

Component resize event

Quick answerby artf

Hi David, I think currently is the best you can do, but I'm open for suggestions to make it less hacky

Read full answer below ↓

Question

I have a canvas component and I need to be able to register resize events for it.

After diving trough the code and looking for relevant model events all I could come up with, that would actually trigger on the resize is this:

handleUpdate (e) {
  if (this.prevWidth !== this.el.clientWidth || 
      this.prevHeight !== this.el.clientHeight) {
  this.prevWidth = this.el.clientWidth
  this.prevHeight = this.el.clientHeight
  this.handleResize()
  }
},

render () {
  defaultType.view.prototype.render.apply(this, arguments)

  this.prevHeight = null
  this.prevWidth = null
  this.handleUpdate = this.handleUpdate.bind(this)
  editor.on('component:styleUpdate', this.handleUpdate)

  return this
}

Which works, but is kinda hacky.

Is there a better suited event?

Answers (2)

artfβ€’ August 13, 2018

Hi David, I think currently is the best you can do, but I'm open for suggestions to make it less hacky

lock[bot]β€’ September 17, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

Premium plugins ship with support, regular updates, and production-ready features β€” save days of integration work.

Browse premium plugins β†’

Related tutorials

In-depth guides on the same topic.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.