Skip to content

Commit

Permalink
Fix some selection-related issues in input and textarea
Browse files Browse the repository at this point in the history
When setting the value of a text input, the selection is now set to the end of the new text. This also fixes textarea's initial section selection start/end to be 0.

Fixes #2787.
  • Loading branch information
Matthew-Goldberg authored and domenic committed Jan 25, 2020
1 parent 6928d6d commit 27b7074
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 38 deletions.
3 changes: 1 addition & 2 deletions lib/jsdom/living/nodes/HTMLInputElement-impl.js
Expand Up @@ -404,8 +404,7 @@ class HTMLInputElementImpl extends HTMLElementImpl {
this._dirtyValue = true;

if (oldValue !== this._value) {
this._selectionStart = 0;
this._selectionEnd = 0;
this._selectionStart = this._selectionEnd = this._getValueLength();
this._selectionDirection = "none";
}
break;
Expand Down
11 changes: 8 additions & 3 deletions lib/jsdom/living/nodes/HTMLTextAreaElement-impl.js
Expand Up @@ -17,6 +17,8 @@ class HTMLTextAreaElementImpl extends HTMLElementImpl {
constructor(globalObject, args, privateData) {
super(globalObject, args, privateData);

this._selectionStart = this._selectionEnd = 0;
this._selectionDirection = "none";
this._rawValue = "";
this._dirtyValue = false;

Expand Down Expand Up @@ -69,12 +71,15 @@ class HTMLTextAreaElementImpl extends HTMLElementImpl {
}

set value(val) {
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-textarea-value
const oldAPIValue = this._getAPIValue();
this._rawValue = val;
this._dirtyValue = true;

this._selectionStart = 0;
this._selectionEnd = 0;
this._selectionDirection = "none";
if (oldAPIValue !== this._getAPIValue()) {
this._selectionStart = this._selectionEnd = this._getValueLength();
this._selectionDirection = "none";
}
}

get textLength() {
Expand Down
10 changes: 10 additions & 0 deletions test/web-platform-tests/to-run.yaml
Expand Up @@ -574,6 +574,16 @@ DIR: html/semantics/forms/resetting-a-form

---

DIR: html/semantics/forms/textfieldselection

select-event.html: [fail, not yet implemented]
selection-not-application-textarea.html: [fail, not yet implemented]
selection-start-end-extra.html: [fail, not yet implemented. Shortening value by turning input type into url - fix would cause the-input-element type-change-state.html to fail.]
textfieldselection-setRangeText.html: [fail, not yet implemented]
textfieldselection-setSelectionRange.html: [fail, not yet implemented]

---

DIR: html/semantics/forms/the-button-element

button-activate.html: [fail, iframe onload needs to run after synchronous script]
Expand Down

This file was deleted.

0 comments on commit 27b7074

Please sign in to comment.