Link

A link allows a user to navigate to a different location.

Props

variant?

The visual style of the link.

Defaults to primary.
size?

Size of the link.

Defaults to inherit.
isQuiet?

Whether the link should be displayed with a quiet style.

isExternal?

Whether the link should open in a new tab.

style?

The inline style for the element. A function may be provided to compute the style based on component state.

autoFocus?

Whether the element should receive focus on render.

href?

A URL to link to. See MDN.

hrefLang?

Hints at the human language of the linked URL. SeeMDN.

target?

The target window for the link. See MDN.

rel?

The relationship between the linked resource and the current page. See MDN.

download?

Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.

ping?

A space-separated list of URLs to ping when the link is followed. See MDN.

referrerPolicy?

How much of the referrer to send when following the link. See MDN.

routerOptions?

Options for the configured client side router.

children?

The children of the component. A function may be provided to alter the children based on component state.

className?

The CSS className for the element. A function may be provided to compute the class based on component state.

onPress?

Handler that is called when the press is released over the target.

onPressStart?

Handler that is called when a press interaction starts.

onPressEnd?

Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target.

onPressChange?

Handler that is called when the press state changes.

onPressUp?

Handler that is called when a press is released over the target, regardless of whether it started on the target or not.

onFocus?

Handler that is called when the element receives focus.

onBlur?

Handler that is called when the element loses focus.

onFocusChange?

Handler that is called when the element's focus status changes.

onKeyDown?

Handler that is called when a key is pressed.

onKeyUp?

Handler that is called when a key is released.

onHoverStart?

Handler that is called when a hover interaction starts.

onHoverEnd?

Handler that is called when a hover interaction ends.

onHoverChange?

Handler that is called when the hover state changes.

isDisabled?

Whether the link is disabled.

aria-label?

Defines a string value that labels the current element.

aria-labelledby?

Identifies the element (or elements) that labels the current element.

aria-describedby?

Identifies the element (or elements) that describes the object.

aria-details?

Identifies the element (or elements) that provide a detailed, extended description for the object.

slot?

A slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.

Anatomy

Composed Components

A Link uses the following components.

Examples

Disabled

Links can be disabled.

External

An external text link will render by default with rel="noopener noreferrer" and target="_blank" attributes.

No Href

When a <Link> does not have an href prop, it is rendered as a <span role="link"> instead of an <a>. Events will need to be handled in JavaScript with the onPress prop.

Note: this will not behave like a native link. Browser features like context menus and open in a new tab will not apply.

Variants

Links can be presented in different variants.

Sizes

Links can be presented in different sizes.

Inherit Size

The size can also be inherited.

Icon

Links can contain an icon.

Start Icon

Non standard start icons can be provided to handle special cases. However, think twice before adding start icons, end icons should be your go to.

Icon Only

A link's content can be a single icon. When using this variant, an accessible name must be provided through the aria-label prop. See WCAG practices.

Quiet

All links can have a quiet style, without an underline. This style should only be used when the placement and context of the link is explicit enough that a visible underline isn’t necessary.

A button can be rendered as a react router link when using the href property and setting the navigate property on the HopperProvider

Custom Styles

When the colors from the variant props are not enough, you can use the color prop to set the color of the link. This removes the hover and focus colors from the link. Use the color props when a link needs to be placed on top of a colored background or visual. Make sure that the background and the link color meet the minimum color contrast ratio.

Image

A link's content can be an image element.

Migration Notes

Coming from Orbiter, you should be aware of the following changes:

  • Link, IconLink and TextLink have all been merged into one.
  • LinkAsButton has been removed. It is now possible to use the Link component without an href attribute.