Open Web Components
On this page

Icon Button#

A borderless icon-only button. It renders as an anchor when href is set, so it works for actions and navigation alike. Give it a label so screen readers can name it. via the name parameter, you can set which icon it should use.

Simple Example#

this is a simple example, where it logs on each click.

export const simpleButton = () => {
  return html`
    <owc-icon-button name="gear" label="Settings" @click=${() => console.log('click')}>
    </owc-icon-button>
  `;
};

With tooltip#

you can also give it a tooltip to display a text while hovering over it.

export const withTooltip = () => {
  return html`
    <owc-tooltip>
      Settings
      <owc-icon-button slot="anchor" name="gear" label="Settings"> </owc-icon-button>
    </owc-tooltip>
  `;
};

With href the icon button navigates. A target automatically adds rel="noreferrer noopener"; set download to offer the target as a file download.

export const asLink = () => {
  return html`
    <owc-icon-button
      name="arrow-up-right-square"
      label="Open example.com"
      href="https://example.com"
      target="_blank"
    >
    </owc-icon-button>
  `;
};

Variant#

The variant is forwarded to the underlying wa-icon (e.g. regular instead of the solid default).

export const variant = () => {
  return html`
    <owc-icon-button name="x-circle" label="Close" variant="regular"> </owc-icon-button>
  `;
};

Disabled#

Disabled icon buttons block clicks and are removed from the tab order - links included.

export const disabled = () => {
  return html`
    <owc-icon-button disabled name="x-circle" label="Close" variant="regular"> </owc-icon-button>
    <owc-icon-button disabled name="gear" label="Settings" href="https://example.com">
    </owc-icon-button>
  `;
};

API#

Attributes & properties#

PropertyTypeDefaultDescription
namestring''Icon name, forwarded to wa-icon.
labelstring''Accessible name (aria-label); omitted from the DOM when empty.
hrefstring''Renders the icon button as an anchor pointing here.
targetstring''Link target (e.g. _blank); adds rel="noreferrer noopener" when set.
downloadstring''Download filename for links; only rendered when non-empty.
variantstring''Icon variant, forwarded to wa-icon (e.g. regular).
disabledbooleanfalseBlocks clicks and removes the control from the tab order; reflected as an attribute.

Methods#

MethodDescription
click()Simulates a click.
focus(options?)Focuses the inner button/anchor.
blur()Removes focus.