Skip to content

Commit 9e5be9b

Browse files
committed
TINY-11911: Add logic to sync with the disabled option
1 parent d2ed417 commit 9e5be9b

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/demo/html/disabled.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
<body>
1111
<script>
1212
function toggleDisabled() {
13-
var editor = document.getElementById('mody');
14-
13+
var editor = document.getElementById('disabled_state');
1514
if (!editor.hasAttribute('disabled')) {
1615
editor.setAttribute('disabled', '');
1716
} else {
@@ -20,9 +19,7 @@
2019
}
2120

2221
function toggleReadonly() {
23-
var editor = document.getElementById('mody');
24-
25-
editor.removeAttribute('disabled');
22+
var editor = document.getElementById('readonly_mode');
2623
if (!editor.hasAttribute('readonly')) {
2724
editor.setAttribute('readonly', '');
2825
} else {
@@ -32,9 +29,12 @@
3229
</script>
3330
<h2>TinyMCE WebComponent Demo: Disabled and Readonly</h2>
3431
<div id="ephox-ui">
35-
<button onclick="toggleDisabled()">Toggle disabled</button>
32+
<h2>Readonly mode</h2>
3633
<button onclick="toggleReadonly()">Toggle readonly</button>
37-
<tinymce-editor id="mody"></tinymce-editor>
34+
<tinymce-editor id="readonly_mode" readonly></tinymce-editor>
35+
<h2>Disabled state</h2>
36+
<button onclick="toggleDisabled()" plugins="help">Toggle disabled</button>
37+
<tinymce-editor id="disabled_state" disabled></tinymce-editor>
3838
</div>
3939
<script src="../../../node_modules/tinymce/tinymce.js"></script>
4040
<script src="../../../dist/tinymce-webcomponent.js"></script>

src/main/ts/component/Editor.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ const configAttributes: Record<string, (v: string) => unknown> = {
8080
const configRenames: Record<string, string> = {};
8181

8282
// Function that checks if the disabled option is supported with the version used
83-
const isDisabledOptionSupported = (tinymce: TinyMCE): boolean => {
84-
return (!TinyVer.isLessThan(tinymce, '7.6.0'))
85-
};
83+
const isDisabledOptionSupported = (tinymce: TinyMCE): boolean => !TinyVer.isLessThan(tinymce, '7.6.0');
8684

8785
class TinyMceEditor extends HTMLElement {
8886
private _status: Status;
@@ -250,24 +248,26 @@ class TinyMceEditor extends HTMLElement {
250248
const baseConfig = this._getConfig();
251249
const conf: EditorOptions = {
252250
...baseConfig,
251+
...{
252+
disabled: this.hasAttribute('disabled'),
253+
readonly: this.hasAttribute('readonly')
254+
},
253255
target,
254256
setup: (editor: Editor) => {
255257
this._editor = editor;
256-
editor.on("init", (_e: unknown) => {
257-
const tinymce = this._getTinymce();
258-
const isDisableSupported = isDisabledOptionSupported(tinymce);
259-
if (isDisableSupported && this.hasAttribute('disabled')) {
260-
editor.options.set('disabled', true);
261-
}
262-
if (this.hasAttribute('readonly')) {
263-
editor.options.set('readonly', true);
264-
}
258+
editor.on('init', (_e: unknown) => {
265259
this._status = Status.Ready;
266260
});
267261
editor.on('SwitchMode', (_e: unknown) => {
268262
// this assignment ensures the attribute is in sync with the editor
269263
this.readonly = this.readonly;
270264
});
265+
266+
editor.on('DisabledStateChange', (_e: unknown) => {
267+
// this assignment ensures the attribute is in sync with the editor
268+
this.disabled = this.disabled;
269+
});
270+
271271
Obj.each(this._eventHandlers, (handler, event) => {
272272
if (handler !== undefined) {
273273
editor.on(event, handler);
@@ -382,11 +382,11 @@ class TinyMceEditor extends HTMLElement {
382382
set disabled(value: boolean) {
383383
const tinymce = this._getTinymce?.();
384384
const isVersionNewer = tinymce ? isDisabledOptionSupported(tinymce) : true;
385-
385+
386386
if (this._editor && this._status === Status.Ready && isVersionNewer) {
387-
this._editor.options.set('disabled', value);
387+
this._editor.options.set('disabled', value);
388388
}
389-
389+
390390
if (value && !this.hasAttribute('disabled')) {
391391
this.setAttribute('disabled', '');
392392
} else if (!value && this.hasAttribute('disabled')) {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7055,10 +7055,10 @@ thunky@^1.0.2:
70557055
resolved "https://registry.yarnpkg.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d"
70567056
integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==
70577057

7058-
tinymce@^7.4.1:
7059-
version "7.4.1"
7060-
resolved "https://registry.yarnpkg.com/tinymce/-/tinymce-7.4.1.tgz#cae3160a7d5850e3069d6d79625b1c74918f8af9"
7061-
integrity sha512-g1Ieaio5YU+jLEQZkQyxTT8EY/im+TC/CFBPlqDBCNdsF8YQOeLMot+K6vmFOAXhNc85KhP1rC9Dn2X+iBFDGg==
7058+
tinymce@7.6:
7059+
version "7.6.1"
7060+
resolved "https://registry.yarnpkg.com/tinymce/-/tinymce-7.6.1.tgz#f35990f6e9c2f90220939f545ac032e3d9301b05"
7061+
integrity sha512-5cHhaAoyyTHfAVTInNfoSp0KkUHmeVUbGSu37QKQbOFIPqxYPhqBiaLm1WVLgoNBYOHRProVc3xzxnNTeWHyoQ==
70627062

70637063
tinyrainbow@^1.2.0:
70647064
version "1.2.0"

0 commit comments

Comments
 (0)