Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmparrish authored and overmyheadandbody committed Dec 3, 2024
1 parent c2ea4b5 commit 9a392e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion libs/features/icons/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ export default async function loadIcons(icons) {
const iconsToFetch = new Map();

icons.forEach((icon) => {
setNodeIndexClass(icon);
if (icon.classList.contains('icon-tooltip')) decorateToolTip(icon);
const iconName = [...icon.classList].find((c) => c.startsWith('icon-'))?.substring(5);
if (icon.dataset.svgInjected || !iconName) return;
icon.setAttribute('data-name', iconName);
if (!federalIcons[iconName] && !iconsToFetch.has(iconName)) {
const url = `${fedRoot}/federal/assets/icons/svgs/${iconName}.svg`;
iconsToFetch.set(iconName, fetch(url)
Expand Down Expand Up @@ -101,7 +103,7 @@ export default async function loadIcons(icons) {
await Promise.all(iconRequests);

icons.forEach((icon) => {
const iconName = [...icon.classList].find((c) => c.startsWith('icon-'))?.substring(5);
const iconName = icon.getAttribute('data-name');
if (iconName && federalIcons[iconName] && !icon.dataset.svgInjected) {
const svgClone = federalIcons[iconName].cloneNode(true);
icon.appendChild(svgClone);
Expand Down
4 changes: 2 additions & 2 deletions test/features/icons/icons.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import { stub } from 'sinon';
import sinon, { stub } from 'sinon';
import { waitForElement } from '../../helpers/waitfor.js';

const { default: loadIcons, setNodeIndexClass } = await import('../../../libs/features/icons/icons.js');
Expand All @@ -27,7 +27,7 @@ describe('Icon Suppprt', () => {
});

afterEach(() => {
window.fetch.restore();
sinon.restore();
});

it('Replaces span.icon', async () => {
Expand Down

0 comments on commit 9a392e9

Please sign in to comment.