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
Copy file name to clipboardExpand all lines: documentation/docs/03-template-syntax/18-class.md
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,18 @@ The user of this component has the same flexibility to use a mixture of objects,
71
71
</Button>
72
72
```
73
73
74
+
Svelte also exposes the `ClassValue` type, which is the type of value that the `class` attribute on elements accept. This is useful if you want to use a type-safe class name in component props:
75
+
76
+
```svelte
77
+
<script lang="ts">
78
+
import type { ClassValue } from 'svelte/elements';
79
+
80
+
const props: { class: ClassValue } = $props();
81
+
</script>
82
+
83
+
<div class={['original', props.class]}>...</div>
84
+
```
85
+
74
86
## The `class:` directive
75
87
76
88
Prior to Svelte 5.16, the `class:` directive was the most convenient way to set classes on elements conditionally.
0 commit comments