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

TextField autofocus breaks when defining actions #532

Open
hahn-kev opened this issue Jan 14, 2025 · 1 comment
Open

TextField autofocus breaks when defining actions #532

hahn-kev opened this issue Jan 14, 2025 · 1 comment

Comments

@hahn-kev
Copy link
Contributor

This example from the docs which defines an action, does not autofocus when you add the autofocus attribute

<TextField
  label="Name"
  autofocus
  actions={(node) => [
    debounceEvent(node, {
      type: "input",
      listener: (e) => {
        // @ts-expect-error
        console.log(e.target.value);
      },
      timeout: 500,
    }),
  ]}
/>

but if you remove the action then it starts working

<TextField
  label="Name"
  autofocus
/>

I wouldn't expect those 2 things to effect each other.

as a workaround this should work:

<script>
  import { autoFocus } from 'svelte-ux';
</script>
<TextField
  label="Name"
  actions={(node) => [
    debounceEvent(node, {
      type: "input",
      listener: (e) => {
        // @ts-expect-error
        console.log(e.target.value);
      },
      timeout: 500,
    }),
    autoFocus(node)
  ]}
/>
@hahn-kev hahn-kev changed the title TextEditor autofocus breaks when defining actions TextField autofocus breaks when defining actions Jan 14, 2025
@techniq
Copy link
Owner

techniq commented Jan 14, 2025

Thanks for the issue @hahn-kev. At the moment autoFocus is just a convenience to add the autoFocus action as the initial actions value (save an import and less boilerplate) since it's a common use case. We could possibly initialize actions as an empty array and then add autoFocus in onMount or similar, but would need some exploration.

I'm also keeping an eye on the new attachments PR proposal as a replacement for actions with better compatibility (and other improvements).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants