Components
Read More
Collapsible text clamped to a line count with an expand toggle.
Installation
$ npx veil-ui@latest add read-moreUsage
import { ReadMore } from "@/components/ui/read-more";
<ReadMore lines={3}>{article.summary}</ReadMore>;Examples
Basic
Buttons, inputs, navigation and overlays arrive as source files. Keep what you need, delete the rest, and edit every class. The registry only resolves dependencies and writes files, so there is no runtime to upgrade or fight with later.
Expanded
Buttons, inputs, navigation and overlays arrive as source files. Keep what you need, delete the rest, and edit every class. The registry only resolves dependencies and writes files, so there is no runtime to upgrade or fight with later.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| lines | 1 | 2 | 3 | 4 | 5 | 6 | 3 | Line count shown while collapsed. |
| moreLabel | string | "Read more" | Label of the expand button. |
| lessLabel | string | "Show less" | Label of the collapse button. |
| defaultExpanded | boolean | false | Start in the expanded state. |
Accessibility
- The toggle is a real button with
aria-expanded, so state changes are announced. - Labels describe the action in both directions rather than using a bare arrow.
- Content stays in the DOM and is only visually clamped, keeping it available to assistive technology.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add read-more --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { computed, ref } from "vue";
import { cn } from "@/lib/utils";
import type { ReadMoreLines, ReadMoreProps } from "./types";
const props = withDefaults(defineProps<ReadMoreProps>(), {
lines: 3,
moreLabel: "Read more",
lessLabel: "Show less",
defaultExpanded: false,
});
const clamps: Record<ReadMoreLines, string> = {
1: "line-clamp-1",
2: "line-clamp-2",
3: "line-clamp-3",
4: "line-clamp-4",
5: "line-clamp-5",
6: "line-clamp-6",
};
const expanded = ref(props.defaultExpanded);
const contentClass = computed(() =>
expanded.value ? undefined : clamps[props.lines],
);
</script>
<template>
<div data-slot="read-more" :class="cn('grid gap-2', props.class)">
<div :class="contentClass">
<slot />
</div>
<button
type="button"
:aria-expanded="expanded"
class="w-fit rounded-sm text-xs font-medium text-muted-foreground underline-offset-4 transition-colors hover:text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
@click="expanded = !expanded"
>
{{ expanded ? lessLabel : moreLabel }}
</button>
</div>
</template>