-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: make defaultValue work with spread
#14640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -347,19 +347,19 @@ export function set_attributes( | |
| } else if (key === '__value' || (key === 'value' && value != null)) { | ||
| // @ts-ignore | ||
| element.value = element[key] = element.__value = value; | ||
| } else if (key === 'defaultValue') { | ||
| /** @type {HTMLInputElement} */ (element).defaultValue = value; | ||
| } else if (key === 'defaultChecked') { | ||
| /** @type {HTMLInputElement} */ (element).defaultChecked = value; | ||
| } else if (key === 'selected' && is_option_element) { | ||
| set_selected(/** @type {HTMLOptionElement} */ (element), value); | ||
| } else { | ||
| var name = key; | ||
| if (!preserve_attribute_case) { | ||
| name = normalize_attribute(name); | ||
| } | ||
| if (value == null && !is_custom_element) { | ||
| let is_default_value_or_checked = name === 'defaultValue' || name === 'defaultChecked'; | ||
|
|
||
| if (value == null && !is_custom_element && !is_default_value_or_checked) { | ||
| attributes[key] = null; | ||
| // if we remove the value/checked attributes this also for some reasons reset | ||
| // the default value so we need to keep track of it and reassign it after the remove | ||
| let default_value_reset = /**@type {HTMLInputElement}*/ (element).defaultValue; | ||
| let default_checked_reset = /**@type {HTMLInputElement}*/ (element).defaultChecked; | ||
| element.removeAttribute(key); | ||
|
|
@@ -368,7 +368,10 @@ export function set_attributes( | |
| } else if (key === 'checked') { | ||
| /**@type {HTMLInputElement}*/ (element).defaultChecked = default_checked_reset; | ||
| } | ||
| } else if (setters.includes(name) && (is_custom_element || typeof value !== 'string')) { | ||
| } else if ( | ||
| is_default_value_or_checked || | ||
|
||
| (setters.includes(name) && (is_custom_element || typeof value !== 'string')) | ||
| ) { | ||
| // @ts-ignore | ||
| element[name] = value; | ||
| } else if (typeof value !== 'function') { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, yeah that's why - now I'm wondering if we should model this differently: Check if the dom element is an input or textarea, and if so, if we come across a
valueorcheckedattribute, skip to the setters. Not sure which solution ends up being less code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need to remove the attribute, we just need to make sure to restore the default value