Skip to content

Commit ca9009e

Browse files
committed
Fix #1413: show color indicator on readonly fields
1 parent 26bcebd commit ca9009e

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
https://github.com/josdejong/jsoneditor
44

55

6+
## not yet published, version 9.7.0
7+
8+
- Implement #1413: show color indicator on readonly fields.
9+
10+
611
## 2022-01-13, version 9.6.0
712

813
- Pass a new property `value` along with the `onNodeName` callback, see #1409.

src/js/Node.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,8 +1785,7 @@ export class Node {
17851785
}
17861786

17871787
// show color picker when value is a color
1788-
if (this.editable.value &&
1789-
this.editor.options.colorPicker &&
1788+
if (this.editor.options.colorPicker &&
17901789
typeof value === 'string' &&
17911790
isValidColor(value)) {
17921791
if (!this.dom.color) {
@@ -1802,6 +1801,11 @@ export class Node {
18021801

18031802
// update styling of value and color background
18041803
addClassName(this.dom.value, 'jsoneditor-color-value')
1804+
if (!this.editable.value) {
1805+
addClassName(this.dom.color, 'jsoneditor-color-readonly')
1806+
} else {
1807+
removeClassName(this.dom.color, 'jsoneditor-color-readonly')
1808+
}
18051809
this.dom.color.style.backgroundColor = value
18061810
} else {
18071811
// cleanup color picker when displayed
@@ -2536,7 +2540,11 @@ export class Node {
25362540
}
25372541
}
25382542

2539-
if (type === 'click' && (event.target === node.dom.tdColor || event.target === node.dom.color)) {
2543+
if (
2544+
type === 'click' &&
2545+
(event.target === node.dom.tdColor || event.target === node.dom.color) &&
2546+
this.editable.value
2547+
) {
25402548
this._showColorPicker()
25412549
}
25422550

src/scss/jsoneditor/_editor.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ div {
185185
margin: 4px;
186186
border: 1px solid $jse-readonly;
187187
cursor: pointer;
188+
189+
&.jsoneditor-color-readonly {
190+
cursor: inherit;
191+
}
188192
}
189193
&.jsoneditor-date {
190194
background: $jse-date;

0 commit comments

Comments
 (0)