Skip to content

Commit

Permalink
feat(fabric.iText): Add optional hiddenTextareaContainer to contain h…
Browse files Browse the repository at this point in the history
…iddenTextarea (#7314)
  • Loading branch information
rockerBOO authored Aug 27, 2021
1 parent c672744 commit 9425064
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/mixins/itext_key_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
this.hiddenTextarea.style.cssText = 'position: absolute; top: ' + style.top +
'; left: ' + style.left + '; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px;' +
' paddingーtop: ' + style.fontSize + ';';
fabric.document.body.appendChild(this.hiddenTextarea);

if (this.hiddenTextareaContainer) {
this.hiddenTextareaContainer.appendChild(this.hiddenTextarea);
}
else {
fabric.document.body.appendChild(this.hiddenTextarea);
}

fabric.util.addListener(this.hiddenTextarea, 'keydown', this.onKeyDown.bind(this));
fabric.util.addListener(this.hiddenTextarea, 'keyup', this.onKeyUp.bind(this));
Expand Down
10 changes: 10 additions & 0 deletions src/shapes/itext.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@
*/
caching: true,

/**
* DOM container to append the hiddenTextarea.
* An alternative to attaching to the document.body.
* Useful to reduce laggish redraw of the full document.body tree and
* also with modals event capturing that won't let the textarea take focus.
* @type HTMLElement
* @default
*/
hiddenTextareaContainer: null,

/**
* @private
*/
Expand Down

0 comments on commit 9425064

Please sign in to comment.