Skip to content

Commit 07eddb3

Browse files
daKmoRJoren Broekema
authored andcommitted
fix(field): getter/setter for selectionStart/End instead of delegation
1 parent 88f5264 commit 07eddb3

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

packages/field/src/LionField.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,7 @@ export class LionField extends FormControlMixin(
4747
return {
4848
...super.delegations,
4949
target: () => this.inputElement,
50-
properties: [
51-
...super.delegations.properties,
52-
'name',
53-
'type',
54-
'selectionStart',
55-
'selectionEnd',
56-
],
50+
properties: [...super.delegations.properties, 'name', 'type'],
5751
attributes: [...super.delegations.attributes, 'name', 'type'],
5852
};
5953
}
@@ -67,6 +61,36 @@ export class LionField extends FormControlMixin(
6761
};
6862
}
6963

64+
get selectionStart() {
65+
const native = this.inputElement;
66+
if (native && native.selectionStart) {
67+
return native.selectionStart;
68+
}
69+
return 0;
70+
}
71+
72+
set selectionStart(value) {
73+
const native = this.inputElement;
74+
if (native && native.selectionStart) {
75+
native.selectionStart = value;
76+
}
77+
}
78+
79+
get selectionEnd() {
80+
const native = this.inputElement;
81+
if (native && native.selectionEnd) {
82+
return native.selectionEnd;
83+
}
84+
return 0;
85+
}
86+
87+
set selectionEnd(value) {
88+
const native = this.inputElement;
89+
if (native && native.selectionEnd) {
90+
native.selectionEnd = value;
91+
}
92+
}
93+
7094
// We don't delegate, because we want to preserve caret position via _setValueAndPreserveCaret
7195
set value(value) {
7296
// if not yet connected to dom can't change the value

0 commit comments

Comments
 (0)