From 07eddb38c385e68a356e9646e400da6c8276b261 Mon Sep 17 00:00:00 2001 From: Thomas Allmer Date: Tue, 6 Aug 2019 16:39:59 +0200 Subject: [PATCH] fix(field): getter/setter for selectionStart/End instead of delegation --- packages/field/src/LionField.js | 38 +++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/packages/field/src/LionField.js b/packages/field/src/LionField.js index e9ef66064..d4425308e 100644 --- a/packages/field/src/LionField.js +++ b/packages/field/src/LionField.js @@ -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