Prevent multiple <a> tags in progressively enhanced usa-link#40
Open
bjmfactory wants to merge 1 commit intouswds:developfrom
Open
Prevent multiple <a> tags in progressively enhanced usa-link#40bjmfactory wants to merge 1 commit intouswds:developfrom
bjmfactory wants to merge 1 commit intouswds:developfrom
Conversation
bjmfactory
commented
Jul 24, 2024
| this.slottedChildren = childLink; | ||
| this.slottedChildren.classList.add('usa-link'); | ||
| this.shadowRoot.appendChild(this.slottedChildren); | ||
| return true; |
Author
There was a problem hiding this comment.
Without this line, I was observing the slot template is always rendered and the child template is never rendered.
Author
There was a problem hiding this comment.
When I ran npm run dev I got an error that said to remove node_modules and package-lock.json and re-run npm install. I'm not sure what the root cause of that is, but there was some error about Rollup I think.
Author
There was a problem hiding this comment.
I'm happy to remove this change if you like the other fix but don't want to touch package-lock.json at the moment.
| expect(getInsideLink().className).toContain("usa-link"); | ||
| }); | ||
|
|
||
| it("should render only one <a> tag", () => { |
Author
There was a problem hiding this comment.
This test successfully captures the current bug on develop. If you add it on develop it should fail with a 2 does not equal 1
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Prevented multiple tags in progressively enhanced
usa-linkFixed an issue in which there are nested tags in theusa-linkwhen a childLink is provided.Problem statement
We want only one tag in the output HTML when we use the progressively enhanced
usa-link.Desired state:
The actual state
Consequences of remaining in the current state
It is invalid HTML.
Solution
I removed the wrapper tag and instead added the
usa-linkclass to the existing link that is passed as a child. It's quite possible I did not follow Web Component best practices or your company best practices, or that there are other things I'm not considering, so there are lots of limitations :)Testing and review
I added a test that asserts that there is only one tag.