Anchor

Twilio's Anchor component

Status
production
Version
1.1.39
Sources
Abstract
Install
yarn add @twilio-paste/anchor — or — yarn add @twilio-paste/core

Guidelines#

About anchors#

The anchor can be used to hyperlink to another URL. It accepts both internal and external URLs.

Example use cases may include:

  • Linking to another page within an app or website
  • Linking to an external domain outside of the current app or website

Anchor vs. Button#

Anchors should be used in place of a button if you only need to create a hyperlink to some other page or content. Anchors should not be used for submitting a form, closing a modal, moving to the next step in a flow, or any other click action that a button should handle. Buttons perform an action, like submitting a form; Anchors take you somewhere, like to the documentation page.

If you need a click handler, you can use our Button component.

Accessibility#

The anchor is built with standard accessible practices in mind. Those include an href attribute, link context, and opening and closing tags.

The title attribute was not included because it’s not exposed to all browsers in an accessible way, meaning most screen readers and touch-only devices will likely never see that information.

Examples#

Default Anchor#

The default anchor is a basic text hyperlink. There are no other anchor variants at this time.

External Anchor#

If an external URL is used for the href, the target and rel will automatically be updated to:

target=”_blank” rel=”noreferrer noopener”

This is done for security purposes. Even though the target and rel are set by default for external anchors, they can be overridden using the target and rel props.

When to Use an Anchor#

You can use an anchor to navigate the user to another webpage.

Do

Anchors should only be used to link to another page, app, or another website.

Don't

Don’t use an anchor where a button makes more sense, i.e., closing a modal.


Usage Guide#

API#

Installation#

yarn add @twilio-paste/anchor - or - yarn add @twilio-paste/core

Usage#

import {Anchor} from '@twilio-paste/anchor';
const Component = () => <Anchor href="https://paste.twilio.design">Go to Paste</Anchor>;

Props#

PropTypeDescriptionDefault
href?stringA URL to route to. Required.null
tabindex?AnchorTabIndexes'0', '-1'null
target?AnchorTargets'_self', '_blank', '_parent', '_top'. If external href, defaults to '_blank'. Can be overwritten.null
rel?stringSets the anchor rel attribute. If external href, defaults to 'noreferrer noopener'. Can be overwritten.false
onClick?(event: React.MouseEvent<HTMLElement>)null
onFocus?(event: React.FocusEvent<HTMLElement>)null
onBlur?(event: React.FocusEvent<HTMLElement>)null

Support

If you need support, please open a new issue in our GitHub repository. Please try to provide as much detail as possible in your issue.

Contributing

The Paste design system is open source and contributions are welcome. Check out the project on GitHub to learn more about contributing.

Copyright © 2020 Twilio, Inc.