You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -323,6 +340,7 @@ Without an argument, `use:enhance` will emulate the browser-native behaviour, ju
323
340
- reset the `<form>` element and invalidate all data using `invalidateAll` on a successful response
324
341
- call `goto` on a redirect response
325
342
- render the nearest `+error` boundary if an error occurs
343
+
-[reset focus](/docs/accessibility#focus-management) to the appropriate element
326
344
327
345
To customise the behaviour, you can provide a `SubmitFunction` that runs immediately before the form is submitted, and (optionally) returns a callback that runs with the `ActionResult`. Note that if you return a callback, the default behavior mentioned above is not triggered. To get it back, call `update`.
328
346
@@ -381,6 +399,8 @@ The behaviour of `applyAction(result)` depends on `result.type`:
381
399
-`redirect` — calls `goto(result.location)`
382
400
-`error` — renders the nearest `+error` boundary with `result.error`
383
401
402
+
In all cases, [focus will be reset](/docs/accessibility#focus-management).
403
+
384
404
### Custom event listener
385
405
386
406
We can also implement progressive enhancement ourselves, without `use:enhance`, with a normal event listener on the `<form>`:
@@ -448,7 +468,10 @@ Some forms don't need to `POST` data to the server — search inputs, for exampl
Copy file name to clipboardExpand all lines: documentation/docs/40-best-practices/10-accessibility.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,9 @@ This will allow screen readers and other assistive technology to identify the ne
29
29
30
30
In traditional server-rendered applications, every navigation will reset focus to the top of the page. This ensures that people browsing the web with a keyboard or screen reader will start interacting with the page from the beginning.
31
31
32
-
To simulate this behavior during client-side routing, SvelteKit focuses the `<body>` element after each navigation. If you want to customize this behavior, you can implement custom focus management logic using the `afterNavigate` hook:
32
+
To simulate this behavior during client-side routing, SvelteKit focuses the `<body>` element after each navigation and [enhanced form submission](https://kit.svelte.dev/docs/form-actions#progressive-enhancement). There is one exception - if an element with the [`autofocus`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) attribute is present, SvelteKit will focus that element instead. Make sure to [consider the implications for assistive technology](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus#accessibility_considerations) when using that attribute.
33
+
34
+
If you want to customize SvelteKit's focus management, you can use the `afterNavigate` hook:
0 commit comments