Skip to content

Commit 01ef601

Browse files
committed
TINY-11911: Handle updates of the disabled attribute
1 parent 2f23731 commit 01ef601

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

src/demo/html/disabled.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title>TinyMCE WebComponent Demo: Disabled and Readonly </title>
6+
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
7+
</head>
8+
9+
<body>
10+
<script>
11+
function toggleDisabled() {
12+
var editor = document.getElementById('mody');
13+
14+
if (!editor.hasAttribute('disabled')) {
15+
editor.setAttribute('disabled', '');
16+
} else {
17+
editor.removeAttribute('disabled');
18+
}
19+
}
20+
21+
function toggleReadonly() {
22+
var editor = document.getElementById('mody');
23+
24+
editor.removeAttribute('disabled');
25+
if (!editor.hasAttribute('readonly')) {
26+
editor.setAttribute('readonly', '');
27+
} else {
28+
editor.removeAttribute('readonly');
29+
}
30+
}
31+
</script>
32+
<h2>TinyMCE WebComponent Demo: Disabled and Readonly</h2>
33+
<div id="ephox-ui">
34+
<button onclick="toggleDisabled()">Toggle disabled</button>
35+
<button onclick="toggleReadonly()">Toggle readonly</button>
36+
<tinymce-editor id="mody"></tinymce-editor>
37+
</div>
38+
<script src="../../../node_modules/tinymce/tinymce.js"></script>
39+
<script src="../../../dist/tinymce-webcomponent.js"></script>
40+
</body>
41+
</html>

src/main/ts/component/Editor.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const configAttributes: Record<string, (v: string) => unknown> = {
7474
icons: parseString, // name of icon pack eg. 'material'
7575
icons_url: parseString, // url to icon pack js
7676
promotion: parseBooleanOrString, // boolean
77-
disabled: parseBooleanOrString, // boolean
7877
};
7978

8079
const configRenames: Record<string, string> = {
@@ -202,6 +201,9 @@ class TinyMceEditor extends HTMLElement {
202201
if (this.readonly) {
203202
config.readonly = true;
204203
}
204+
if (this.disabled) {
205+
config.disabled = true;
206+
}
205207
if (this.autofocus) {
206208
config.auto_focus = true;
207209
}
@@ -294,6 +296,8 @@ class TinyMceEditor extends HTMLElement {
294296
if (oldValue !== newValue) {
295297
if (attribute === 'form') {
296298
this._updateForm();
299+
} else if (attribute === 'disabled') {
300+
this.disabled = newValue !== null;
297301
} else if (attribute === 'readonly') {
298302
this.readonly = newValue !== null;
299303
} else if (attribute === 'autofocus') {
@@ -357,25 +361,23 @@ class TinyMceEditor extends HTMLElement {
357361
}
358362

359363
get disabled(): boolean {
360-
if (this._editor) {
361-
return this._editor.mode.get() === 'disabled';
362-
} else {
363-
return this.hasAttribute('disabled');
364-
}
364+
return this._editor ? this._editor.options.get('disabled') : this.hasAttribute('disabled');
365365
}
366366

367367
set disabled(value: boolean) {
368368
if (value) {
369-
if (this._editor && this._editor.mode.get() !== 'disabled') {
370-
this._editor.mode.set('disabled');
369+
if (this._editor && this._editor.options.get('disabled') === false) {
370+
this._editor.options.set('disabled', value);
371371
}
372+
372373
if (!this.hasAttribute('disabled')) {
373374
this.setAttribute('disabled', '');
374375
}
375376
} else {
376-
if (this._editor && this._editor.mode.get() === 'disabled') {
377-
this._editor.mode.set('design');
377+
if (this._editor && this._editor.options.get('disabled') === true) {
378+
this._editor.options.set('disabled', false);
378379
}
380+
379381
if (this.hasAttribute('disabled')) {
380382
this.removeAttribute('disabled');
381383
}

0 commit comments

Comments
 (0)