fix(field): getter/setter for selectionStart/End instead of delegation

This commit is contained in:
Thomas Allmer 2019-08-06 16:39:59 +02:00 committed by Joren Broekema
parent 88f52646b8
commit 07eddb38c3

View file

@ -47,13 +47,7 @@ export class LionField extends FormControlMixin(
return {
...super.delegations,
target: () => this.inputElement,
properties: [
...super.delegations.properties,
'name',
'type',
'selectionStart',
'selectionEnd',
],
properties: [...super.delegations.properties, 'name', 'type'],
attributes: [...super.delegations.attributes, 'name', 'type'],
};
}
@ -67,6 +61,36 @@ export class LionField extends FormControlMixin(
};
}
get selectionStart() {
const native = this.inputElement;
if (native && native.selectionStart) {
return native.selectionStart;
}
return 0;
}
set selectionStart(value) {
const native = this.inputElement;
if (native && native.selectionStart) {
native.selectionStart = value;
}
}
get selectionEnd() {
const native = this.inputElement;
if (native && native.selectionEnd) {
return native.selectionEnd;
}
return 0;
}
set selectionEnd(value) {
const native = this.inputElement;
if (native && native.selectionEnd) {
native.selectionEnd = value;
}
}
// We don't delegate, because we want to preserve caret position via _setValueAndPreserveCaret
set value(value) {
// if not yet connected to dom can't change the value