classList
caution
className was deprecated in Solid 1.4 in favor of class.
classList toggles element classes from an object of class names and boolean values.
Syntax
<div classList={{ active: state.active }} />Value
- Type:
Record<string, boolean | undefined>
Object whose keys are class names and whose values control whether each class is present.
Behavior
- Each key is treated as a class name.
- Keys can contain multiple space-separated class names, which are toggled individually.
- Truthy values add the class and falsy values remove it.
- Updates are applied per class rather than replacing the whole
classattribute. classListworks through normal DOM prop assignment, including prop spreads and<Dynamic>when it renders an intrinsic element.- If both
classandclassListare reactive, updates toclasscan overwrite classes managed byclassList. - SSR output merges
class,className, andclassListinto the emittedclassattribute.
Examples
Basic usage
<div classList={{ active: state.active, editing: state.currentId === row.id, }}/>Dynamic class name
<div classList={{ [className()]: classOn() }} />