diff --git a/packages/clay-icon/src/ClayIcon.js b/packages/clay-icon/src/ClayIcon.js index 633a3a5890..c6aa9e943d 100644 --- a/packages/clay-icon/src/ClayIcon.js +++ b/packages/clay-icon/src/ClayIcon.js @@ -51,6 +51,15 @@ ClayIcon.STATE = { * @default undefined */ symbol: Config.string().required(), + + /** + * The title of the Clay SVG Icon. + * @instance + * @memberof ClayIcon + * @type {?string|undefined} + * @default undefined + */ + title: Config.string(), }; defineWebComponent('clay-icon', ClayIcon); diff --git a/packages/clay-icon/src/ClayIcon.soy b/packages/clay-icon/src/ClayIcon.soy index fd72c033ed..44f8672048 100644 --- a/packages/clay-icon/src/ClayIcon.soy +++ b/packages/clay-icon/src/ClayIcon.soy @@ -8,6 +8,7 @@ {@param symbol: string} {@param? elementClasses: string} {@param? id: string} + {@param? title: string} {let $attributes kind="attributes"} aria-hidden="true" @@ -25,6 +26,7 @@ {/let} + {$title ?: $id ?: $symbol} {/template} diff --git a/packages/clay-icon/src/__tests__/ClayIcon.js b/packages/clay-icon/src/__tests__/ClayIcon.js index 1b82e29002..6eef756acf 100644 --- a/packages/clay-icon/src/__tests__/ClayIcon.js +++ b/packages/clay-icon/src/__tests__/ClayIcon.js @@ -39,4 +39,25 @@ describe('ClayIcon', function() { expect(clayIcon).toMatchSnapshot(); }); + + it('should render an icon with specified title', () => { + clayIcon = new ClayIcon({ + title: 'myTitle', + spritemap: spritemap, + symbol: 'add-cell', + }); + + expect(clayIcon).toMatchSnapshot(); + }); + + it('should render an icon with specified title when id is passed too', () => { + clayIcon = new ClayIcon({ + id: 'myId', + title: 'myTitle', + spritemap: spritemap, + symbol: 'add-cell', + }); + + expect(clayIcon).toMatchSnapshot(); + }); }); diff --git a/packages/clay-icon/src/__tests__/__snapshots__/ClayIcon.js.snap b/packages/clay-icon/src/__tests__/__snapshots__/ClayIcon.js.snap index 42b4f632f7..d1c153aa63 100644 --- a/packages/clay-icon/src/__tests__/__snapshots__/ClayIcon.js.snap +++ b/packages/clay-icon/src/__tests__/__snapshots__/ClayIcon.js.snap @@ -2,18 +2,35 @@ exports[`ClayIcon should render an icon with classes 1`] = ` `; exports[`ClayIcon should render an icon with id 1`] = ` +`; + +exports[`ClayIcon should render an icon with specified title 1`] = ` + +`; + +exports[`ClayIcon should render an icon with specified title when id is passed too 1`] = ` + `; exports[`ClayIcon should render markup for icon \`add-cell\` 1`] = ` `;