Skip to content

Commit 7d38577

Browse files
paodbjavier-godoy
authored andcommitted
fix: fix component style for readonly mode
Close #40
1 parent ec5838f commit 7d38577

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/main/java/com/flowingcode/vaadin/addons/chipfield/ChipField.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ public boolean isReadonly() {
306306
return this.isReadonly();
307307
}
308308

309+
@Override
310+
public void setReadOnly(boolean readOnly) {
311+
super.setReadOnly(readOnly);
312+
getElement().callJsFunction("toggleReadonly");
313+
}
314+
309315
/** @deprecated use {@link #setRequiredIndicatorVisible(boolean)} */
310316
@Deprecated
311317
public void setRequired(boolean required) {

src/main/resources/META-INF/frontend/paper-chip-input-autocomplete.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class PaperChipInputAutocomplete extends PolymerElement {
287287
[[item.name]]
288288
<paper-chip id="paper-chip-[[item]]-[[index]]"
289289
label="[[item]]"
290-
closable$="[[closable]]"
290+
closable="[[_isClosable(closable,readonly)]]"
291291
on-chip-removed="_removeChip">
292292
</paper-chip>
293293
</template>
@@ -318,6 +318,7 @@ class PaperChipInputAutocomplete extends PolymerElement {
318318
this._autoValidate = this.autoValidate;
319319
this._required = this.required;
320320
this._paperInputElement = this.$.paperInput;
321+
this.toggleReadonly();
321322
}
322323

323324
_isEmpty(item) {
@@ -457,6 +458,18 @@ class PaperChipInputAutocomplete extends PolymerElement {
457458
}));
458459
}
459460

461+
_isClosable(closable, readonly) {
462+
return closable && !readonly;
463+
}
464+
465+
toggleReadonly() {
466+
if(this.readonly){
467+
this.$.paperInput.style.pointerEvents="none";
468+
} else {
469+
this.$.paperInput.style.removeProperty("pointer-events");
470+
}
471+
}
472+
460473
}
461474

462475
window.customElements.define(PaperChipInputAutocomplete.is, PaperChipInputAutocomplete);

0 commit comments

Comments
 (0)