Skip to content

Commit 13b2740

Browse files
daKmoRJoren Broekema
authored andcommitted
fix(field): sync type down instead of delegating
1 parent d2f4e3c commit 13b2740

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

packages/field/src/LionField.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DelegateMixin, SlotMixin, LitElement } from '@lion/core';
1+
import { SlotMixin, LitElement } from '@lion/core';
22
import { ElementMixin } from '@lion/core/src/ElementMixin.js';
33
import { DisabledMixin } from '@lion/core/src/DisabledMixin.js';
44
import { ObserverMixin } from '@lion/core/src/ObserverMixin.js';
@@ -35,23 +35,10 @@ import { FocusMixin } from './FocusMixin.js';
3535
export class LionField extends FormControlMixin(
3636
InteractionStateMixin(
3737
FocusMixin(
38-
FormatMixin(
39-
ValidateMixin(
40-
DisabledMixin(ElementMixin(DelegateMixin(SlotMixin(ObserverMixin(LitElement))))),
41-
),
42-
),
38+
FormatMixin(ValidateMixin(DisabledMixin(ElementMixin(SlotMixin(ObserverMixin(LitElement)))))),
4339
),
4440
),
4541
) {
46-
get delegations() {
47-
return {
48-
...super.delegations,
49-
target: () => this.inputElement,
50-
properties: [...super.delegations.properties, 'type'],
51-
attributes: [...super.delegations.attributes, 'type'],
52-
};
53-
}
54-
5542
static get properties() {
5643
return {
5744
submitted: {
@@ -62,6 +49,10 @@ export class LionField extends FormControlMixin(
6249
type: String,
6350
reflect: true,
6451
},
52+
type: {
53+
type: String,
54+
reflect: true,
55+
},
6556
};
6657
}
6758

@@ -112,6 +103,7 @@ export class LionField extends FormControlMixin(
112103
super();
113104
this.name = '';
114105
this.submitted = false;
106+
this.type = 'text';
115107
}
116108

117109
connectedCallback() {
@@ -152,6 +144,9 @@ export class LionField extends FormControlMixin(
152144
if (changedProps.has('name')) {
153145
this.inputElement.name = this.name;
154146
}
147+
if (changedProps.has('type')) {
148+
this.inputElement.type = this.type;
149+
}
155150
}
156151

157152
/**

packages/field/test/lion-field.test.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ describe('<lion-field>', () => {
128128
expect(el.inputElement.getAttribute('name')).to.equal('foo');
129129
});
130130

131+
it('has a type which is reflected to an attribute and is synced down to the native input', async () => {
132+
const el = await fixture(`<${tagString}>${inputSlotString}</${tagString}>`);
133+
expect(el.type).to.equal('text');
134+
expect(el.getAttribute('type')).to.equal('text');
135+
expect(el.inputElement.getAttribute('type')).to.equal('text');
136+
137+
el.type = 'foo';
138+
await el.updateComplete;
139+
expect(el.getAttribute('type')).to.equal('foo');
140+
expect(el.inputElement.getAttribute('type')).to.equal('foo');
141+
});
142+
131143
// TODO: find out if we could put all listeners on this.value (instead of this.inputElement.value)
132144
// and make it act on this.value again
133145
it('has a class "state-filled" if this.value is filled', async () => {
@@ -397,23 +409,6 @@ describe('<lion-field>', () => {
397409
expect(el.inputElement.value).to.equal('one');
398410
});
399411

400-
it('delegates property type', async () => {
401-
const el = await fixture(`<${tagString} type="text">${inputSlotString}</${tagString}>`);
402-
const inputElemTag = el.inputElement.tagName.toLowerCase();
403-
if (inputElemTag === 'select') {
404-
// TODO: later on we might want to support multi select ?
405-
expect(el.inputElement.type).to.contain('select-one');
406-
} else if (inputElemTag === 'textarea') {
407-
expect(el.inputElement.type).to.contain('textarea');
408-
} else {
409-
// input or custom inputElement
410-
expect(el.inputElement.type).to.contain('text');
411-
el.type = 'password';
412-
expect(el.type).to.equal('password');
413-
expect(el.inputElement.type).to.equal('password');
414-
}
415-
});
416-
417412
it('delegates property selectionStart and selectionEnd', async () => {
418413
const el = await fixture(html`
419414
<${tag}

0 commit comments

Comments
 (0)