Skip to content
Slotted

Link

Text that goes to another page or resource, with an underline, a new-tab warning and a current-page state.

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { Link, LinkDefaultsProvider } from '@slotted/react';

A link goes somewhere: it renders an anchor with an href, so the link role, Enter, the context menu, the middle click and every modified click come from the platform. An action that runs a handler and leaves the page where it is, such as sending an email again, is a Button, and inline sets it in the text around it. Space does not activate a link, and Link does not add it. For a navigation that wants the surface of a button, use ButtonLink in React and slButtonLink in Angular.

Underline

underline sets when the underline is drawn. always, the default, is the only value that suits a link inside a sentence, because color alone does not tell a link from the text beside it. hover draws the underline on hover and on keyboard focus, and none never draws it. Use hover and none where the position already says the text is a link, such as a navigation row or a table cell. Under forced colors the underline returns whatever the value is.

Variants

variant sets how the link is painted. accent, the default, uses the accent color. neutral takes the color of the text around it, so it belongs where nothing else on the line could be mistaken for it, such as a cell, a title or a row, and never inside a sentence. inverse uses the inverse text color, for a link on a solid surface.

Sizes

size sets the text to xs, sm or md: 12, 13 or 14 pixels on the type scale. Without it, a link takes the size its action slot states, or else the size of the text around it.

States

A link that has no destination yet is disabled. It renders no href, which stops a middle click as well as a left one, and it keeps role="link", aria-disabled and its place in the tab sequence, so a keyboard reader can still find it. Hover and press change the color and the underline. visited opts in to the visited color, which the browser applies once the destination is in its history.

Leaving the application

external opens the destination in a new tab and states it three ways: rel="noopener noreferrer", a marker for the eye, and the words “(opens in a new tab)” appended to the accessible name. The three follow the resolved target, so a target="_blank" you write yourself is warned about in the same way, and target="_self" beside external withdraws the warning. rel and target that you write are kept. messages replaces the wording of the warning: pass externalHint.

Current page

A link marks the page you are on through aria-current, the attribute a router already writes. The link takes the body text color. Its underline and its weight do not change, so the row does not shift. Link has no prop for it. In Angular, routerLinkActive with ariaCurrentWhenActive writes the attribute on the anchor.

In React, render substitutes the element and hands it the destination and every data attribute, so a router’s own link component keeps both. In Angular, slLink is an attribute on your own anchor, so routerLink and routerLinkActive sit on the same element. The example handles the click itself, which is what a router link does: the view changes and the page does not reload.

Defaults for the application

LinkDefaultsProvider in React and provideLinkDefaults in Angular set underline, variant and visited once for everything below them. A link that states a value of its own keeps it, as the last link here keeps its accent underline.

Accessibility

  • The rendered element is a plain anchor with an href, so the link role, Enter, the context menu and every modified click come from the platform. Space does not activate a link, and nothing here makes it. An action inside a line that runs a handler and goes nowhere is a Button with inline, not a Link without an href.
  • underline="always" is the default because color alone does not distinguish a link: the accent text color clears 4.5:1 against the surface and not 3:1 against the body text beside it.
  • variant="neutral" takes the color of the text around it, so it belongs where nothing on the line could be mistaken for it — a cell, a title, a row — and never inside a sentence.
  • Whatever the underline axis says, the underline returns under forced-colors, where the palette flattens the color contrast a bare link relies on.
  • A new browsing context is announced in the accessible name and marked with a glyph, and both follow the resolved target: a target="_blank" you write is warned about exactly like external.
  • external also sets rel="noopener noreferrer"; a rel or target you pass is kept instead of rewritten.
  • A disabled link renders no href, which is what stops a middle click as well as a left one, and keeps role="link", aria-disabled and its place in the tab sequence so the state can be discovered.
  • The current page is painted from aria-current, the attribute a router already writes; Link adds no prop for it.

API

Props

underline'always' | 'hover' | 'none'Default always
When the underline is drawn.
variant'accent' | 'neutral' | 'inverse'Default accent
The accent color, the color of the surrounding text, or the color for a solid surface.
size'xs' | 'sm' | 'md'
The text size: 12, 13 or 14 pixels on the type scale. Unset, the link takes the size its action slot states — a stat card’s action, a section’s or a chart’s actions state sm — or else its parent’s.
externalbooleanDefault false
Opens a new tab and warns that it does.
messagesPartial<LinkMessages>
Words laid over the language in force: the wording of that warning (externalHint).
disabledbooleanDefault false
Withholds the destination, keeps the role, the state and the tab stop.
visitedbooleanDefault false
Paints a destination the reader already followed.
hrefstring
The destination, and every other anchor attribute — target, rel, download, hreflang — reaches the element unchanged.

Composition

render(props: LinkRootProps) => ReactNode
Substitutes the rendered element. The destination and every data attribute are handed to it, so a router link keeps both.
refRef<HTMLAnchorElement>
Reaches the anchor, and focus() with it.
onClick, onAuxClick, onKeyDownEventHandler
Composed rather than replaced. While disabled, Link refuses the event first and the handler is not called.
LinkDefaultsProviderunderline | variant | visited
On ApplicationSets those three once for everything below it. A prop on the link still wins.

Parts

PartElementRequiredPurpose
rootaYesThe link itself. Carries data-ui="link", the axes as data attributes, and every native anchor attribute you pass.
external-iconspanNoThe marker a new tab earns: the external Glyph inside a directional icon box, sized to the text and hidden from assistive technology. Rendered only when the resolved target is _blank.
external-hintspanNoThe same warning in words, clipped from view and appended to the accessible name. Rendered with the visually-hidden family.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every link inside it.

Link tokens

TokenDefault
--slotted-link-colorvar(--slotted-tone-accent-text, LinkText)
--slotted-link-color-activecolor-mix(in oklab, var(--_rest) 35%, var(--_strong))
--slotted-link-color-currentvar(--slotted-text, CanvasText)
--slotted-link-color-disabledvar(--slotted-disabled-foreground, GrayText)
--slotted-link-color-hovercolor-mix(in oklab, var(--_rest) 65%, var(--_strong))
--slotted-link-color-visitedcolor-mix(in oklab, var(--_rest) 40%, var(--slotted-text-muted, GrayText))
--slotted-link-external-icon-gap0.15em
--slotted-link-external-icon-size1em
--slotted-link-focus-ring-offset1px
--slotted-link-font-sizeinherit
--slotted-link-radiusvar(--slotted-control-radius, 4px)
--slotted-link-underline-colorcolor-mix(in oklab, currentColor 55%, transparent)
--slotted-link-underline-offset0.15em
--slotted-link-underline-thicknessfrom-font

Theme tokens it reads

TokenDefault
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-duration-short120ms
--slotted-easing-standardcubic-bezier(0.2, 0, 0, 1)
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-size-md0.875rem
--slotted-font-size-sm0.8125rem
--slotted-font-size-xs0.75rem
--slotted-textSet per scheme by the theme
--slotted-text-inverseSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-accent-textSet per scheme by the theme