Skip to content

Commit

Permalink
fix(ui5-input): fix inpur cursor movement in Safari (#1983)
Browse files Browse the repository at this point in the history
  • Loading branch information
fifoosid authored Jul 27, 2020
1 parent 3b614ad commit 7a9e9a3
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/main/src/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
import RenderScheduler from "@ui5/webcomponents-base/dist/RenderScheduler.js";
import { isIE, isPhone } from "@ui5/webcomponents-base/dist/Device.js";
import { isIE, isPhone, isSafari } from "@ui5/webcomponents-base/dist/Device.js";
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
import {
Expand Down Expand Up @@ -843,9 +843,20 @@ class Input extends UI5Element {
const isSubmit = action === this.ACTION_ENTER;
const isUserInput = action === this.ACTION_USER_INPUT;

const input = await this.getInputDOMRef();
const cursorPosition = input.selectionStart;

this.value = inputValue;
this.highlightValue = inputValue;

if (isSafari()) {
// When setting the value by hand, Safari moves the cursor when typing in the middle of the text (See #1761)
setTimeout(() => {
input.selectionStart = cursorPosition;
input.selectionEnd = cursorPosition;
}, 0);
}

if (isUserInput) { // input
this.fireEvent(this.EVENT_INPUT);
// Angular two way data binding
Expand Down

0 comments on commit 7a9e9a3

Please sign in to comment.