Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bind:inputEl to textarea in TextField #531

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/svelte-ux/src/lib/components/TextField.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
? (node) => [autoFocus(node, typeof autofocus === 'object' ? autofocus : undefined)]
: undefined;
export let operators: { label: string; value: string }[] | undefined = undefined;
export let inputEl: HTMLInputElement | null = null;
export let inputEl: HTMLInputElement | HTMLTextAreaElement | null = null;
export let debounceChange: boolean | number = false;
export let classes: {
root?: string;
Expand Down Expand Up @@ -327,6 +327,7 @@
{disabled}
value={inputValue}
{autocapitalize}
bind:this={inputEl}
on:input={handleInput}
on:focus
on:blur
Expand Down Expand Up @@ -366,7 +367,7 @@
{max}
{step}
{actions}
bind:inputEl
bind:inputEl={null, (el) => (inputEl = el ?? null)}
Copy link
Author

Choose a reason for hiding this comment

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

this is using function bindings as defined here. The problem was that svelte thought we wanted to provide the value from TextField to Input, and since inputEl now may be a TextArea it was not happy with that since there's missing properties. This ensures that data flow is only one way out of the Input and into the TextField variable. I would have put a comment in code but there's not a good way to do that here.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks @hahn-kev. As of right now Svelte UX supports Svelte 3-5 (and will be for 1.x, but will be Svelte 5 only). I plan to release Svelte UX 1.0 VERY soon (maybe later this week) and have a PR that has started the migration to Svelte 5, but there is a lot of regression testing and refinements that need done.

With that said, we won't be able to use Svelte 5 function bindings yet (the docs are running Svelte 5 so it succeeds).

Here's my rough plan for Svelte UX 2.x (and others). Once we start the next branch I would love to include this, and plan to have incremental releases.

Copy link
Author

Choose a reason for hiding this comment

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

Ahh ok, I didn't realize that was a svelte 5 feature. I've changed this to do the same thing but an object to act as a wrapper which lets us define a setter without a getter.

Copy link
Owner

Choose a reason for hiding this comment

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

Nice technique! Care to run pnpm format to fix the prettier lint issue and I'll merge / release.

Copy link
Owner

Choose a reason for hiding this comment

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

Also, could you add an example or a way to validate the change. I don't have any component tests at the moment, just some unit tests and a lot of examples for visual/manual validation

Copy link
Author

Choose a reason for hiding this comment

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

fixed the lint issues. FYI maybe this is because I'm on windows, but when I ran format it modified 486 files, in addition to the TextField file. I only checked in that one. That might trip up others though, I think it might be a BOM issue, but it's hard to tell what the changes are.

Copy link
Author

@hahn-kev hahn-kev Jan 15, 2025

Choose a reason for hiding this comment

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

Alright there's now also an example (really like how that system was designed btw, really cool), here's a screenshot of it, I figured I should include a toggle between single and multi-line since that's what this PR was mainly for.
image

on:input={handleInput}
on:focus
on:blur
Expand Down
Loading