link — Link
The link is the smallest interactive unit for jumping between pages. core/link computes exactly two things: class names and aria — semantic type colors, the underline tri-state, and the disabled fallback all land on class names, while the navigation itself is left to the native <a> element and each platform’s router.
When to use
Section titled “When to use”- Each platform implements
LhLink: class names and aria are produced entirely bygetLinkClassNames/getLinkAria. - For scenarios reusing the link visual, such as the breadcrumb current page or in-table row actions, import the core function plus the class names from
styles/linkdirectly. - Do not use it for: triggering in-page actions — use
core/button(link semantics would mislead screen reader users into expecting a navigation).
Import
Section titled “Import”import { getLinkClassNames, getLinkAria } from '@lh-ui/share/core/link'import type { LhLinkState, LhLinkType, LhLinkUnderline } from '@lh-ui/share/core/link'Design intent
Section titled “Design intent”Three whitelist fallbacks guarantee that “an invalid prop never produces dirty class names”:
- Invalid
type→default: uses the token’s regular text color and produces no modifier class (lh-link--defaultdoes not exist). - Invalid
underline→hover: the global default form, likewise producing no modifier class; only explicitalways/nonevalues landlh-link--underline-{always|none}. - A truthy
disabledalways outputslh-link--disabled: the style side disables the hover color change and the underline.
A disabled link is a semantic hole in HTML — <a> has no disabled attribute. core’s answer is the aria-disabled + role="link" combination: screen readers still announce “link”, but it is explicitly unavailable; actually removing the clickable semantics (rendering as a span or omitting href) is done by the UI layer, and core only provides the correct attributes.
aria-current supports page / location, serving links that mean “I am where you currently are”, such as the breadcrumb current page or the pagination current item.
Function table
Section titled “Function table”| Function | Signature | Returns | Purpose |
|---|---|---|---|
getLinkClassNames |
(state?: Partial<LhLinkState>) => string[] |
class name array | computes all link class names |
getLinkAria |
(input: LhLinkAriaInput) => LhAriaAttrs |
aria attribute bundle | disabled and current-page semantics |
getLinkClassNames({ type: 'primary', underline: 'hover', disabled: false })// ['lh-link', 'lh-link--primary']
getLinkClassNames({ type: 'danger', underline: 'always', disabled: true })// ['lh-link', 'lh-link--danger', 'lh-link--underline-always', 'lh-link--disabled']Type definitions
Section titled “Type definitions”export type LhLinkType = 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info'
export type LhLinkUnderline = 'always' | 'hover' | 'none'
export interface LhLinkState { type: LhLinkType underline: LhLinkUnderline disabled: boolean}
export interface LhLinkAriaInput { disabled: boolean /** Current page / current location (breadcrumb and similar scenarios, outputs aria-current) */ current?: 'page' | 'location' | true}Accessibility
Section titled “Accessibility”- Disabled:
getLinkAria({ disabled: true })outputsaria-disabled="true"androle="link". The UI layer must also removehref(or render as aspan), otherwise keyboard users can still focus it and trigger navigation — the attribute bundle governs semantics, the DOM structure governs behavior, and neither layer is dispensable. - Current page:
aria-current="page"lets screen readers announce “current page” in a breadcrumb, which beats mere highlight styling. - Keyboard focus ring: driven uniformly by the focus-ring tokens in
theme/common/a11y.scss; the component never writes its own scattered outline rules.
Usage examples
Section titled “Usage examples”import { getLinkClassNames, getLinkAria } from '@lh-ui/share/core/link'
getLinkClassNames({ type: 'warning', underline: 'none', disabled: false })// ['lh-link', 'lh-link--warning', 'lh-link--underline-none']
getLinkAria({ disabled: false, current: 'page' })// { 'aria-current': 'page' }<!-- Vue3 --><a :class="getLinkClassNames({ type, underline, disabled })" :href="disabled ? undefined : href" v-bind="getLinkAria({ disabled, current })"> <span v-if="$slots.prefix" class="lh-link__icon lh-link__icon--prefix"><slot name="prefix" /></span> <slot /> <span v-if="$slots.suffix" class="lh-link__icon lh-link__icon--suffix"><slot name="suffix" /></span></a>// React: render a span when disabled, completely removing the interactive surface of link semanticsconst Tag = disabled ? 'span' : 'a'return ( <Tag className={getLinkClassNames({ type, underline, disabled }).join(' ')} href={disabled ? undefined : href} {...getLinkAria({ disabled, current })} > {children} </Tag>)// uniapp: the navigator component carries the navigation; a purely presentational state can// render text + class names directly. aria attributes have limited support on non-h5// platforms — trade off via platform conditional compilationStyles and tokens
Section titled “Styles and tokens”| Class | Semantic meaning |
|---|---|
.lh-link |
base class: inline-flex, regular text color, hover turns primary |
.lh-link--{primary|success|warning|danger|info} |
semantic types (default has no modifier class) |
.lh-link--underline-always |
persistent underline |
.lh-link--underline-none |
no underline (not even on hover) |
.lh-link--disabled |
disabled state: dimmed color + not-allowed pointer, hover underline disabled |
.lh-link__icon--prefix / .lh-link__icon--suffix |
prefix/suffix icon slots |
Colors are all var(--lh-*); hover colors for success / warning / danger mix 80% toward the text color with color-mix, and dark mode is flipped by var-dark.scss.
- The default
underline: 'hover'produces no modifier class; the style-side hover rule covers it. To “never show an underline” you must passnoneexplicitly. - If a disabled link still renders an
<a>, be sure to removehref; otherwisearia-disabledis effectively void. - The
defaulttype, like thehoverunderline, follows the “no modifier class” strategy; the UI layer must not rely onlh-link--defaultexisting.
@lh-ui/share/core/link → getLinkClassNames( )(填好参数后点运行)Copyright © 2024-2026 FengMo WenXue

