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
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]>
Copy file name to clipboardExpand all lines: docs/reference-guides/interactivity-api/api-reference.md
+28-4Lines changed: 28 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -220,10 +220,36 @@ The `wp-class` directive is executed:
220
220
- When the element is created
221
221
- 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)
222
222
223
-
When `wp-class` directive references a callback to get its final boolean value, the callback receives the class name: `className`.
224
-
225
223
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.
226
224
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
+
<divdata-wp-class--is-dark="context.isDarkMode">
232
+
<!-- ... -->
233
+
</div>
234
+
235
+
<!-- Not recommended -->
236
+
<divdata-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
+
227
253
### `wp-style`
228
254
229
255
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:
256
282
- When the element is created
257
283
- 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)
258
284
259
-
When `wp-style` directive references a callback to get its final value, the callback receives the class style property: `css-property`.
260
-
261
285
The value received by the directive is used to add or remove the style attribute with the associated CSS property:
262
286
263
287
- If the value is `false`, the style attribute is removed: `<div>`
0 commit comments