This repository has been archived by the owner on Apr 4, 2019. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
People are using bound
<input>
s. For the most part everything works great.But not everything is rainbows and butterflies. Text inputs have an annoying
wart. Whenever you update their
value
, the cursor is moved to the end of theinput. This becomes a problem when you are trying to edit text in the middle of
a text input. Curiously, this issue doesn't affect
<textarea>
(confirmed onFirefox/Chrome/Safari).
Here's an ember-twiddle that show cases the
current state of affairs.
Why does this happen?
A little background first. When you edit a text input through the browser GUI the
oninput
event is triggered. When you change the input element's
value
property, theoninput
event is not fired, but the cursor is set to the end of the text field.
Now let's say you write
and
If you edit the text input the browser will internally update the
value
property on theinput element and then fire the
oninput
event. Our handler mutates the value ofuser.name
.This triggers the
value={{user.name}}
binding to update, or in other words callsProposed fix
In order to fix this we can avoid setting .value when we don't need to. This will skirt the issue
of resetting the cursor when
value
is mutated. Specifically, we add a guard toPropertyAttrMorph
so that we avoid calling
input.value = newValue
if the follow conditions are met:this.attrName === 'value'
this.element.tagName === 'INPUT'
this.element.value == newValue
Here is an ember-twiddle with the patch applied.
Note how editing the Name text input works correctly now. Even dead keys work just fine! (Try
entering
Option-e + e
in the text input. It should generate a "é" character.)Trade-offs
Making this change has a small trade off. It alters DOM semantics so that, when the conditions
above are met, we treat the mutation as a no-op rather than a set-the-value-to-what-it-already-was.
We believe that this is a very small price to pay for a massive improvement in developer ergonomics.