hperrin / svelte-material-ui

Svelte Material UI Components
https://sveltematerialui.com/
Apache License 2.0
3.3k stars 286 forks source link

Cursor in Textfield jumps to end of text when editing on Safari #144

Open natesilva opened 4 years ago

natesilva commented 4 years ago

Hi! This is an error report for the Textfield when used on Safari (iOS or macOS).

This can be demo’ed with the Textfield inputs on https://sveltematerialui.com/demo/textfield/.

To reproduce:

  1. In Safari, type some text into a <Textfield>.
  2. Move your insertion point back to the middle of the text you just typed.
  3. Make a change, such as typing or deleting a character.

Expected results:

Actual results:

phelbas commented 4 years ago

The first answer may help ? https://stackoverflow.com/questions/46000544/react-controlled-input-cursor-jumps

volksvargas commented 3 years ago

change your @smui/textfield/Input.svelte file so that the valueUpdater function looks like this:

function valueUpdater(e) {

const start = e.target.selectionStart;
const end = e.target.selectionEnd;

switch (type) {
  case 'number':
  case 'range':
    value = toNumber(e.target.value);
    break;
  case 'file':
    files = e.target.files;
  // Fall through.
  default:
    value = e.target.value;
    break;
}

requestAnimationFrame(() => {
  e.target.selectionStart = start;
  e.target.selectionEnd = end;
});

}

hperrin commented 2 years ago

Is this regarding desktop Safari?