Skip to content

Commit 600e511

Browse files
INT-3328: fix disabled property with ngmodel (#416)
* INT-3328: fix disabled property with ngmodel * INT-3328: fix tests * INT-3328: add changelog entry
1 parent 997c091 commit 600e511

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Fixed
1313
- Updated dependencies. #INT-3324
14+
- Fixed a bug where `[disabled]` property was ignored while using `[ngModel]`. #INT-3328
1415

1516
### Changed
1617
- Moved tinymce dependency to be a optional peer dependency. #INT-3324

tinymce-angular-component/src/main/ts/editor/editor.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class EditorComponent extends Events implements AfterViewInit, ControlVal
6868
@Input()
6969
public set readonly(val) {
7070
this._readonly = val;
71-
if (this._editor && this._editor.initialized) {
71+
if (this._editor) {
7272
setMode(this._editor, val ? 'readonly' : 'design');
7373
}
7474
}
@@ -80,7 +80,7 @@ export class EditorComponent extends Events implements AfterViewInit, ControlVal
8080
@Input()
8181
public set disabled(val) {
8282
this._disabled = val;
83-
if (this._editor && this._editor.initialized) {
83+
if (this._editor) {
8484
if (DisabledUtils.isDisabledOptionSupported()) {
8585
this._editor.options.set('disabled', val ?? false);
8686
} else {

tinymce-angular-component/src/test/ts/browser/DisabledPropertyTest.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ import { Assertions } from '@ephox/agar';
22
import '../alien/InitTestEnvironment';
33

44
import { EditorComponent } from '../../../main/ts/public_api';
5-
import { describe, it } from '@ephox/bedrock-client';
5+
import { after, before, context, describe, it } from '@ephox/bedrock-client';
66
import { eachVersionContext, editorHook } from '../alien/TestHooks';
77
import { Editor } from 'tinymce';
8+
import { ComponentFixture, TestBed } from '@angular/core/testing';
9+
import { Component, ViewChild } from '@angular/core';
10+
import { FormsModule } from '@angular/forms';
11+
import { VersionLoader } from '@tinymce/miniature';
12+
import { deleteTinymce } from '../alien/TestHelpers';
813

914
describe('DisabledPropertyTest', () => {
1015
const getMode = (editor: Editor) => {
@@ -104,4 +109,55 @@ describe('DisabledPropertyTest', () => {
104109
assertDesignMode(editor);
105110
});
106111
});
112+
113+
context('With version 7', () => {
114+
@Component({
115+
imports: [ FormsModule, EditorComponent ],
116+
template: `<editor [(ngModel)]="text" [disabled]="true" />`,
117+
standalone: true,
118+
selector: 'test-host-component'
119+
})
120+
class TestHostComponent {
121+
public text = '<h1>Hello World</h1>';
122+
@ViewChild(EditorComponent) public editorRef!: EditorComponent;
123+
}
124+
125+
const waitForEditorInitialized = (editor: Editor) => new Promise<void>((resolve) => {
126+
if (editor.initialized) {
127+
resolve();
128+
}
129+
editor.once('init', () => resolve());
130+
});
131+
132+
let fixture: ComponentFixture<TestHostComponent>;
133+
let testHost: TestHostComponent;
134+
let tinyEditor: Editor;
135+
136+
before(async () => {
137+
await VersionLoader.pLoadVersion('7');
138+
139+
await TestBed.configureTestingModule({
140+
imports: [ TestHostComponent ]
141+
}).compileComponents();
142+
143+
fixture = TestBed.createComponent(TestHostComponent);
144+
testHost = fixture.componentInstance;
145+
fixture.detectChanges();
146+
tinyEditor = testHost.editorRef.editor!;
147+
});
148+
149+
after(() => {
150+
deleteTinymce();
151+
});
152+
153+
it('INT-3328: disabled property should work with [ngModel] when TinyMCE has been loaded before editor component has been created', async () => {
154+
assertDisabledOption(tinyEditor!, true);
155+
/*
156+
I have to wait until the editor is fully initialized before using deleteTinymce() in after block.
157+
There's for example theme.js script that starts to load after editor instance has been created.
158+
If I remove tinymce from window too soon the theme.js will fail alongside with this test case.
159+
*/
160+
await waitForEditorInitialized(tinyEditor!);
161+
});
162+
});
107163
});

0 commit comments

Comments
 (0)