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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,9 +18,19 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
18
18
19
19
## [Unreleased]
20
20
21
+
### Added
22
+
23
+
- Added `data-bird-<component_name>` data attribute to the `attrs` template context variable for components when `ENABLE_BIRD_ATTRS` is enabled.
24
+
21
25
### Changed
22
26
23
27
-**Internal**: Refactored component rendering by introducing a new `BoundComponent` class and moving some of the rendering logic from `Component` and `BirdNode` to this new class.
28
+
- Renamed `ENABLE_BIRD_ID_ATTR` setting to `ENABLE_BIRD_ATTRS` to reflect its expanded functionality.
29
+
- Moved setting the `data-bird-id` data attribute in the `attrs` template context variable to `BoundComponent` and added a sequence number to better uniquely identify multiple instances of the same component.
30
+
31
+
### Deprecated
32
+
33
+
- The `ENABLE_BIRD_ID_ATTR` setting is deprecated and will be removed in the next minor version (v0.13.0). Use `ENABLE_BIRD_ATTRS` instead.
Copy file name to clipboardExpand all lines: docs/configuration.md
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ from pathlib import Path
12
12
DJANGO_BIRD = {
13
13
"COMPONENT_DIRS": list[Path | str] = [],
14
14
"ENABLE_AUTO_CONFIG": bool = True,
15
-
"ENABLE_BIRD_ID_ATTR": bool = True,
15
+
"ENABLE_BIRD_ATTRS": bool = True,
16
16
}
17
17
```
18
18
@@ -112,8 +112,12 @@ TEMPLATES = [
112
112
113
113
This configuration ensures that django-bird's templatetags are available globally and that its loader is used to compile bird component templates before the standard Django loaders.
114
114
115
-
## `ENABLE_BIRD_ID_ATTR`
115
+
## `ENABLE_BIRD_ATTRS`
116
116
117
-
Controls whether components automatically receive a `data-bird-id` attribute containing a unique identifier. Defaults to `True`.
117
+
Controls whether components automatically receive data attributes related to django-bird in its `attrs` template context variable. Defaults to `True`.
118
118
119
119
See [Component ID Attribute](params.md#component-id-attribute) for more details on how this works.
120
+
121
+
```{important}
122
+
This setting was previously named `ENABLE_BIRD_ID_ATTRS`. It was renamed to reflect the expansion of the data attributes for a component, from just `data-bird-id` to include `data-bird-<component_name>`, as well as to allow for future expansion. As of v0.12.0, the `ENABLE_BIRD_ID_ATTRS` setting is deprecated and will be removed in v0.13.0.
Copy file name to clipboardExpand all lines: docs/params.md
+39-6Lines changed: 39 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,7 +87,12 @@ This will render as:
87
87
88
88
### Component ID Attribute
89
89
90
-
When the [`ENABLE_BIRD_ID_ATTR` setting](configuration.md#enable_bird_id_attr) is enabled (the default), django-bird automatically adds a `data-bird-id` attribute to your components, available via the `{{ attrs }}` context variable. This attribute contains a unique identifier that helps identify specific component instances in the DOM.
90
+
When the [`ENABLE_BIRD_ATTRS` setting](configuration.md#enable_bird_attrs) is enabled (the default), django-bird automatically adds data attributes to your components, available via the `{{ attrs }}` context variable.
91
+
92
+
The following attributes are included:
93
+
94
+
-`data-bird-<component_name>`: This attribute will contain the name of the component. This is not unique across component instances in the DOM.
95
+
-`data-bird-id`: This attribute contains a unique identifier that helps identify specific component instances in the DOM.
The ID is automatically generated from a hash of the component's name and template content.
121
+
The ID is automatically generated from a hash of the component's name and template content. It also contains a sequence counter that will increment for any uses of a component across a single template.
122
+
123
+
The above example button component template, used like this:
124
+
125
+
```htmldjango
126
+
{% bird button class="btn" %}
127
+
Click me once
128
+
{% endbird %}
129
+
{% bird button class="btn" %}
130
+
Click me twice
131
+
{% endbird %}
132
+
{% bird button class="btn" %}
133
+
Click me three times a lady
134
+
{% endbird %}
135
+
```
136
+
137
+
Will be rendered like this, with the unique sequence numbers added to the component's hashed ID:
0 commit comments