Button
A configurable Button
component used to communicate actions that a user could take including triggering actions or events, submitting forms and more.
Button
components can also be grouped to create a ButtonGroup. For more information, see ButtonGroup.
Import
- React
- Angular
- Vue.js
// with @dhl-official/react-library:
import { DhlButton } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlButton } from "@dhl-official/ui-libraries/react-library"
If the DUIL has been installed, you can use the web component directly:
<dhl-button></dhl-button>
// with @dhl-official/vue-library:
import { DhlButton } from "@dhl-official/vue-library"
// with @dhl-official/ui-libraries/vue-library:
import { DhlButton } from "@dhl-official/ui-libraries/vue-library"
Code
- React
- Angular
- Vue.js
<DhlButton clickEvent={() => {}} variant="DHL_BUTTON.VARIANT.PRIMARY">Click here</DhlButton>
<dhl-button [clickEvent]="changeEvent" [variant]="DHL_BUTTON.VARIANT.PRIMARY">Click here</dhl-button>
<dhl-button :clickEvent.prop="() => {}" variant="DHL_BUTTON.VARIANT.PRIMARY">Click here</dhl-button>
Interactive Demo
Migrating from DUIL 1.0
- Rename
onClick
toclickEvent
- Rename
onKeyPress
tokeyPressEvent
Changelog
v2.4.1-monorepo.8
Breaking changes
- Deprecating
isBlock
property. - Add
isFullWidth
property - sets the button to 100% width of the parent container. Does NOT change the button to a block element.
Readme
Properties
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
clickEvent | -- | An optional onClick callback handler. | (e: MouseEvent) => void | undefined |
dataAriaControls | data-aria-controls | An 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. It's commonly used to describe a relationship between a button and the expandable region revealed by that button. | string | undefined |
dataAriaDisabled | data-aria-disabled | An optional ariaDisabled prop that conveys the disabled state of the Button to assistive technology such as screen readers. | string | undefined |
dataAriaExpanded | data-aria-expanded | An optional prop used for assistive technology support - used to mark expandable and collapsible regions. | string | undefined |
dataAriaLabel | data-aria-label | An optional prop defining the text read by the screen reader to represent the component; use this if you need different text to be read from label. | string | undefined |
dataAriaLabelledby | data-aria-labelledby | An 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. | string | undefined |
dataAutoFocus | data-auto-focus | An optional prop that when set, automatically sets focus on mount. | boolean | undefined |
dataClassName | data-class-name | An optional class name prop for the component. | string | undefined |
dataId | data-id | An optional prop. Gives a valid HTML ID attribute value for the component. | string | dhl-button-${getRandomString()} |
dataTestid | data-testid | An optional prop. The test id attached to the component as a data-testid attribute. | string | undefined |
dataTracking | data-tracking | An optional data tracking prop for the component. | string | undefined |
form | form | An optional prop used to associate the button within a form context. The value of the attribute must be the id attribute of a <form> element in the same document. If this attribute is not specified, the <button> element will be associated to an ancestor <form> element, if one exists. This attribute enables you to associate <button> elements to <form> elements anywhere within a document, not just as descendants of <form> elements. | string | undefined |
icon | icon | An optional prop used to pass an icon to render by the children of the Button | string | undefined |
iconOrientation | icon-orientation | An optional prop used to align an icon (if present) on either the left or right side of the component. | "left" \| "right" | DHL_BUTTON.ICON_ORIENTATION.RIGHT |
iconSize | icon-size | An optional prop used to control the size of icons in the button | "lg" \| "md" \| "sm" \| "xl" | undefined |
isBlock | is-block | [DEPRECATED] An optional prop that sets whether the component should inherit the width of it's container. | boolean | false |
isDisabled | is-disabled | An optional flag to define if the component is disabled. | boolean \| string | false |
isFullWidth | is-full-width | An optional prop that sets the component to 100% width of it's parent container. | boolean | false |
isRound | is-round | An optional property used in conjunction with an icon only variant. | boolean | undefined |
isStyled | is-styled | An optional prop used to set/remove the styling of the component. | boolean | true |
keyPressEvent | -- | An optional onKeyPress callback handler | (e: KeyboardEvent) => void | undefined |
name | name | An optional value to be set to the element HTML name attribute. It takes any valid value that can be used for the name attribute of an HTMLInputElement. | string | undefined |
renderAs | render-as | An optional prop used to set the parent tag - used to ensure semantic HTML use | "a" \| "button" | DHL_BUTTON.RENDER_AS.BUTTON |
renderAsProps | -- | An optional prop used to pass any additional props necessary for renderAs HTML tag. This is useful for passing additional props to the button element. The values set in the renderAsProps property takes priority over the values set in the stand alone properties. Setting conflicting values in the renderAsProps property and the stand alone properties, may generate unexpected results. | {} | {} |
size | size | An optional size prop for the component. | "md" \| "sm" \| "xs" | DHL_BUTTON.SIZE.MD |
textVariant | text-variant | An optional prop used to set the text color. | "dark" \| "light" \| "primary" | DHL_BUTTON.TEXT_VARIANT.PRIMARY |
type | type | An optional type prop used to set the type of the button e.g. reset, submit or button | "button" \| "reset" \| "submit" | DHL_BUTTON.TYPE.BUTTON |
variant | variant | An optional prop to select a component design variant. | "outline" \| "primary" \| "text" | DHL_BUTTON.VARIANT.PRIMARY |
Events
Event | Description | Type |
---|---|---|
dhlButtonBlur | Emits a custom event when the component is blurred | CustomEvent<any> |
Slots
Slot | Description |
---|---|
"unnamed" | unnamed children slot for Button text |
Dependencies
Used by
- dhl-back-to-top
- dhl-counter
- dhl-date-picker
- dhl-date-range-picker
- dhl-footer
- dhl-link
- dhl-modal
- dhl-navbar
- dhl-panel
- dhl-read-more
- dhl-tabs
- dhl-theme-switch
- dhl-tracking-bar
Depends on
Graph
Built by DHL User Interface Library Team!