Skip to content

Commit 7a94210

Browse files
authored
fix: handle synchronous read-only properties in polylit-mixin (#6457)
1 parent 738ee11 commit 7a94210

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎packages/component-base/src/polylit-mixin.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ const PolylitMixinImplementation = (superclass) => {
129129
// This is run during construction of the element
130130
instance[`_set${upper(name)}`] = function (value) {
131131
setter.call(instance, value);
132+
133+
if (options.sync) {
134+
this.performUpdate();
135+
}
132136
};
133137
});
134138

‎packages/component-base/test/polylit-mixin.test.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,19 @@ describe('PolylitMixin', () => {
925925
value: 0,
926926
sync: true,
927927
},
928+
929+
opened: {
930+
type: Boolean,
931+
readOnly: true,
932+
sync: true,
933+
reflect: true,
934+
},
935+
936+
helper: {
937+
type: String,
938+
readOnly: true,
939+
reflect: true,
940+
},
928941
};
929942
}
930943

@@ -960,6 +973,22 @@ describe('PolylitMixin', () => {
960973
expect(element.hasAttribute('disabled')).to.be.false;
961974
});
962975

976+
it('should reflect immediately when setting a read-only sync property', () => {
977+
element._setOpened(true);
978+
expect(element.hasAttribute('opened')).to.be.true;
979+
980+
element._setOpened(false);
981+
expect(element.hasAttribute('opened')).to.be.false;
982+
});
983+
984+
it('should not reflect immediately when setting a read-only non-sync property', () => {
985+
element._setHelper('foo');
986+
expect(element.hasAttribute('helper')).to.be.false;
987+
988+
element.performUpdate();
989+
expect(element.hasAttribute('helper')).to.be.true;
990+
});
991+
963992
it('should only call ready callback once during initialization', () => {
964993
expect(element.count).to.equal(1);
965994
});

0 commit comments

Comments
 (0)