Skip to content

Commit

Permalink
fix: don't render anchor if no href (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlockhart committed Jul 12, 2022
1 parent 4e263c0 commit 16839c0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
15 changes: 9 additions & 6 deletions d2l-navigation-link-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ class NavigationLinkImage extends FocusMixin(LitElement) {
}

render() {
return html`
<a href="${this.href}" title="${this.text}">
<span class="d2l-navigation-highlight-border"></span>
<span class="d2l-navigation-link-image-container"><img src="${this.src}" alt="${this.text}"></span>
</a>
`;
if (this.href) {
return html`
<a href="${this.href}" title="${this.text}">
<span class="d2l-navigation-highlight-border"></span>
<span class="d2l-navigation-link-image-container"><img src="${this.src}" alt="${this.text}"></span>
</a>
`;
}
return html`<span class="d2l-navigation-link-image-container"><img src="${this.src}" alt="${this.text}" title="${this.text}"></span>`;
}
}

Expand Down
3 changes: 3 additions & 0 deletions demo/button-link.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ <h2>d2l-navigation-link-image</h2>
href="https://www.example.org"
src="./logo-image.png"
text="Link Image Text"></d2l-navigation-link-image>
<d2l-navigation-link-image
src="./logo-image.png"
text="Link Image Text"></d2l-navigation-link-image>
</div>
</d2l-demo-snippet>

Expand Down
9 changes: 8 additions & 1 deletion test/link.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ describe('Links', () => {
describe('d2l-navigation-link-image', () => {

describe('accessibility', () => {
it('should pass all aXe tests', async() => {

it('default', async() => {
const el = await fixture(html`<d2l-navigation-link-image src="../demo/logo-image.png" href="https:/www.d2l.com" text="D2L"></d2l-navigation-link-image>`);
await expect(el).to.be.accessible();
});

it('no href', async() => {
const el = await fixture(html`<d2l-navigation-link-image src="../demo/logo-image.png" text="D2L"></d2l-navigation-link-image>`);
await expect(el).to.be.accessible();
});

});

describe('constructor', () => {
Expand Down
3 changes: 3 additions & 0 deletions test/link.visual-diff.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
<div class="visual-diff">
<d2l-navigation-link-image id="image" src="../demo/logo-image.png" href="https:/www.d2l.com" text="D2L"></d2l-navigation-link-image>
</div>
<div class="visual-diff">
<d2l-navigation-link-image id="image-no-href" src="../demo/logo-image.png" text="D2L"></d2l-navigation-link-image>
</div>
</body>
</html>
3 changes: 2 additions & 1 deletion test/link.visual-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('d2l-navigation-link', () => {
{ category: 'back', tests: ['normal', 'hover', 'focus'] },
{ category: 'icon-text', tests: ['normal', 'hover', 'focus'] },
{ category: 'icon-text-hidden', rectSelector: 'icon-text-hidden-container', tests: ['normal', 'hover', 'focus'] },
{ category: 'image', tests: ['normal', 'hover', 'focus'] }
{ category: 'image', tests: ['normal', 'hover', 'focus'] },
{ category: 'image-no-href', tests: ['normal', 'hover'] }
].forEach((entry) => {
describe(entry.category, () => {
entry.tests.forEach((name) => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 16839c0

Please sign in to comment.