Skip to main content

BackToTop

The BackToTop component is used on a page to scroll the page to top when it was scrolled down. It can be configured to be only visible after certain vertical offset. By default the button is shown when the page has been scrolled down more than 200px.

Import

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

Code

<DhlBackToTop buttonText="Top" clickEvent={() => {}}></DhlBackToTop>

Interactive Demo

Migrating from DUIL 1.0

  • Rename onClick to clickEvent
  • Rename onScrollComplete to scrollCompleteEvent

Readme

Properties

PropertyAttributeDescriptionTypeDefault
buttonTextbutton-textA REQUIRED buttonText prop for the inner BackToTop text - for an icon only variant, this prop should be set to emptystringundefined
clickEvent--An optional onClick callback handler.(e: MouseEvent) => voidundefined
dataAriaLabeldata-aria-labelAn 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.stringundefined
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.stringdhl-back-to-top-${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
focusSelectorfocus-selectorAn optional focusSelector prop - defaults to body, selector prop to focus an interactive element when back to top scroll is complete. user should set tabIndex appropriately if focus needs to move to a non-interactive element. use these styles to have smooth scroll behavior html {scroll-behavior: smooth;stringundefined
iconOrientationicon-orientationAn optional iconOrientation prop used to align the icon within the component. Passing a value to this prop without a set buttonText will result in a misaligned icon and thus should not be set if an iconOnly variant is desired."left" \| "right"undefined
isDisabledis-disabledAn optional flag to define if the component is disabled.booleanfalse
scrollCompleteEvent--An optional onScrollComplete callback handler triggered upon scroll completion() => voidundefined
showAtshow-atAn optional showAt prop taking a scrollY distance at which the BackToTop button should become visiblenumber200
sizesizeAn optional size prop for the component."md" \| "sm" \| "xs"DHL_BACK_TO_TOP.SIZE.MD
textSizetext-sizeAn optional textSize prop for the BackToTop inner text"10xl" \| "11xl" \| "2xl" \| "2xs" \| "3xl" \| "4xl" \| "5xl" \| "6xl" \| "7xl" \| "8xl" \| "9xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"DHL_BACK_TO_TOP.TEXT_SIZE.MD
textWeighttext-weightAn optional textWeight prop for the BackToTop inner text weight200 \| 400 \| 700 \| 800DHL_BACK_TO_TOP.TEXT_WEIGHT[700]

Dependencies

Depends on

Graph


Built by DHL User Interface Library Team!