Skip to content

Commit b883f30

Browse files
Docs/iAPI: Recommend kebab-case in data-wp-class (#62817)
* Recommend kebab-case in wp-class and remove outdated info about callback args * Trigger actions again Co-authored-by: luisherranz <[email protected]> Co-authored-by: cbravobernal <[email protected]>
1 parent fe67010 commit b883f30

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

docs/reference-guides/interactivity-api/api-reference.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,36 @@ The `wp-class` directive is executed:
220220
- When the element is created
221221
- Each time there's a change on any of the properties of the `state` or `context` involved in getting the final value of the directive (inside the callback or the expression passed as reference)
222222

223-
When `wp-class` directive references a callback to get its final boolean value, the callback receives the class name: `className`.
224-
225223
The boolean value received by the directive is used to toggle (add when `true` or remove when `false`) the associated class name from the `class` attribute.
226224

225+
It's important to note that when using the `wp-class` directive, it's recommended to use kebab-case for class names instead of camelCase. This is because HTML attributes are not case-sensitive, and HTML will treat `data-wp-class--isDark` the same as `data-wp-class--isdark` or `DATA-WP-CLASS--ISDARK`.
226+
227+
So, for example, use the class name `is-dark` instead of `isDark` and `data-wp-class--is-dark` instead of `data-wp-class--isDark`:
228+
229+
```html
230+
<!-- Recommended -->
231+
<div data-wp-class--is-dark="context.isDarkMode">
232+
<!-- ... -->
233+
</div>
234+
235+
<!-- Not recommended -->
236+
<div data-wp-class--isDark="context.isDarkMode">
237+
<!-- ... -->
238+
</div>
239+
```
240+
241+
```css
242+
/* Recommended */
243+
.is-dark {
244+
/* ... */
245+
}
246+
247+
/* Not recommended */
248+
.isDark {
249+
/* ... */
250+
}
251+
```
252+
227253
### `wp-style`
228254

229255
This directive adds or removes inline style to an HTML element, depending on its value. It follows the syntax `data-wp-style--css-property`.
@@ -256,8 +282,6 @@ The `wp-style` directive is executed:
256282
- When the element is created
257283
- Each time there's a change on any of the properties of the `state` or `context` involved in getting the final value of the directive (inside the callback or the expression passed as reference)
258284

259-
When `wp-style` directive references a callback to get its final value, the callback receives the class style property: `css-property`.
260-
261285
The value received by the directive is used to add or remove the style attribute with the associated CSS property:
262286

263287
- If the value is `false`, the style attribute is removed: `<div>`

0 commit comments

Comments
 (0)