huntabyte / vaul-svelte

An unstyled drawer component for Svelte.
https://vaul-svelte.com
MIT License
465 stars 19 forks source link

'openFocus' property does not work #62

Open snrmwg opened 8 months ago

snrmwg commented 8 months ago

Describe the bug

When opening a drawer containing form elements (i.e. textarea) I would like to focus a specific element. Tried to use the openFocus for that reason. But focus is not set. Compared to bits-ui Dialog where all works like expected. I put both usecases in the Stackblitz.

Reproduction

https://stackblitz.com/edit/vitejs-vite-q4c9mb?file=src%2FApp.svelte

Logs

No response

System Info

envinfo@7.11.1
   System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm
  npmPackages:
    bits-ui: 0.18.6 => 0.18.6 
    svelte: ^4.2.12 => 4.2.12 
    typescript: ^5.2.2 => 5.3.3 
    vaul-svelte: 0.2.4 => 0.2.4

Severity

annoyance

DarthGigi commented 6 months ago

+1 having the same issue

jramke commented 5 months ago

Got the same issue. Some workarounds i found was to manually focus another element 300ms after you opened the drawer or (the one im using now) just place an focusable element inside the content and around your inputs.

<Drawer.Root bind:open={$editDialogOpen} onOpenChange={editDialogChange}>
  <Drawer.Content>
      <!-- svelte-ignore a11y-no-noninteractive-tabindex -->
      <div tabindex="0">
          <Drawer.Header>
              <Drawer.Title>Detail view</Drawer.Title>
          </Drawer.Header>
          ... more content where we got some inputs
      </div>
  </Drawer.Content>
</Drawer.Root>