Skip to content

Commit a306102

Browse files
committed
sync again
1 parent c052ae2 commit a306102

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

apps/svelte.dev/content/docs/kit/40-best-practices/10-accessibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ This will allow screen readers and other assistive technology to identify the ne
2929

3030
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.
3131

32-
To simulate this behavior during client-side routing, SvelteKit focuses the `<body>` element after each navigation and [enhanced form submission](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.
32+
To simulate this behavior during client-side routing, SvelteKit focuses the `<body>` element after each navigation and [enhanced form submission](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.
3333

3434
If you want to customize SvelteKit's focus management, you can use the `afterNavigate` hook:
3535

apps/svelte.dev/content/docs/svelte/07-misc/03-typescript.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ Components can declare a generic relationship between their properties. One exam
130130

131131
The content of `generics` is what you would put between the `<...>` tags of a generic function. In other words, you can use multiple generics, `extends` and fallback types.
132132

133+
## Typing wrapper components
134+
135+
In case you're writing a component that wraps a native element, you may want to expose all the attributes of underlying element to the user. In that case, use (or extend from) one of the interfaces provided by `svelte/elements`. Here's an example for a `Button` component:
136+
137+
```svelte
138+
<script lang="ts">
139+
import type { HTMLButtonAttributes } from 'svelte/elements';
140+
141+
let { children, ...rest }: HTMLButtonAttributes = $props();
142+
</script>
143+
144+
<button {...rest}>
145+
{@render children()}
146+
</button>
147+
```
148+
133149
## Typing `$state`
134150

135151
You can type `$state` like any other variable.
@@ -159,9 +175,9 @@ class Counter {
159175

160176
## The `Component` type
161177

162-
Svelte components or of type `Component`. You can use it and its related types to express a variety of constraints.
178+
Svelte components are of type `Component`. You can use it and its related types to express a variety of constraints.
163179

164-
Using it together with `<svelte:component>` to restrict what kinds of component can be passed to it:
180+
Using it together with dynamic components to restrict what kinds of component can be passed to it:
165181

166182
```svelte
167183
<script lang="ts">
@@ -170,13 +186,13 @@ Using it together with `<svelte:component>` to restrict what kinds of component
170186
interface Props {
171187
// only components that have at most the "prop"
172188
// property required can be passed
173-
component: Component<{ prop: string }>;
189+
DynamicComponent: Component<{ prop: string }>;
174190
}
175191
176-
let { component }: Props = $props();
192+
let { DynamicComponent }: Props = $props();
177193
</script>
178194
179-
<svelte:component this={component} prop="foo" />
195+
<DynamicComponent prop="foo" />
180196
```
181197

182198
Closely related to the `Component` type is the `ComponentProps` type which extracts the properties a component expects.

apps/svelte.dev/content/docs/svelte/98-reference/20-svelte.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,11 @@ import type { ComponentProps } from 'svelte';
581581
import MyComponent from './MyComponent.svelte';
582582

583583
// Errors if these aren't the correct props expected by MyComponent.
584-
const props: ComponentProps<MyComponent> = { foo: 'bar' };
584+
const props: ComponentProps<typeof MyComponent> = { foo: 'bar' };
585585
```
586586

587+
> [!NOTE] In Svelte 4, you would do `ComponentProps<MyComponent>` because `MyComponent` was a class.
588+
587589
Example: A generic function that accepts some component and infers the type of its props:
588590

589591
```ts

0 commit comments

Comments
 (0)