Skip to content

Commit b7db21a

Browse files
authored
Update classlist.mdx
improve styling and fix some sentences
1 parent 6f46659 commit b7db21a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/routes/reference/jsx-attributes/classlist.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ title: classList
33
order: 1
44
---
55

6-
Solid offers two ways to set the class of an element: class and classList attributes.
6+
Solid offers two ways to set the class of an element: `class` and `classList` attributes.
77

8-
First, you can set class=... like any other attribute. For example:
8+
First, you can set `class` like any other attribute. For example:
99

1010
```tsx
1111
// Two static classes
@@ -27,7 +27,10 @@ Alternatively, the `classList` pseudo-attribute lets you specify an object, wher
2727

2828
```tsx
2929
<div
30-
classList={{ active: state.active, editing: state.currentId === row.id }}
30+
classList={{
31+
active: state.active,
32+
editing: state.currentId === row.id,
33+
}}
3134
/>
3235
```
3336

@@ -45,6 +48,6 @@ setClasses((c) => ({ ...c, active: true }))
4548
<div classList={classes()} />
4649
```
4750

48-
It's also possible, but dangerous, to mix class and classList. The main safe situation is when class is set to a static string (or nothing), and classList is reactive. (class could also be set to a static computed value as in `class={baseClass()}`, but then it should appear before any classList pseudo-attributes.) If both class and classList are reactive, you can get unexpected behavior: when the class value changes, Solid sets the entire class attribute, so will overwrite any toggles made by classList.
51+
It's also possible, but dangerous, to mix `class` and `classList`. The main safe situation is when `class` is set to a static string (or nothing), and `classList` is reactive (`class` could also be set to a static computed value as in `class={baseClass()}`, but then it should appear before any classList pseudo-attributes). If both `class` and `classList` are reactive, you can get unexpected behavior: when the class value changes, Solid sets the entire class attribute, so will overwrite any toggles made by classList.
4952

5053
Because classList is a compile-time pseudo-attribute, it does not work in a prop spread like `<div {...props} />` or in `<Dynamic>`.

0 commit comments

Comments
 (0)