Dojo NG is being built in the open, one section at a time — follow along on Heptapod.

API REFERENCE · DATA DISPLAY

<dj-icon>

A presentational icon.

Supply a glyph in one of two ways: set type to the name of an icon registered with registerIcon or registerIcons, or slot an inline <svg>.

Try it in the playground

@dojo-ng/icon · v0.1.1

npm install @dojo-ng/icon

import "@dojo-ng/icon";

Accessibility

  • Set alt-text when the icon carries meaning. It becomes the accessible name.
  • Without alt-text, the icon is hidden from assistive technology (aria-hidden).

SVG requirements

  • A registered SVG must have a viewBox. dj-icon sizes a glyph by stretching it to fill the icon box, and an <svg> scales its artwork only when it has a viewBox.
  • An SVG without a viewBox gets a box of the right size, but its artwork is clipped or not scaled. registerIcon and registerIcons log one console warning for each such icon, and they do not change the SVG.
  • dj-icon's own sizing overrides any width or height attributes on a registered SVG.
  • A slotted inline <svg> follows the same rules.

Properties

PropertyAttributeTypeDefault
typeRegistered icon name; resolved to an inline SVG from the icon registry. type string ""
sizeSize modifier. size reflected "small""medium""large" None
altTextVisually-hidden label; when set, the icon is exposed to assistive tech. alt-text string None

Slots

Default slot

CSS parts

Style these with dj-icon::part(name).

base

CSS custom properties

PropertyDefaultDescription
--dj-icon-colorcurrentColorIcon color.