Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Conversation

zhang740
Copy link

No description provided.

src/index.js Outdated

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.