Skip to content

fix(ui5-input): fix inpur cursor movement in Safari #1983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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