diff --git a/src/components.d.ts b/src/components.d.ts index 7a98dee..75c825b 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -7,6 +7,10 @@ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; export namespace Components { interface PdsIcon { + /** + * The `alt` attribute of the icon. + */ + "alt"?: string; /** * The color of the icon */ @@ -51,6 +55,10 @@ declare global { } declare namespace LocalJSX { interface PdsIcon { + /** + * The `alt` attribute of the icon. + */ + "alt"?: string; /** * The color of the icon */ diff --git a/src/components/pds-icon/pds-icon.tsx b/src/components/pds-icon/pds-icon.tsx index 0de403d..f64e8b0 100644 --- a/src/components/pds-icon/pds-icon.tsx +++ b/src/components/pds-icon/pds-icon.tsx @@ -20,6 +20,11 @@ export class PdsIcon { @State() private isVisible = false; @State() private svgContent?: string; + /** + * The `alt` attribute of the icon. + */ + @Prop() alt?: string; + /** * * The color of the icon @@ -157,7 +162,7 @@ export class PdsIcon { { html: '', }); expect(root).toEqualHtml(` - +
@@ -22,7 +22,7 @@ describe('pds-icon', () => { html: '', }); expect(root).toEqualHtml(` - +
@@ -30,13 +30,27 @@ describe('pds-icon', () => { `); }); + it('renders the alt attribute when prop is set', async () => { + const { root } = await newSpecPage({ + components: [PdsIcon], + html: ``, + }) + expect(root).toEqualHtml(` + + +
+
+
+ `) + }) + it('allows custom size', async () => { const { root } = await newSpecPage({ components: [PdsIcon], html: '', }); expect(root).toEqualHtml(` - +
@@ -50,7 +64,7 @@ describe('pds-icon', () => { html: '', }); expect(root).toEqualHtml(` - +
@@ -64,7 +78,7 @@ describe('pds-icon', () => { html: '', }); expect(root).toEqualHtml(` - +
@@ -79,7 +93,7 @@ describe('pds-icon', () => { }); expect(root).toEqualHtml(` - +
@@ -96,7 +110,7 @@ describe('pds-icon', () => { const icon = page.root; expect(icon).toEqualHtml(` - +
@@ -109,7 +123,7 @@ describe('pds-icon', () => { await page.waitForChanges(); expect(icon).toEqualHtml(` - +