Skip to content

Commit c4a2f02

Browse files
committed
feat: adding disabled state
1 parent ca1b5b5 commit c4a2f02

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

api-property-form-item.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ declare namespace ApiElements {
129129
/**
130130
* When set the editor is in read only mode.
131131
*/
132-
readonly: boolean|null|undefined;
132+
readOnly: boolean|null|undefined;
133+
134+
/**
135+
* When set the editor renders form controls disabled.
136+
*/
137+
disabled: boolean|null|undefined;
133138

134139
/**
135140
* Computed value, renders nillable switch when needed.

api-property-form-item.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
110110
}
111111

112112
_enumTemplate() {
113-
const { model, name, readOnly, value, outlined, legacy } = this;
113+
const { model, name, readOnly, disabled, value, outlined, legacy } = this;
114114
const values = model.schema.enum || [];
115115
return html`
116116
<anypoint-dropdown-menu
117117
name="${name}"
118118
?required="${model.required}"
119119
autovalidate
120120
data-type="enum"
121-
?disabled="${readOnly}"
121+
?disabled="${readOnly || disabled}"
122122
?outlined="${outlined}"
123123
?legacy="${legacy}">
124124
<label slot="label">${model.schema.inputLabel}</label>
@@ -134,14 +134,14 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
134134
}
135135

136136
_booleanTemplate() {
137-
const { model, name, readOnly, value, outlined, legacy } = this;
137+
const { model, name, readOnly, disabled, value, outlined, legacy } = this;
138138
return html`
139139
<anypoint-dropdown-menu
140140
name="${name}"
141141
?required="${model.required}"
142142
autovalidate
143143
data-type="boolean"
144-
?disabled="${readOnly}"
144+
?disabled="${readOnly || disabled}"
145145
?outlined="${outlined}"
146146
?legacy="${legacy}">
147147
<label slot="label">${model.schema.inputLabel}</label>
@@ -158,7 +158,7 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
158158
}
159159

160160
_inputTemplate() {
161-
const { model, name, noLabelFloat, readOnly, value, outlined, legacy } = this;
161+
const { model, name, noLabelFloat, readOnly, disabled, value, outlined, legacy } = this;
162162
if (!model) {
163163
return;
164164
}
@@ -179,6 +179,7 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
179179
.placeholder="${model.schema.inputPlaceholder}"
180180
?nolabelfloat="${noLabelFloat}"
181181
?readonly="${readOnly}"
182+
?disabled="${disabled}"
182183
?outlined="${outlined}"
183184
?legacy="${legacy}"
184185
data-type="input"
@@ -188,7 +189,7 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
188189
}
189190

190191
_arrayTemplate() {
191-
const { model, name, readOnly, _arrayValue, outlined, legacy } = this;
192+
const { model, name, readOnly, disabled, _arrayValue, outlined, legacy } = this;
192193
const values = _arrayValue || [];
193194
const itemLabel = model.schema.inputLabel || 'Parameter value';
194195
return html`
@@ -209,6 +210,7 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
209210
.minLength="${model.schema.minLength}"
210211
nolabelfloat
211212
?readonly="${readOnly}"
213+
?disabled="${disabled}"
212214
?outlined="${outlined}"
213215
?legacy="${legacy}"
214216
data-type="array"
@@ -223,15 +225,15 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
223225
?legacy="${legacy}"
224226
@click="${this._removeArrayValue}"
225227
title="Remove array value"
226-
?disabled="${this.readOnly}">
228+
?disabled="${this.readOnly || disabled}">
227229
<iron-icon icon="arc:remove-circle-outline"></iron-icon>
228230
</anypoint-icon-button>` : undefined}
229231
</div>`)}
230232
<div class="add-action">
231233
<anypoint-button
232234
@click="${this.addEmptyArrayValue}"
233235
title="Add array velue button"
234-
?disabled="${readOnly}"
236+
?disabled="${readOnly || disabled}"
235237
?outlined="${outlined}"
236238
?legacy="${legacy}">
237239
<iron-icon class="action-icon" icon="arc:add-circle-outline" alt="Add array value icon"></iron-icon>
@@ -242,7 +244,7 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
242244
}
243245

244246
render() {
245-
const { readOnly, _isEnum, _isBoolean, _isInput, _isArray, _renderNillable } = this;
247+
const { readOnly, disabled, _isEnum, _isBoolean, _isInput, _isArray, _renderNillable } = this;
246248
return html`
247249
<div class="content">
248250
${_isEnum ? this._enumTemplate() : undefined}
@@ -251,7 +253,7 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
251253
${_isArray ? this._arrayTemplate() : undefined}
252254
253255
${_renderNillable ? html`<anypoint-checkbox
254-
?disabled="${readOnly}"
256+
?disabled="${readOnly || disabled}"
255257
class="nil-option"
256258
@checked-changed="${this._nillableChanged}">Nil</anypoint-checkbox>` : undefined}
257259
</div>`;
@@ -308,6 +310,10 @@ class ApiPropertyFormItem extends ValidatableMixin(LitElement) {
308310
* When set the editor is in read only mode.
309311
*/
310312
readOnly: { type: Boolean },
313+
/**
314+
* When set the editor renders form controls disabled.
315+
*/
316+
disabled: { type: Boolean },
311317
// Computed value, renders nillable switch when needed.
312318
_renderNillable: { type: Boolean }
313319
};

0 commit comments

Comments
 (0)