kobaltedev / kobalte

A UI toolkit for building accessible web apps and design systems with SolidJS.
https://kobalte.dev
MIT License
1.23k stars 63 forks source link

bug: TextField.TextArea's size does not update when value is set externally #484

Open andrerocco opened 1 week ago

andrerocco commented 1 week ago

Describe the bug

The TextField.TextArea component is not triggering a resize when the text signal changes by its setter. This means that when the content of the textarea is updated programmatically, the component doesn't automatically adjust its height as expected.

To Reproduce

Steps to reproduce the behavior:

  1. Create a TextField.TextArea component with the autoResize prop set to true.
  2. Set up a signal to control the textarea's content (using the value prop).
  3. Update the signal's value programmatically (e.g., through a button click or effect).
  4. Observe that the textarea's height does not adjust to fit the new content.

Demo: https://stackblitz.com/edit/github-b14x5v-a9ch1g?file=src%2FApp.tsx

Expected behavior

When the content of the TextFieldTextArea is updated either through user input or programmatically via a signal, the component should automatically resize to fit the new content if the autoResize prop is set to true.

Screenshots

https://github.com/user-attachments/assets/af6e13e1-6609-4538-b174-e9f79923ee0a

Desktop:

Additional context

Listening to the value prop passed to TextFieldTextArea will fix the problem. In the means of:

createEffect(
    on(
        [() => ref, () => local.autoResize, () => context.value(), () => others.value],
        ([ref, autoResize]) => {
            if (!ref || !autoResize) {
                return;
            }

            adjustHeight(ref);
        },
    ),
);