Skip to content

Commit 7a9e9a3

Browse files
authored
fix(ui5-input): fix inpur cursor movement in Safari (#1983)
1 parent 3b614ad commit 7a9e9a3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/main/src/Input.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
22
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
33
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
44
import RenderScheduler from "@ui5/webcomponents-base/dist/RenderScheduler.js";
5-
import { isIE, isPhone } from "@ui5/webcomponents-base/dist/Device.js";
5+
import { isIE, isPhone, isSafari } from "@ui5/webcomponents-base/dist/Device.js";
66
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
77
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
88
import {
@@ -843,9 +843,20 @@ class Input extends UI5Element {
843843
const isSubmit = action === this.ACTION_ENTER;
844844
const isUserInput = action === this.ACTION_USER_INPUT;
845845

846+
const input = await this.getInputDOMRef();
847+
const cursorPosition = input.selectionStart;
848+
846849
this.value = inputValue;
847850
this.highlightValue = inputValue;
848851

852+
if (isSafari()) {
853+
// When setting the value by hand, Safari moves the cursor when typing in the middle of the text (See #1761)
854+
setTimeout(() => {
855+
input.selectionStart = cursorPosition;
856+
input.selectionEnd = cursorPosition;
857+
}, 0);
858+
}
859+
849860
if (isUserInput) { // input
850861
this.fireEvent(this.EVENT_INPUT);
851862
// Angular two way data binding

0 commit comments

Comments
 (0)