solar-forms icon indicating copy to clipboard operation
solar-forms copied to clipboard

Deselection of text input inside <Show>

Open Kazumasan opened this issue 2 years ago • 4 comments

Hey, so pretty simple issue if you have a form like this

<Show when={true}>
    <form use:formGroup={fg}>
        <input type="text" formControlName="email" /> 
     </form>
</Show>

Essentially, the input field gets deselected every time you input a character. Here is a repo with an example.

A quick discussion on the Solid-js Discord found that the issue is with solid-js@>1.4.7 in the playground, the Repo uses [email protected] Breaks Works

Maybe you can shed some light on it ?

Kazumasan avatar Jul 19 '22 23:07 Kazumasan

Thanks for reporting this and for repros 🚀

I cannot pinpoint from the top of my head what exactly is the issue here...

Also found out, that if you wrap individual form controls in <Show>, the binding does not work 😅

I'll take a look at both cases.

kajetansw avatar Jul 20 '22 06:07 kajetansw

Hey, I tinkered a bit with it and found that if you wrap the form into a component it works inside Show I added a branch with the example to my repo.

Kazumasan avatar Jul 20 '22 11:07 Kazumasan

This issue comes from unintentional subscription to a signal like the one at https://github.com/kajetansw/solar-forms/blob/master/src/core/form-group-directive/form-group-directive.tsx#L31 There are other places with the same code. It might solve this issue if these are untrack-ed. It is also a good practice to wrap with untrack explicitly especially when writing actions. You never know when users are gonna call your functions.

I also wonder if this is on Show. I'll see what I can do in solid discord.

mdynnl avatar Jul 20 '22 15:07 mdynnl

I appreciate the engagement and suggesting solutions! ❤️

I did what @mdynnl suggested and seems to be working! I untracked dangling subscriptions in form-group-directive.tsx and wrapping form in Show seems to be working (see preview below). Thanks!

Also, I managed to fix a case of wrapping individual form controls in <Show> that I described previously. The solution was suggested by The Man himself in one of Solid's issues.

I'll publish the new version when I'll wrap it up.

https://user-images.githubusercontent.com/33182225/180031854-85f8cb93-e18f-4991-bd92-21d74403670d.mov

kajetansw avatar Jul 20 '22 16:07 kajetansw