---
title: "Link Overlay"
description: "Used to stretch a link click area over a positioned ancestor."
url: https://weme-ui.github.io/slim/components/link-overlay.md
---
# Link Overlay

用 `::before` 把点击范围铺到定位祖先上。整张卡片都能点，链接还是那个 `<a>`。`href`、`target`、`rel` 走 `$attrs`。

顺便一提，父级得 `position: relative`，不然铺不满。

## Installation

```bash
pnpm dlx @weme-ui/weme-ui add link-overlay
```

## Usage

```vue
<script lang="ts" setup>
import LinkOverlay from '../link-overlay.vue'
</script>

<template>
  <article class="p-4 b b-default rounded-lg max-w-sm transition-colors relative hover:bg-muted">
    <h3 class="text-base font-medium">
      <LinkOverlay href="#getting-started"> Getting Started </LinkOverlay>
    </h3>
    <p class="text-sm text-muted mt-1">整张卡片可点击，标题仍是语义化链接。</p>
  </article>
</template>
```

## Props

| 属性      | 说明                                      | 类型                 | 默认值  |
| --------- | ----------------------------------------- | -------------------- | ------- |
| `as`      | 渲染为的元素或组件（Reka UI `Primitive`） | `AsTag \| Component` | `'a'`   |
| `asChild` | 合并到子元素上渲染（Reka UI composition） | `boolean`            | `false` |
| `class`   | 根节点额外 class                          | `any`                | —       |

## Slots

| 插槽      | 说明                       |
| --------- | -------------------------- |
| `default` | 链接内容（通常为标题文案） |

## Accessibility

默认是原生 `<a>`（Reka UI `Primitive`）。点的是伪元素铺开的区域，链接还在文档流里，读屏和键盘都找得到。

### Keyboard Interactions

| Key     | Description    |
| ------- | -------------- |
| `Enter` | 激活链接并导航 |

## Examples

### As Child

```vue
<script lang="ts" setup>
import LinkOverlay from '../link-overlay.vue'
</script>

<template>
  <article class="p-4 b b-default rounded-lg max-w-sm transition-colors relative hover:bg-muted">
    <h3 class="text-base font-medium">
      <LinkOverlay as-child>
        <a href="#as-child" class="text-accent"> Compose with asChild </a>
      </LinkOverlay>
    </h3>
    <p class="text-sm text-muted mt-1">将样式与行为合并到自定义子元素上渲染。</p>
  </article>
</template>
```