Thomas G. Lopes commited on
Commit
7f214aa
·
1 Parent(s): 936176c

fix autofocus

Browse files
src/lib/actions/autofocus.ts ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ export function autofocus(node: HTMLElement) {
2
+ node.focus();
3
+ }
src/lib/components/prompts.svelte CHANGED
@@ -2,6 +2,7 @@
2
  import { clickOutside } from "$lib/actions/click-outside.js";
3
  import { writable } from "svelte/store";
4
  import IconCross from "~icons/carbon/close";
 
5
 
6
  type Prompt = {
7
  label: string;
@@ -27,7 +28,7 @@
27
  </script>
28
 
29
  <script lang="ts">
30
- import { run } from 'svelte/legacy';
31
 
32
  let current = $derived($prompts?.[0]);
33
 
@@ -73,13 +74,11 @@
73
  <!-- Modal body -->
74
  <div class="p-4 md:p-5">
75
  <label class="flex flex-col gap-2 font-medium text-gray-900 dark:text-white">
76
- <!-- This is fine in dialogs -->
77
- <!-- svelte-ignore a11y_autofocus -->
78
  <input
79
  bind:value={current.value}
80
  placeholder={current.placeholder}
81
- autofocus
82
  required
 
83
  type="text"
84
  class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
85
  />
 
2
  import { clickOutside } from "$lib/actions/click-outside.js";
3
  import { writable } from "svelte/store";
4
  import IconCross from "~icons/carbon/close";
5
+ import { autofocus } from "$lib/actions/autofocus.js";
6
 
7
  type Prompt = {
8
  label: string;
 
28
  </script>
29
 
30
  <script lang="ts">
31
+ import { run } from "svelte/legacy";
32
 
33
  let current = $derived($prompts?.[0]);
34
 
 
74
  <!-- Modal body -->
75
  <div class="p-4 md:p-5">
76
  <label class="flex flex-col gap-2 font-medium text-gray-900 dark:text-white">
 
 
77
  <input
78
  bind:value={current.value}
79
  placeholder={current.placeholder}
 
80
  required
81
+ use:autofocus
82
  type="text"
83
  class="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
84
  />