Link
Takes the user to another page or section. Primary, neutral and on-colour, two sizes, inline and external.
Version 0.2.0 ·
Installation
bunx --bun shadcn@latest add @dga/linkUsage
import NextLink from "next/link";
import { Link } from "@/components/ui/link";
<Link render={<NextLink href="/services" />}>الخدمات</Link>Without render, Link renders a plain <a>. Use a Button for actions.
Anatomy
- Root: an
<a>, or any element throughrender. - Label: the link text.
- External icon (external links): mirrored in RTL.
Examples
Inline
Inside running text, set inline. Inline links are always underlined, so they can be told apart without colour (WCAG 1.4.1).
External
external opens a new tab with rel="noopener noreferrer", adds the external-link icon and tells screen readers. Translate the hint with externalLabel:
<Link href="https://dga.gov.sa" external externalLabel="(يفتح في علامة تبويب جديدة)">
هيئة الحكومة الرقمية
</Link>RTL
Text and the external-link icon follow the reading direction; the icon is mirrored in Arabic.
Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus to the link. |
| Enter | Follows it. |
- A real
<a href>: works with the keyboard, middle-click and "open in new tab". - Visited links change colour (
link-primary-visited). Hover and pressed also underline. - Focus ring on
:focus-visibleonly: 2pxborder-black, 2px offset, white on brand fills. - A disabled link has no
href, cannot be focused and is announced as disabled.
API Reference
Link
A text link in the DGA link colours. Works with Next.js `Link` through `render`.
| Prop | Type | Default |
|---|---|---|
ReactElement | functionAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. | No default | |
| ||
"on-color" | "primary" | "neutral"Colour. `on-color` is for links on brand fills. | "primary" | |
| ||
"sm" | "md"Text size: `sm` 14px, `md` 16px. | "md" | |
| ||
booleanAlways underlined, for links inside running text (WCAG 1.4.1). | false | |
| ||
booleanOpens in a new tab, adds rel="noopener noreferrer" and an external-link icon. | false | |
| ||
stringScreen-reader text added to external links. Translate it on Arabic pages. | "(opens in a new tab)" | |
| ||
stringDestination. | No default | |
| ||
booleanRenders without an href, with aria-disabled. | false | |
| ||
Also accepts the props of the element it renders.
Deviations from DGA
| Change | Reason |
|---|---|
--link-oncolor-hovered (light) and 5 more | Translucent white (60–90%) on the brand fill is 2.73–4.21:1. On-colour links stay white; hovered and pressed are shown by the underline. |
Link: focus ring and disabled | Keyboard-only focus (WCAG 2.4.7). A link without an href cannot be followed or focused. |
Link: external | WCAG 3.2.5: warn before opening a new window. |
Contrast
96 pairs checked · all pass WCAG 2.1 AAShow 18 statesHide
| Variant / state | Light | Dark |
|---|---|---|
| primary / default | 4.54:1 AA | 7.73:1 AAA |
| primary / hovered | 6.31:1 AA | 10.38:1 AAA |
| primary / pressed | 8.18:1 AAA | 13.05:1 AAA |
| primary / visited | 8.18:1 AAA | 13.05:1 AAA |
| primary / focused | 4.54:1 AA | 7.73:1 AAA |
| primary / focus ring | 17.31:1 3:1 | 17.49:1 3:1 |
| neutral / default | 9.73:1 AAA | 12.04:1 AAA |
| neutral / hovered | 4.57:1 AA | 6.32:1 AA |
| neutral / pressed | 7.04:1 AAA | 6.32:1 AA |
| neutral / visited | 8.18:1 AAA | 13.05:1 AAA |
| neutral / focused | 9.73:1 AAA | 12.04:1 AAA |
| neutral / focus ring | 17.31:1 3:1 | 17.49:1 3:1 |
| on-color / default | 4.74:1 AA | 4.74:1 AA |
| on-color / hovered | 4.74:1 AA | 4.74:1 AA |
| on-color / pressed | 4.74:1 AA | 4.74:1 AA |
| on-color / visited | 4.74:1 AA | 4.74:1 AA |
| on-color / focused | 4.74:1 AA | 4.74:1 AA |
| on-color / focus ring | 4.74:1 3:1 | 4.74:1 3:1 |
Text needs 4.5:1, icons and focus rings 3:1. Disabled states are exempt. Full contrast report