Skip to content

Commit

Permalink
Refactor <output>
Browse files Browse the repository at this point in the history
This matches the latest spec which uses a unified "default value override" concept. It does not change behavior.
  • Loading branch information
domenic committed Mar 28, 2021
1 parent b36d418 commit 761d8cc
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/jsdom/living/nodes/HTMLOutputElement-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class HTMLOutputElementImpl extends HTMLElementImpl {
constructor(globalObject, args, privateData) {
super(globalObject, args, privateData);
this._labels = null;
this._defaultValue = "";
this._valueMode = "default";
this._defaultValueOverride = null;

this._customValidityErrorMessage = "";
}
Expand All @@ -30,12 +29,8 @@ class HTMLOutputElementImpl extends HTMLElementImpl {
}

_formReset() {
if (this._valueMode === "value") {
this.textContent = this._defaultValue;
}

this._defaultValue = "";
this._valueMode = "default";
this.textContent = this.defaultValue;
this._defaultValueOverride = null;
}

get htmlFor() {
Expand Down Expand Up @@ -65,21 +60,24 @@ class HTMLOutputElementImpl extends HTMLElementImpl {
}

set value(val) {
this._valueMode = "value";
this._defaultValue = this.textContent;
this._defaultValueOverride = this.defaultValue;
this.textContent = val;
}

get defaultValue() {
return this._valueMode === "default" ? this.textContent : this._defaultValue;
if (this._defaultValueOverride !== null) {
return this._defaultValueOverride;
}
return this.textContent;
}

set defaultValue(val) {
this._defaultValue = val;

if (this._valueMode === "default") {
if (this._defaultValueOverride === null) {
this.textContent = val;
return;
}

this._defaultValueOverride = val;
}
}

Expand Down

0 comments on commit 761d8cc

Please sign in to comment.