Skip to content

TextField autofocus breaks when defining actions #532

@hahn-kev

Description

@hahn-kev

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)
  ]}
/>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions