Skip to content

Commit 3981985

Browse files
committed
fix(field): make InteractionState leaveEvent protected
1 parent dcf8726 commit 3981985

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

packages/field/src/InteractionStateMixin.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const InteractionStateMixin = dedupeMixin(
7373
this.touched = false;
7474
this.dirty = false;
7575
this.prefilled = false;
76-
this.leaveEvent = 'blur';
76+
this._leaveEvent = 'blur';
7777
this._valueChangedEvent = 'model-value-changed';
7878

7979
this._iStateOnLeave = this._iStateOnLeave.bind(this);
@@ -87,7 +87,7 @@ export const InteractionStateMixin = dedupeMixin(
8787
if (super.connectedCallback) {
8888
super.connectedCallback();
8989
}
90-
this.addEventListener(this.leaveEvent, this._iStateOnLeave);
90+
this.addEventListener(this._leaveEvent, this._iStateOnLeave);
9191
this.addEventListener(this._valueChangedEvent, this._iStateOnValueChange);
9292
this.initInteractionState();
9393
}
@@ -96,7 +96,7 @@ export const InteractionStateMixin = dedupeMixin(
9696
if (super.disconnectedCallback) {
9797
super.disconnectedCallback();
9898
}
99-
this.removeEventListener(this.leaveEvent, this._iStateOnLeave);
99+
this.removeEventListener(this._leaveEvent, this._iStateOnLeave);
100100
this.removeEventListener(this._valueChangedEvent, this._iStateOnValueChange);
101101
}
102102

@@ -159,5 +159,19 @@ export const InteractionStateMixin = dedupeMixin(
159159
_onDirtyChanged() {
160160
this.dispatchEvent(new CustomEvent('dirty-changed', { bubbles: true, composed: true }));
161161
}
162+
163+
/**
164+
* @deprecated
165+
*/
166+
get leaveEvent() {
167+
return this._leaveEvent;
168+
}
169+
170+
/**
171+
* @deprecated
172+
*/
173+
set leaveEvent(eventName) {
174+
this._leaveEvent = eventName;
175+
}
162176
},
163177
);

packages/field/test/InteractionStateMixin.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,26 @@ describe('InteractionStateMixin', async () => {
164164
expect(el.touched).to.be.false;
165165
expect(el.prefilled).to.be.true;
166166
});
167+
168+
describe('SubClassers', () => {
169+
it('can override the `_leaveEvent`', async () => {
170+
const tagLeaveString = defineCE(
171+
class IState extends InteractionStateMixin(LitElement) {
172+
constructor() {
173+
super();
174+
this._leaveEvent = 'custom-blur';
175+
}
176+
},
177+
);
178+
const tagLeave = unsafeStatic(tagLeaveString);
179+
const el = await fixture(html`<${tagLeave}></${tagLeave}>`);
180+
el.dispatchEvent(new Event('custom-blur'));
181+
expect(el.touched).to.be.true;
182+
});
183+
184+
it('can override the deprecated `leaveEvent`', async () => {
185+
const el = await fixture(html`<${tag} .leaveEvent=${'custom-blur'}></${tag}>`);
186+
expect(el._leaveEvent).to.equal('custom-blur');
187+
});
188+
});
167189
});

0 commit comments

Comments
 (0)