Skip to content

controlled text field never updates if first controlled values is undefined #627

@jcmonnin

Description

@jcmonnin

When having controlled TextField, it never updates if the value at construction time is undefined. I would expect that the controlled value is allowed to be initially undefined and update the text field content when it becomes a string. Both pairs of text fields in following example should be kept in sync:

https://stackblitz.com/edit/solidjs-templates-yxfy22g2

This regression was introduced in #9ccdc68.

	// Disable reactivity to only track controllability on first run
	// Our current implementation breaks with undefined (stops tracking controlled value)
	const initialValue = local.value;

	const [value, setValue] = createControllableSignal({
		value: () => (initialValue === undefined ? undefined : local.value ?? ""),
		defaultValue: () => local.defaultValue,
		onChange: (value) => local.onChange?.(value),
	});

It's not clear to me what this commit fixes, therefore not proposing a PR reverting it.

Would this work?

		value: () => local.value ?? "",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions