Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Fix: when 'value' is an empty and has 'defaultValue', 'value' will be replace. #450

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhang740
Copy link

No description provided.

src/index.js Outdated
@@ -90,7 +90,7 @@ options.vnode = vnode => {
if (vnode.children) attrs.children = vnode.children;

if (attrs.defaultValue) {
if (!attrs.value && attrs.value!==0) {
if (!attrs.value && attrs.value!==0 && attrs.value!=='') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we used this check instead of all three?

if (attrs.value==null) {
  attrs.value = attrs.defaultValue;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, only undefined should be ignored.

if (attrs.defaultValue) {
	if (attrs.value === undefined) {
		attrs.value = attrs.defaultValue;
	}
	delete attrs.defaultValue;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, in check will be most strictly, but, preact-compat will merge defaultValue to value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is React's behavior here? They usually differentiate between null and undefined, but I haven't tested this specific behavior. We should just use whatever they use to avoid an inconsistency.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also ran into problems with the preact-compat implementation of defaultValue.

In React, the defaultValue prop will not set the value prop on an element in general. In my observations, the value prop remains undefined. Changing the defaultValue prop does not cause any further changes/renders on the component.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The described behavior applies to the case of a select.

@developit developit added this to To Do in Backlog via automation Feb 23, 2018
@developit developit moved this from To Do to In progress in Backlog Feb 23, 2018
@developit developit added this to the 3.19 milestone Feb 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Backlog
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants