diff --git a/src/shapes/IText/ITextBehavior.ts b/src/shapes/IText/ITextBehavior.ts index e0cb705e0bd..d698c716b55 100644 --- a/src/shapes/IText/ITextBehavior.ts +++ b/src/shapes/IText/ITextBehavior.ts @@ -15,6 +15,7 @@ import type { TOptions } from '../../typedefs'; import { getDocumentFromElement } from '../../util/dom_misc'; import { LEFT, RIGHT, reNewline } from '../../constants'; import type { IText } from './IText'; +import { getFabricDocument } from '../../env'; /** * extend this regex to support non english languages @@ -616,6 +617,13 @@ export abstract class ITextBehavior< p.x += this.canvas._offset.left; p.y += this.canvas._offset.top; + const doc = + (this.canvas && getDocumentFromElement(this.canvas.getElement())) || + getFabricDocument(); + if (p.y > doc.body.clientHeight - charHeight) { + p.y = doc.body.clientHeight - charHeight; + } + return { left: `${p.x}px`, top: `${p.y}px`, diff --git a/src/shapes/IText/ITextKeyBehavior.ts b/src/shapes/IText/ITextKeyBehavior.ts index 082ce8bb2cb..8ea0098dc1e 100644 --- a/src/shapes/IText/ITextKeyBehavior.ts +++ b/src/shapes/IText/ITextKeyBehavior.ts @@ -76,7 +76,7 @@ export abstract class ITextKeyBehavior< const { top, left, fontSize } = this._calcTextareaPosition(); // line-height: 1px; was removed from the style to fix this: // https://bugs.chromium.org/p/chromium/issues/detail?id=870966 - textarea.style.cssText = `position: absolute; top: ${top}; left: ${left}; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; padding-top: ${fontSize};`; + textarea.style.cssText = `position: absolute; top: ${top}; left: ${left}; z-index: -999; opacity: 0; width: 1px; height: 1px; font-size: 1px; border: 0; padding-bottom: 0; padding-top: ${fontSize};`; (this.hiddenTextareaContainer || doc.body).appendChild(textarea);