Skip to content

Commit dcf8726

Browse files
committed
fix(field): remove CssClassMixin from InteractionStateMixin
1 parent b398f40 commit dcf8726

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

packages/field/src/InteractionStateMixin.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { dedupeMixin } from '@lion/core';
2-
import { CssClassMixin } from '@lion/core/src/CssClassMixin.js';
32
import { ObserverMixin } from '@lion/core/src/ObserverMixin.js';
43
import { Unparseable } from '@lion/validate';
54

@@ -15,7 +14,7 @@ import { Unparseable } from '@lion/validate';
1514
export const InteractionStateMixin = dedupeMixin(
1615
superclass =>
1716
// eslint-disable-next-line no-unused-vars, no-shadow
18-
class InteractionStateMixin extends CssClassMixin(ObserverMixin(superclass)) {
17+
class InteractionStateMixin extends ObserverMixin(superclass) {
1918
static get properties() {
2019
return {
2120
...super.properties,
@@ -24,15 +23,15 @@ export const InteractionStateMixin = dedupeMixin(
2423
*/
2524
touched: {
2625
type: Boolean,
27-
nonEmptyToClass: 'state-touched',
26+
reflect: true,
2827
},
2928

3029
/**
3130
* True when user has typed in something in the input field.
3231
*/
3332
dirty: {
3433
type: Boolean,
35-
nonEmptyToClass: 'state-dirty',
34+
reflect: true,
3635
},
3736

3837
/**
@@ -101,6 +100,17 @@ export const InteractionStateMixin = dedupeMixin(
101100
this.removeEventListener(this._valueChangedEvent, this._iStateOnValueChange);
102101
}
103102

103+
updated(changedProperties) {
104+
super.updated(changedProperties);
105+
// classes are added only for backward compatibility - they are deprecated
106+
if (changedProperties.has('touched')) {
107+
this.classList[this.touched ? 'add' : 'remove']('state-touched');
108+
}
109+
if (changedProperties.has('dirty')) {
110+
this.classList[this.dirty ? 'add' : 'remove']('state-dirty');
111+
}
112+
}
113+
104114
/**
105115
* Evaluations performed on connectedCallback. Since some components can be out of sync
106116
* (due to interdependence on light children that can only be processed

packages/field/test/InteractionStateMixin.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ describe('InteractionStateMixin', async () => {
5959
expect(el.touched).to.be.true;
6060
});
6161

62+
// classes are added only for backward compatibility - they are deprecated
6263
it('sets a class "state-(touched|dirty)"', async () => {
6364
const el = await fixture(html`<${tag}></${tag}>`);
6465
el.touched = true;
@@ -70,6 +71,20 @@ describe('InteractionStateMixin', async () => {
7071
expect(el.classList.contains('state-dirty')).to.equal(true, 'has class "state-dirty"');
7172
});
7273

74+
it('sets an attribute "touched', async () => {
75+
const el = await fixture(html`<${tag}></${tag}>`);
76+
el.touched = true;
77+
await el.updateComplete;
78+
expect(el.hasAttribute('touched')).to.be.true;
79+
});
80+
81+
it('sets an attribute "dirty', async () => {
82+
const el = await fixture(html`<${tag}></${tag}>`);
83+
el.dirty = true;
84+
await el.updateComplete;
85+
expect(el.hasAttribute('dirty')).to.be.true;
86+
});
87+
7388
it('fires "(touched|dirty)-state-changed" event when state changes', async () => {
7489
const touchedSpy = sinon.spy();
7590
const dirtySpy = sinon.spy();

0 commit comments

Comments
 (0)