Links allow users to navigate to a different location. They can be presented inline inside a paragraph or as standalone text.
Events
Links with an href will be handled by the browser, or via a client side router. Links without an href will be rendered as a <span role="link"> instead of an <a>. Use the onPress event to handle user interaction.
import {Link} from '@react-spectrum/s2/Link';
<Link onPress={() => alert('Pressed link')}>Link</Link>
API
| Name | Type | Default |
|---|---|---|
children | ReactNode | Default: β |
styles | StylesProp | Default: β |
Spectrum-defined styles, returned by the | ||
variant | 'primary' |Β 'secondary' | Default: 'primary'
|
The visual style of the link. | ||
staticColor | 'white'
|Β 'black'
|Β 'auto' | Default: β |
The static color style to apply. Useful when the link appears over a color background. | ||
isStandalone | boolean | Default: β |
Whether the link is on its own vs inside a longer string of text. | ||
isQuiet | boolean | Default: β |
Whether the link should be displayed with a quiet style. | ||
onPress | | Default: β |
Handler that is called when the press is released over the target. | ||
onPressStart | | Default: β |
Handler that is called when a press interaction starts. | ||
onPressEnd | | Default: β |
Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. | ||
onPressChange | | Default: β |
Handler that is called when the press state changes. | ||
onPressUp | | Default: β |
Handler that is called when a press is released over the target, regardless of whether it started on the target or not. | ||
onFocus | | Default: β |
Handler that is called when the element receives focus. | ||
onBlur | | Default: β |
Handler that is called when the element loses focus. | ||
onFocusChange | | Default: β |
Handler that is called when the element's focus status changes. | ||
onKeyDown | | Default: β |
Handler that is called when a key is pressed. | ||
onKeyUp | | Default: β |
Handler that is called when a key is released. | ||
href | Href | Default: β |
A URL to link to. See MDN. | ||
hrefLang | string | Default: β |
Hints at the human language of the linked URL. SeeMDN. | ||
target | HTMLAttributeAnchorTarget | Default: β |
The target window for the link. See MDN. | ||
rel | string | Default: β |
The relationship between the linked resource and the current page. See MDN. | ||
download | boolean |Β string | Default: β |
Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN. | ||
ping | string | Default: β |
A space-separated list of URLs to ping when the link is followed. See MDN. | ||
referrerPolicy | HTMLAttributeReferrerPolicy | Default: β |
How much of the referrer to send when following the link. See MDN. | ||
routerOptions | RouterOptions | Default: β |
Options for the configured client side router. | ||
autoFocus | boolean | Default: β |
Whether the element should receive focus on render. | ||
id | string | Default: β |
The element's unique identifier. See MDN. | ||
aria-current | boolean
|Β 'true'
|Β 'false'
|Β 'page'
|Β 'step'
|Β 'location'
|Β 'date'
|Β 'time' | Default: β |
Indicates whether this element represents the current item within a container or set of related elements. | ||
aria-label | string | Default: β |
Defines a string value that labels the current element. | ||
aria-labelledby | string | Default: β |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | Default: β |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | Default: β |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
UNSAFE_className | UnsafeClassName | Default: β |
Sets the CSS className
for the element. Only use as a last resort. Use the | ||
UNSAFE_style | CSSProperties | Default: β |
Sets inline style for the
element. Only use as a last resort. Use the | ||
slot | string |Β null | Default: β |
A slot name for the component. Slots allow the component to receive props from a parent
component. An explicit | ||