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: guidelines/dxp/namespacing.md
+8-12Lines changed: 8 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
3
3
To promote consistency, we have established the following rule of thumb for namespacing in DXP:
4
4
5
-
*Unique attributes, such as `id`s, should *not* be namespaced
6
-
* Non-unique attributes, such as `name`, should be namespaced
7
-
* Fallback: if `id` is not passed, default to using `name` as `id`
5
+
-Unique attributes, such as `id`s, should _not_ be namespaced
6
+
- Non-unique attributes, such as `name`, should be namespaced
7
+
- Fallback: if `id` is not passed, default to using `name` as `id`
8
8
9
9
## Reasoning
10
10
11
-
The purpose of the `id` attribute is to define something unique to the whole page. By following this approach, we ensure that these attributes can be used in methods such as `document.getElementById` as is, without juggling namespaces.
11
+
The purpose of the `id` attribute is to define something unique to the whole page. By following this approach, we ensure that these attributes can be used in methods such as `document.getElementById` as is, without juggling namespaces.
12
12
13
13
Other attributes, such as `name`, only need to be unique for some internal mechanism, such as in a `form` element. By namespacing them internally we ensure that, in case they end up being used under the hood as `id`s, they won't bleed into other components and cause duplicate issues.
The `clay:headless-data-set-display` element receives the `id` of its wrapping form as a `formId` attribute. This `id`**doesn't include the namespace**, and should not be namespaced inside the form taglib. The `clay:headless-data-set-display` component can now internally use `document.getElementById(formId)` to interact with the form when necessary, without adding the `namespace` before it, because the resulting HTML for the `form` would be as follows:
In this case, the `form` tag has a `name` attribute, which **will be namespaced under the hood**. Since we aren't passing an `id` prop, the component must use the fallback case and use the `name` as an `id`, resulting in the following HTML:
In this case, for the `clay:headless-data-set-display`, we are passing the `formName` prop instead of `id`. The component must namespace the `formName` attribute to find the element on the page, as such:
0 commit comments