API: components
Link
A link with a disabled and a current state, on your anchor or your router's link, with no router dependency, in each framework.
A link that knows the two states your navigation gives it: current (aria-current="page",
the APG breadcrumb's attribute for the
page you are on) and disabled (aria-disabled="true": it stays in the tab order, and its
press navigates nowhere). It is the APG link: a
native anchor, Enter follows it. It renders your router's link, and the package depends on no
router.
Behaviour
- Current:
currentsetsaria-current="page"anddata-current. - Disabled:
aria-disabled="true"anddata-disabled; the anchor keeps itshrefand its tab stop. Its click stops in its capture phase: its default is prevented (no navigation) and no listener after it runs, a router's included (React Router's and Vue Router's links, and Angular'sRouterLink, which does not checkdefaultPrevented). Enter on it does nothing. - Routers: React
render={<RouterLink to="/docs" />}, Vue:as="RouterLink" to="/docs", Angular on the router's own anchor,<a routerLink="/docs" link>. - No text: its text, or your
aria-label.
Anatomy
| part | element | data-primitives-part | role |
|---|---|---|---|
| Link | a | link-root | one component; your anchor or your router's |
Usage
import { Link } from "@fragiola/primitives-react/link";
import { Link as RouterLink } from "react-router";
<Link render={<RouterLink to="/docs" />} current={pathname === "/docs"}>
Docs
</Link>;
<Link href="/archive" disabled>
Archive
</Link>;Props
Link also takes what the primitive contract gives: render
(Vue: as and the render slot), a class and a style, a ref, and any attribute, which it
forwards (href, target, rel). Angular binds them as inputs ([current], [disabled]).
Link
| prop | type | default | description |
|---|---|---|---|
disabled | boolean | false | unavailable: aria-disabled, and its press navigates nowhere |
current | boolean | false | it links to the page the app is on: aria-current="page" |
State and part attributes
| attribute | when |
|---|---|
aria-disabled="true", data-disabled | disabled |
aria-current="page", data-current | current |
Keyboard
The browser's: Tab reaches it (a disabled link too), Enter follows it; Enter on a disabled link does nothing.
Exports
| entry | exports |
|---|---|
@fragiola/primitives-react/link | Link, LinkProps, LinkState, RenderProp |
@fragiola/primitives-vue/link | Link, LinkProps, LinkState, RenderSlotProps |
@fragiola/primitives-angular/link | Link, LinkState |