Skip to content

Commit

Permalink
Merge pull request #15145 from ckeditor/cf/5595
Browse files Browse the repository at this point in the history
Fix (ui): `TextareaView` will no longer update its height (and log warnings) when the element is detached from DOM.
  • Loading branch information
oleq authored Oct 6, 2023
2 parents f1a686e + f14e41f commit 46c6595
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/ckeditor5-ui/src/textarea/textareaview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @module ui/textarea/textareaview
*/

import { Rect, type Locale, toUnit, getBorderWidths, global, CKEditorError } from '@ckeditor/ckeditor5-utils';
import { Rect, type Locale, toUnit, getBorderWidths, global, CKEditorError, isVisible } from '@ckeditor/ckeditor5-utils';
import InputBase from '../input/inputbase';

import '../../theme/components/input/input.css';
Expand Down Expand Up @@ -107,8 +107,10 @@ export default class TextareaView extends InputBase<HTMLTextAreaElement> {
this.on( 'change:value', () => {
// The content needs to be updated by the browser after the value is changed. It takes a few ms.
global.window.requestAnimationFrame( () => {
this._updateAutoGrowHeight();
this.fire<TextareaViewUpdateEvent>( 'update' );
if ( isVisible( this.element ) ) {
this._updateAutoGrowHeight();
this.fire<TextareaViewUpdateEvent>( 'update' );
}
} );
} );
}
Expand Down
13 changes: 13 additions & 0 deletions packages/ckeditor5-ui/tests/textarea/textareaview.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ describe( 'TextareaView', () => {
expect( view.element.style.height ).to.not.equal( initialHeight );
} );

it( 'should not resize the view on the #value change when the view element is not in DOM', async () => {
wrapper.removeChild( view.element );

const initialHeight = view.element.style.height;

view.value = 'foo\nbar\nbaz\nqux';

expect( view.element.style.height ).to.equal( initialHeight );

await requestAnimationFrame();
expect( view.element.style.height ).to.equal( initialHeight );
} );

describe( 'dynamic resizing', () => {
it( 'should respect #minRows and #maxRows', async () => {
// One row, it's less than default #minRows.
Expand Down

0 comments on commit 46c6595

Please sign in to comment.