Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit d55ca11

Browse files
developitacdvorak
authored andcommitted
fix(text-field): Don't move caret when value has not changed (#4160)
This fixes an issue where the cursor on Safari will be reset to its end position any time `.setValue()` is called.
1 parent de6c833 commit d55ca11

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

packages/mdc-textfield/foundation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,10 @@ class MDCTextFieldFoundation extends MDCFoundation {
292292
* @param {string} value The value to set on the input Element.
293293
*/
294294
setValue(value) {
295-
this.getNativeInput_().value = value;
295+
// Prevent Safari from moving the caret to the end of the input when the value has not changed.
296+
if (this.getValue() !== value) {
297+
this.getNativeInput_().value = value;
298+
}
296299
const isValid = this.isValid();
297300
this.styleValidity_(isValid);
298301
if (this.adapter_.hasLabel()) {

0 commit comments

Comments
 (0)