Skip to main content

IconButton

An icon only IconButton component for compact actions such as search, close or filter. It renders a Button under the hood, so it shares the same variants, sizes and states.

Because there is no visible text, always pass dataAriaLabel so the button is announced with a name.

Import

// with @dhl-official/react-library:
import { DhlIconButton } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlIconButton } from "@dhl-official/ui-libraries/react-library"

Variants

The variant values are the same as on Button, so the same value works on both components. They map to the design names as follows:

Designvariant
Primaryprimary
SecondaryoutlineBlack
Secondary-highlightoutline
Tonaltonal
GhostghostBlack
Ghost-highlightghost

The button is a rounded square by default. Set isRound for a circle.

Code

<DhlIconButton icon={Search} dataAriaLabel="Search" clickEvent={() => {}} />

Active state

active applies the pressed treatment of the variant until it is toggled off and exposes aria-pressed="true". It is a persistent state, unlike the momentary :active pseudo-class. There is no loading state on IconButton.

<DhlIconButton icon={Filter} dataAriaLabel="Filter" active />

Interactive Demo

Readme

Overview

An icon only button. It renders a duil310-dhl-button so that both components share a single set of variant, size and state styles.

Properties

PropertyAttributeDescriptionTypeDefault
activeactiveAn optional prop that keeps the pressed visual treatment of the variant applied until it is toggled off. Unlike the :active pseudo-class, this is persistent and exposed as aria-pressed.booleanfalse
clickEventclick-eventAn optional onClick callback handler.(e: MouseEvent) => voidundefined
dataAriaControlsdata-aria-controlsAn optional ariaControls prop that is used as a 'relationship attribute' which denotes which elements in a page an interactive element or set of elements has control over and affects.stringundefined
dataAriaDescribedbydata-aria-describedbyAn optional prop used to associate the button with an element that describes it. Useful for explaining why a button is disabled.stringundefined
dataAriaExpandeddata-aria-expandedAn optional prop used for assistive technology support - used to mark expandable and collapsible regions.stringundefined
dataAriaLabeldata-aria-labelA recommended prop defining the text read by the screen reader to represent the component. An icon only button has no visible text, so without it the button is announced without a name.stringundefined
dataAriaLabelledbydata-aria-labelledbyAn optional ariaLabelledby prop that establishes the relationships between objects and their label(s), and its value should be one or more element IDs, which refer to elements that have the text needed for labelling. List multiple element IDs in a space delimited fashion.stringundefined
dataAriaPresseddata-aria-pressedAn optional ariaPressed prop that indicates the pressed state of a toggle button to assistive technology. The active prop already sets it, so this is only needed for a toggle that is not visually pressed.stringundefined
dataAutoFocusdata-auto-focusAn optional prop that when set, automatically sets focus on mount.booleanundefined
dataClassNamedata-class-nameAn optional class name prop for the component.stringundefined
dataIddata-idAn optional prop. Gives a valid HTML ID attribute value for the component.string`duil310-dhl-icon-button-${getRandomString()}`
dataTestiddata-testidAn optional prop. The test id attached to the component as a data-testid attribute.stringundefined
dataTrackingdata-trackingAn optional data tracking prop for the component.stringundefined
formformAn optional prop used to associate the button within a form context.stringundefined
iconiconAn optional prop used to pass the icon to render inside the button.stringundefined
iconSizeicon-sizeAn optional prop used to control the size of the icon. Defaults to the icon size that matches the button size."lg" | "md" | "sm" | "xl"undefined
isDisabledis-disabledAn optional flag to define if the component is disabled.boolean | stringfalse
isRoundis-roundAn optional prop that renders the button as a circle instead of a rounded square.booleanfalse
keyPressEventkey-press-eventAn optional onKeyPress callback handler(e: KeyboardEvent) => voidundefined
namenameAn optional value to be set to the element HTML name attribute.stringundefined
sizesizeAn optional size prop for the component."md" | "sm" | "xs"DHL_ICON_BUTTON.SIZE.MD
typetypeAn optional type prop used to set the type of the button e.g. reset, submit or button"button" | "reset" | "submit"DHL_ICON_BUTTON.TYPE.BUTTON
variantvariantAn optional prop to select a component design variant."ghost" | "ghostBlack" | "outline" | "outlineBlack" | "primary" | "tonal"DHL_ICON_BUTTON.VARIANT.PRIMARY

Dependencies

Depends on

Graph


Built by DHL User Interface Library Team!