mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
fix: issue with controlled input selection ranges
This commit is contained in:
parent
43c31babcd
commit
4524bc4598
5
.changeset/spicy-results-teach.md
Normal file
5
.changeset/spicy-results-teach.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@marko/runtime-tags": patch
|
||||
---
|
||||
|
||||
Fix issue with controlled input selection ranges.
|
||||
@ -7,8 +7,8 @@
|
||||
{
|
||||
"name": "*",
|
||||
"total": {
|
||||
"min": 18907,
|
||||
"brotli": 7216
|
||||
"min": 18901,
|
||||
"brotli": 7208
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// size: 18907 (min) 7216 (brotli)
|
||||
// size: 18901 (min) 7208 (brotli)
|
||||
var empty = [],
|
||||
rest = Symbol();
|
||||
function attrTag(attrs2) {
|
||||
@ -361,14 +361,12 @@ function controllable_input_value_effect(scope, nodeAccessor) {
|
||||
isResuming && (scope["g" + nodeAccessor] = el.defaultValue),
|
||||
syncControllable(el, "input", hasValueChanged, (ev) => {
|
||||
let valueChange = scope["e" + nodeAccessor];
|
||||
if (valueChange) {
|
||||
let newValue = el.value;
|
||||
(inputType = ev?.inputType),
|
||||
setValueAndUpdateSelection(el, scope["g" + nodeAccessor]),
|
||||
valueChange(newValue),
|
||||
run(),
|
||||
(inputType = "");
|
||||
}
|
||||
valueChange &&
|
||||
((inputType = ev?.inputType),
|
||||
valueChange(el.value),
|
||||
run(),
|
||||
setValueAndUpdateSelection(el, scope["g" + nodeAccessor]),
|
||||
(inputType = ""));
|
||||
});
|
||||
}
|
||||
function controllable_select_value(scope, nodeAccessor, value2, valueChange) {
|
||||
@ -482,7 +480,7 @@ function setValueAndUpdateSelection(el, value2) {
|
||||
el.value,
|
||||
(el.value = value2),
|
||||
);
|
||||
~updatedPosition && (el.selectionStart = updatedPosition);
|
||||
~updatedPosition && el.setSelectionRange(updatedPosition, updatedPosition);
|
||||
}
|
||||
}
|
||||
function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
|
||||
|
||||
@ -137,14 +137,13 @@ export function controllable_input_value_effect(
|
||||
AccessorPrefix.ControlledHandler + nodeAccessor
|
||||
] as undefined | ((value: unknown) => unknown);
|
||||
if (valueChange) {
|
||||
const newValue = el.value;
|
||||
inputType = (ev as InputEvent)?.inputType;
|
||||
valueChange(el.value);
|
||||
run();
|
||||
setValueAndUpdateSelection(
|
||||
el,
|
||||
scope[AccessorPrefix.ControlledValue + nodeAccessor],
|
||||
);
|
||||
valueChange(newValue);
|
||||
run();
|
||||
inputType = "";
|
||||
}
|
||||
});
|
||||
@ -306,7 +305,7 @@ function setValueAndUpdateSelection(el: HTMLInputElement, value: string) {
|
||||
(el.value = value),
|
||||
);
|
||||
if (~updatedPosition) {
|
||||
el.selectionStart = updatedPosition;
|
||||
el.setSelectionRange(updatedPosition, updatedPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user