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
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,10 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
18
18
19
19
## [Unreleased]
20
20
21
+
### Added
22
+
23
+
- Added `ENABLE_BIRD_ID_ATTR` setting (default: `True`) to control whether components receive an automatic `data-bird-id` attribute. This is to help with component identification in the DOM and for a future planned feature around JS/CSS asset scoping.
Copy file name to clipboardExpand all lines: docs/configuration.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +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
16
}
16
17
```
17
18
@@ -110,3 +111,9 @@ TEMPLATES = [
110
111
```
111
112
112
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
+
115
+
## `ENABLE_BIRD_ID_ATTR`
116
+
117
+
Controls whether components automatically receive a `data-bird-id` attribute containing a unique identifier. Defaults to `True`.
118
+
119
+
See [Component ID Attribute](params.md#component-id-attribute) for more details on how this works.
Copy file name to clipboardExpand all lines: docs/params.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,46 @@ This will render as:
85
85
</button>
86
86
```
87
87
88
+
### Component ID Attribute
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.
91
+
92
+
For example, for a component template like this:
93
+
94
+
```htmldjango
95
+
<button {{ attrs }}>
96
+
{{ slot }}
97
+
</button>
98
+
```
99
+
100
+
And used like this:
101
+
102
+
```htmldjango
103
+
{% bird button class="btn" %}
104
+
Click me
105
+
{% endbird %}
106
+
```
107
+
108
+
It will be rendered as:
109
+
110
+
```html
111
+
<buttondata-bird-id="abc1234"class="btn">
112
+
Click me
113
+
</button>
114
+
```
115
+
116
+
The ID is automatically generated from a hash of the component's name and template content.
117
+
118
+
You can disable this feature globally by setting `ENABLE_BIRD_ID_ATTR = False` in your Django settings:
119
+
120
+
```python
121
+
DJANGO_BIRD= {
122
+
"ENABLE_BIRD_ID_ATTR": False,
123
+
}
124
+
```
125
+
126
+
When disabled, no `data-bird-id` attribute will be added to your components.
127
+
88
128
## Properties
89
129
90
130
Properties (i.e. `props`) allow you to define parameters that your component expects, with optional default values. Unlike attributes which are provided as a flattened string via `{{ attrs }}`, props are processed by the component and made available as individual values (e.g. `{{ props.variant }}`) that can be used to control rendering logic.
0 commit comments