Getting Started
整张卡片可点击,标题仍是语义化链接。
用 ::before 把点击范围铺到定位祖先上。整张卡片都能点,链接还是那个 <a>。href、target、rel 走 $attrs。
顺便一提,父级得 position: relative,不然铺不满。
pnpm dlx @weme-ui/weme-ui add link-overlay整张卡片可点击,标题仍是语义化链接。
<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>将样式与行为合并到自定义子元素上渲染。
<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>Primitive)AsTag | Component'a'
booleanfalseany-默认是原生 <a>(Reka UI Primitive)。点的是伪元素铺开的区域,链接还在文档流里,读屏和键盘都找得到。
src/components/link-overlay/link-overlay.vuesrc/components/link-overlay/link-overlay.props.tssrc/components/link-overlay/link-overlay.style.ts