ShowMore
Collapses long text or slot content by line count or maximum height, with controlled expansion.
Import
Use <hui-show-more> after configuring uni-app easycom. Import public types and functions from @nscode/handy-uni. Ordinary Vue applications install the @nscode/handy-uni/web preview plugin.
Examples
Each example is standalone. Controls show the current value or event result on the page.
<template>
<view>
<hui-space direction="vertical" fill>
<hui-show-more
custom-class="hui-space__item"
:text="content"
:rows="2"
@change="(value) => (lastEvent = String(value))"
/>
<hui-show-more
v-model:expanded="expanded"
custom-class="hui-space__item"
:max-height="64"
:fade="false"
><text>{{ content }}</text></hui-show-more
>
<text class="hui-space__item">{{ expanded }} / {{ lastEvent }}</text>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
const expanded = ref(false)
const content = '长文本 / Long content. '.repeat(30)
</script>
Props
| Prop | Type | Default | Details |
|---|---|---|---|
text | string | — | Text content; NoticeBar also accepts a list. |
rows | number | 3 | Number of text rows. |
maxHeight | number | string | — | Collapsed maximum height. |
expanded | boolean | undefined | Controlled expansion state. |
defaultExpanded | boolean | false | Initial uncontrolled expansion state. |
expandText | string | — | Custom expand label. |
collapseText | string | — | Custom collapse label. |
fade | boolean | true | Displays an edge fade when more content is available. |
duration | number | 300 | Animation or display duration in milliseconds; see platform notes for zero. |
Root classes and styles use customClass and customStyle. Numbers representing dimensions use px; durations use ms unless explicitly documented.
Events
| Event | Arguments |
|---|---|
update:expanded | (expanded: boolean) |
change | (expanded: boolean) |
Controlled state only changes when the parent accepts its update event. Events with multiple words use kebab-case. Disabled or stale asynchronous actions do not emit a successful state change.
Slots
| Slot | Scope |
|---|---|
default | — |
toggle | { expanded, overflow, toggle } |
Methods
| Method | Signature | Description |
|---|---|---|
toggle | (expanded?: boolean): void | Request expansion change. |
remeasure | (): Promise<void> | Measure content and collapsed height again. |
Types
ShowMoreProps、ShowMoreEmits、ShowMoreExpose.
Platform notes
text is plain text, never HTML. The default slot must contain measurable content on WeChat; call remeasure after a hidden container becomes visible. No overflow means no toggle. Controlled expanded does not change without the parent accepting the update.
Device smoke checklist.