FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

TINY-11907: Update the disabled option check by tiny-ben-tran · Pull Request #419 · tinymce/tinymce-angular · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class EditorComponent extends Events implements AfterViewInit, ControlVal
public set disabled(val) {
this._disabled = val;
if (this._editor) {
if (DisabledUtils.isDisabledOptionSupported()) {
if (DisabledUtils.isDisabledOptionSupported(this._editor)) {
this._editor.options.set('disabled', val ?? false);
} else {
setMode(this._editor, val ? 'readonly' : 'design');
Expand Down Expand Up @@ -190,10 +190,8 @@ export class EditorComponent extends Events implements AfterViewInit, ControlVal
selector: undefined,
target: this._element,
inline: this.inline,
...( DisabledUtils.isDisabledOptionSupported()
? { disabled: this.disabled, readonly: this.readonly }
: { readonly: this.disabled || this.readonly }
),
disabled: this.disabled,
readonly: this.readonly,
license_key: this.licenseKey,
plugins: mergePlugins((this.init && this.init.plugins) as string, this.plugins),
toolbar: this.toolbar || (this.init && this.init.toolbar),
Expand All @@ -209,6 +207,14 @@ export class EditorComponent extends Events implements AfterViewInit, ControlVal
if (this.init && typeof this.init.setup === 'function') {
this.init.setup(editor);
}

if (this.disabled === true) {
if (DisabledUtils.isDisabledOptionSupported(editor)) {
this._editor.options.set('disabled', this.disabled);
} else {
this._editor.mode.set('readonly');
}
}
}
};

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { getTinymce } from '../TinyMCE';
import { TinyMCE } from 'tinymce';
import { Editor } from 'tinymce';

const isDisabledOptionSupported = () => {
const tiny: TinyMCE = getTinymce();
// Disabled option is supported since Tiny 7.6.0
return Number(tiny.majorVersion) > 7 || (Number(tiny.majorVersion) === 7 && Number(tiny.minorVersion) >= 6);
};
const isDisabledOptionSupported = (editor: Editor) => editor.options && editor.options.isRegistered('disabled');

export {
isDisabledOptionSupported
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ describe('DisabledPropertyTest', () => {
const assertDisabledOption = (editor: Editor, expected: boolean) =>
Assertions.assertEq(`TinyMCE should have disabled option set to ${expected}`, expected, editor.options.get('disabled'));

eachVersionContext([ '7.5.0' ], () => {
eachVersionContext([ '5', '6', '7.5.0', ], () => {
const createFixture = editorHook(EditorComponent);

it(`Component 'disabled' property is mapped to editor 'readonly' property`, async () => {
it(`Component 'disabled' property is mapped to editor 'readonly' mode`, async () => {
const { editor } = await createFixture({ disabled: true });
assertReadonlyMode(editor);
});

it(`Toggling component's 'disabled' property is mapped to editor 'readonly' property`, async () => {
it(`Toggling component's 'disabled' property is mapped to editor 'readonly' mode`, async () => {
const fixture = await createFixture();
const { editor } = fixture;

Expand All @@ -46,6 +46,26 @@ describe('DisabledPropertyTest', () => {
assertDesignMode(editor);
});

it(`Setting the 'readonly' property causing readonly mode`, async () => {
const { editor } = await createFixture({ readonly: true });
assertReadonlyMode(editor);
});

it(`Toggling component's 'readonly' property is mapped to editor 'readonly' mode`, async () => {
const fixture = await createFixture();
const { editor } = fixture;

assertDesignMode(editor);

fixture.componentRef.setInput('readonly', true);
fixture.detectChanges();
assertReadonlyMode(editor);

fixture.componentRef.setInput('readonly', false);
fixture.detectChanges();
assertDesignMode(editor);
});

it(`[disabled]=true [readonly]=false triggers readonly mode`, async () => {
const { editor } = await createFixture({ disabled: true, readonly: false });
assertReadonlyMode(editor);
Expand All @@ -67,7 +87,7 @@ describe('DisabledPropertyTest', () => {
assertDesignMode(editor);
});

it(`Toggling component's 'disabled' property is mapped to editor 'disabled' property`, async () => {
it(`Toggling component's 'disabled' property is mapped to editor 'disabled' option`, async () => {
const fixture = await createFixture();
const { editor } = fixture;

Expand All @@ -86,30 +106,6 @@ describe('DisabledPropertyTest', () => {
});
});

eachVersionContext([ '4', '5', '6', '7' ], () => {
const createFixture = editorHook(EditorComponent);

it(`Setting the 'readonly' property causing readonly mode`, async () => {
const { editor } = await createFixture({ readonly: true });
assertReadonlyMode(editor);
});

it(`Toggling component's 'readonly' property is mapped to editor 'readonly' mode`, async () => {
const fixture = await createFixture();
const { editor } = fixture;

assertDesignMode(editor);

fixture.componentRef.setInput('readonly', true);
fixture.detectChanges();
assertReadonlyMode(editor);

fixture.componentRef.setInput('readonly', false);
fixture.detectChanges();
assertDesignMode(editor);
});
});

context('With version 7', () => {
@Component({
imports: [ FormsModule, EditorComponent ],
Expand Down

Back | FazBrowse Home | New Git URL