Closed giovannipiller closed 6 years ago
Created an issue in WebKit Bugzilla: https://bugs.webkit.org/show_bug.cgi?id=191255
Just in case somebody needs a workaround, you can store caret position and restore after the set(...)
. Something like this:
// store caret position
const originalCaretPosition = event.target.selectionStart;
this.set({ who });
// restores caret position
event.target.setSelectionRange(originalCaretPosition, originalCaretPosition);
I think the check on this.node.value !== safeValue
is good. Since you've already solved it would you like to do a PR for credit? If not, no worries, I'll get it in a bit. There's probably not a good way to write a test for this, since the CI is all chrome-based and I don't have access to Safari for manual testing, so a new test case isn't even necessary.
Description:
Title might need some improvement I know. Anyway, I noticed this issue that is Safari specific, but might be interesting to work-around internally.
Steps:
<input type="text" twoway="false" value="{{who}}">
this.set({ who });
when appropriateResult: As soon as you type the first key, the caret will be moved at the end of the input. See attached GIF:
Versions affected:
1.0.1, likely prior as well
Platforms affected:
Reproduced on Safari 12, 11
Reproduction:
JSFiddle here.
Fix (aka workaround):
Looks like Safari moves caret position whenever the value of the focused input is changed, as long as this change is not directly performed by a user action (ex. normal user typing). Which is why
twoway="true"
would work just fine.Example:
input.value = input.value;
moves the caret at the end in Safari. Not in Chrome/Firefox.By setting the value after the input phase, Ractive will rightfully attempt to update input's value during one of its
update
calls, using theupdateStringValue(..)
function.An internal workaround might be to check if
input.value
need to be updated at all. For example, by changing updateStringValue to something like this:TODO
I still have to check WebKit's Bugzilla for this behaviour. In the meantime I'm opening this issue to start the discussion.WebKit issue: https://bugs.webkit.org/show_bug.cgi?id=191255TL;DR
input.value = input.value;
moves the caret at the end of the input in Safari. Not in Chrome/Firefox. Might be worth to add a workaround for edge cases.