Skip to content

Commit e6744ea

Browse files
Add documentation for aria and data props with underscore notation and custom_attrs (#1342)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Alek Petuskey <[email protected]>
1 parent 82451a7 commit e6744ea

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

docs/components/props.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ rx.box(
3838

3939
In the example above, the `class_name` prop of the `rx.box` component is assigned a list of class names. This means the `rx.box` component will be styled with the CSS classes `class-name-1` and `class-name-2`.
4040

41+
### ARIA and Data Attributes
42+
43+
Reflex supports accessibility attributes (ARIA) and data attributes using Python's snake_case convention (with underscore) instead of the HTML kebab-case (with dash). These are automatically converted to the proper format when rendered as HTML.
44+
45+
For example, `aria_label` becomes `aria-label` and `data_testid` becomes `data-testid` in the generated HTML.
46+
47+
```python demo
48+
rx.button(
49+
"Close",
50+
aria_label="Close dialog",
51+
data_testid="close-button",
52+
)
53+
```
54+
55+
### Custom Attributes
56+
57+
For cases where you need to add arbitrary HTML attributes that aren't covered by the built-in props, you can use `custom_attrs` as an escape hatch. This prop accepts a dictionary of attribute names and values.
58+
59+
```python demo
60+
rx.button(
61+
"Custom Button",
62+
custom_attrs={"role": "menuitem", "tabindex": "-1"},
63+
)
64+
```
65+
66+
Note that for ARIA and data attributes, it's recommended to use the underscore notation (`aria_label`, `data_testid`) instead of `custom_attrs` for better readability and consistency.
67+
4168
## Style Props
4269

4370
In addition to component-specific props, most built-in components support a full range of style props. You can use any [CSS property](https://www.w3schools.com/cssref/index.php) to style a component.

0 commit comments

Comments
 (0)