Skip to content

Commit

Permalink
Merge pull request #426 from podium-lib/improve_dsd_assertion
Browse files Browse the repository at this point in the history
fix: sharpen up shadow dom usage assertion
  • Loading branch information
digitalsadhu authored Sep 29, 2024
2 parents bc8a8b6 + 7eeaeb7 commit b853980
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ const podlet = new Podlet(options);

#### name

The name the podlet identifies itself by. This value must be in camelCase.
The name the podlet identifies itself by. This value can contain upper and lower case letters, numbers, the - character and the \_ character. No spaces.
When shadow DOM is used, either via the `useShadowDOM` constructor option or via the `wrapWithShadowDOM` method, the name must comply with custom element naming rules.
See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names) for more information.

_Example:_

Expand Down Expand Up @@ -268,6 +270,7 @@ const podlet = new Podlet({ ..., useShadowDOM: true });
```

Please note the following caveats when using this feature:

1. You must name your podlet following custom element naming conventions as explained here: https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names
2. In order to style your content, you will need to include your CSS inside the shadow DOM wrapper. You can do this using one of the following 2 options:

Expand Down
2 changes: 1 addition & 1 deletion lib/podlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ export default class PodiumPodlet {
wrapWithShadowDOM(data) {
assert.ok(
customElementRegex.test(this.name),
'When using the constructor argument "useShadowDOM", podlet.name must conform to custom element naming conventions: https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names',
`When using the constructor argument "useShadowDOM" or the method podlet.wrapWithShadowDOM, podlet.name must conform to custom element naming conventions. The name "${this.name}" does not comply. See https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define#valid_custom_element_names for more information.`,
);

const styles = this.cssRoute
Expand Down

0 comments on commit b853980

Please sign in to comment.