-
Notifications
You must be signed in to change notification settings - Fork 54
Add optional element name parameter to @controller decorator #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
93d47c3
Initial commit: Planning implementation
Copilot dda4d5e
Implement optional element name parameter for @controller decorator
Copilot ba13979
Add test for data-catalyst attribute with custom element names
Copilot 0c8d2a7
Adjust docs
dgreif 811be96
Remove package-lock.json changes
dgreif c6e44ff
Bump to Node 24
dgreif 1a068b4
Set test timeout to 30 seconds
dgreif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,29 @@ describe('controller', () => { | |
| expect(instance).to.be.instanceof(ControllerRegisterElement) | ||
| }) | ||
|
|
||
| it('registers element with custom name when provided', async () => { | ||
| @controller('happy-widget') | ||
| class SomeClass extends HTMLElement {} | ||
| instance = await fixture(html`<happy-widget />`) | ||
| expect(instance).to.be.instanceof(SomeClass) | ||
| }) | ||
|
|
||
| it('registers element with custom name using function syntax', async () => { | ||
| controller('custom-element-name')(class AnotherClass extends HTMLElement {}) | ||
| instance = await fixture(html`<custom-element-name />`) | ||
| expect(instance).to.exist | ||
| }) | ||
|
|
||
| it('adds data-catalyst to elements with custom names', async () => { | ||
| @controller('custom-named-element') | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| class CustomNamedElement extends HTMLElement {} | ||
|
|
||
| instance = await fixture(html`<custom-named-element />`) | ||
| expect(instance.hasAttribute('data-catalyst')).to.equal(true) | ||
| expect(instance.getAttribute('data-catalyst')).to.equal('') | ||
| }) | ||
|
Comment on lines
+17
to
+38
|
||
|
|
||
| it('adds data-catalyst to elements', async () => { | ||
| @controller | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The custom element name parameter is not validated. According to the HTML specification, custom element names must contain a hyphen to avoid conflicts with standard HTML elements. Consider adding validation to ensure the provided name contains a hyphen and follows custom element naming rules, or rely on the browser's customElements.define to throw appropriate errors for invalid names.