diff --git a/lib/jsdom/living/nodes/HTMLInputElement-impl.js b/lib/jsdom/living/nodes/HTMLInputElement-impl.js index da71d4a375..e868dc6dd6 100644 --- a/lib/jsdom/living/nodes/HTMLInputElement-impl.js +++ b/lib/jsdom/living/nodes/HTMLInputElement-impl.js @@ -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; diff --git a/lib/jsdom/living/nodes/HTMLTextAreaElement-impl.js b/lib/jsdom/living/nodes/HTMLTextAreaElement-impl.js index 3170c8935e..7202e864ca 100644 --- a/lib/jsdom/living/nodes/HTMLTextAreaElement-impl.js +++ b/lib/jsdom/living/nodes/HTMLTextAreaElement-impl.js @@ -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; @@ -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() { diff --git a/test/web-platform-tests/to-run.yaml b/test/web-platform-tests/to-run.yaml index 79c629ca63..952ffec205 100644 --- a/test/web-platform-tests/to-run.yaml +++ b/test/web-platform-tests/to-run.yaml @@ -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] diff --git a/test/web-platform-tests/to-upstream/html/semantics/forms/the-textarea-element/set-value-reset-selection.html b/test/web-platform-tests/to-upstream/html/semantics/forms/the-textarea-element/set-value-reset-selection.html deleted file mode 100644 index fd70cb8eb8..0000000000 --- a/test/web-platform-tests/to-upstream/html/semantics/forms/the-textarea-element/set-value-reset-selection.html +++ /dev/null @@ -1,33 +0,0 @@ - -textarea element setting value property should reset text selection - - - - -
-