fix(field): move type property to input & add step property to input
This commit is contained in:
parent
13b27407b5
commit
5d893f3760
6 changed files with 45 additions and 31 deletions
|
|
@ -49,10 +49,6 @@ export class LionField extends FormControlMixin(
|
||||||
type: String,
|
type: String,
|
||||||
reflect: true,
|
reflect: true,
|
||||||
},
|
},
|
||||||
type: {
|
|
||||||
type: String,
|
|
||||||
reflect: true,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +99,6 @@ export class LionField extends FormControlMixin(
|
||||||
super();
|
super();
|
||||||
this.name = '';
|
this.name = '';
|
||||||
this.submitted = false;
|
this.submitted = false;
|
||||||
this.type = 'text';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
|
|
@ -144,9 +139,6 @@ export class LionField extends FormControlMixin(
|
||||||
if (changedProps.has('name')) {
|
if (changedProps.has('name')) {
|
||||||
this.inputElement.name = this.name;
|
this.inputElement.name = this.name;
|
||||||
}
|
}
|
||||||
if (changedProps.has('type')) {
|
|
||||||
this.inputElement.type = this.type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -128,18 +128,6 @@ describe('<lion-field>', () => {
|
||||||
expect(el.inputElement.getAttribute('name')).to.equal('foo');
|
expect(el.inputElement.getAttribute('name')).to.equal('foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has a type which is reflected to an attribute and is synced down to the native input', async () => {
|
|
||||||
const el = await fixture(`<${tagString}>${inputSlotString}</${tagString}>`);
|
|
||||||
expect(el.type).to.equal('text');
|
|
||||||
expect(el.getAttribute('type')).to.equal('text');
|
|
||||||
expect(el.inputElement.getAttribute('type')).to.equal('text');
|
|
||||||
|
|
||||||
el.type = 'foo';
|
|
||||||
await el.updateComplete;
|
|
||||||
expect(el.getAttribute('type')).to.equal('foo');
|
|
||||||
expect(el.inputElement.getAttribute('type')).to.equal('foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO: find out if we could put all listeners on this.value (instead of this.inputElement.value)
|
// TODO: find out if we could put all listeners on this.value (instead of this.inputElement.value)
|
||||||
// and make it act on this.value again
|
// and make it act on this.value again
|
||||||
it('has a class "state-filled" if this.value is filled', async () => {
|
it('has a class "state-filled" if this.value is filled', async () => {
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,14 @@ export class LionInput extends LionField {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
attribute: 'readonly',
|
attribute: 'readonly',
|
||||||
},
|
},
|
||||||
};
|
type: {
|
||||||
}
|
type: String,
|
||||||
|
reflect: true,
|
||||||
get delegations() {
|
},
|
||||||
return {
|
step: {
|
||||||
...super.delegations,
|
type: Number,
|
||||||
properties: [...super.delegations.properties, 'step'],
|
reflect: true,
|
||||||
attributes: [...super.delegations.attributes, 'step'],
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,6 +47,18 @@ export class LionInput extends LionField {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.readOnly = false;
|
||||||
|
this.type = 'text';
|
||||||
|
/**
|
||||||
|
* Only application to type="amount" & type="range"
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
this.step = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
_requestUpdate(name, oldValue) {
|
_requestUpdate(name, oldValue) {
|
||||||
super._requestUpdate(name, oldValue);
|
super._requestUpdate(name, oldValue);
|
||||||
if (name === 'readOnly') {
|
if (name === 'readOnly') {
|
||||||
|
|
@ -59,6 +71,16 @@ export class LionInput extends LionField {
|
||||||
this.__delegateReadOnly();
|
this.__delegateReadOnly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updated(changedProps) {
|
||||||
|
super.updated(changedProps);
|
||||||
|
if (changedProps.has('type')) {
|
||||||
|
this.inputElement.type = this.type;
|
||||||
|
}
|
||||||
|
if (changedProps.has('step')) {
|
||||||
|
this.inputElement.step = this.step;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
__delegateReadOnly() {
|
__delegateReadOnly() {
|
||||||
if (this.inputElement) {
|
if (this.inputElement) {
|
||||||
this.inputElement.readOnly = this.readOnly;
|
this.inputElement.readOnly = this.readOnly;
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,16 @@ describe('<lion-input>', () => {
|
||||||
const el = await fixture(`<lion-input></lion-input>`);
|
const el = await fixture(`<lion-input></lion-input>`);
|
||||||
expect(el.querySelector('input')).to.equal(el.inputElement);
|
expect(el.querySelector('input')).to.equal(el.inputElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('has a type which is reflected to an attribute and is synced down to the native input', async () => {
|
||||||
|
const el = await fixture(`<lion-input></lion-input>`);
|
||||||
|
expect(el.type).to.equal('text');
|
||||||
|
expect(el.getAttribute('type')).to.equal('text');
|
||||||
|
expect(el.inputElement.getAttribute('type')).to.equal('text');
|
||||||
|
|
||||||
|
el.type = 'foo';
|
||||||
|
await el.updateComplete;
|
||||||
|
expect(el.getAttribute('type')).to.equal('foo');
|
||||||
|
expect(el.inputElement.getAttribute('type')).to.equal('foo');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lion/core": "^0.1.13",
|
"@lion/core": "^0.1.13",
|
||||||
"@lion/input": "^0.1.44",
|
"@lion/field": "^0.1.42",
|
||||||
"autosize": "4.0.2"
|
"autosize": "4.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import autosize from 'autosize/src/autosize.js';
|
import autosize from 'autosize/src/autosize.js';
|
||||||
import { LionInput } from '@lion/input';
|
import { LionField } from '@lion/field';
|
||||||
import { css } from '@lion/core';
|
import { css } from '@lion/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -8,7 +8,7 @@ import { css } from '@lion/core';
|
||||||
* @customElement
|
* @customElement
|
||||||
* @extends LionInput
|
* @extends LionInput
|
||||||
*/
|
*/
|
||||||
export class LionTextarea extends LionInput {
|
export class LionTextarea extends LionField {
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
maxRows: {
|
maxRows: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue