Ellipsis
Text truncation: multi-line CSS line-clamp first (row count driven by the
--lh-ellipsis-rows CSS variable), JS fallback for position="middle"
(truncateMiddle, uniform across platforms). Serves expand/collapse, middle
truncation and custom action scenarios (simple truncation stays with the Text
component's ellipsis). All truncation and state logic is consumed from
@lh-ui/share/core/ellipsis.
Basic usage
Ellipsis (1 row / 2 rows / middle / expandable)
lh-ui 是一个跨端组件库家族,双血脉架构,八仓齐发,文档站十站齐备,中表里外共十仓。lh-ui 是一个跨端组件库家族,双血脉架构,八仓齐发,文档站十站齐备,中表里外共十仓。lh-ui 是一 …中表里外共十仓。lh-ui 是一个跨端组件库家族,双血脉架构,八仓齐发,文档站十站齐备,中表里外共十仓。展开
import { LhEllipsis } from '@lh-ui/react'
export default function Demo() {
const longText =
'lh-ui 是一个跨端组件库家族,双血脉架构,八仓齐发,文档站十站齐备'
return (
<>
<LhEllipsis content={longText} />
<LhEllipsis content={longText} rows={2} />
<LhEllipsis content={longText} position="middle" />
</>
)
}
Controlled expansion
expanded makes the state controlled; onExpandedChange fires on every action
click (answer write-back included):
const [open, setOpen] = useState(false)
<LhEllipsis
content={longText}
rows={2}
expandable
expanded={open}
onExpandedChange={setOpen}
/>
Ellipsis API
| Prop | Description | Type | Default |
|---|---|---|---|
| content | Text content | string | — |
| rows | Visible rows when collapsed (>= 1; invalid values fall back to 1) | number | 1 |
| expandable | Render the expand / collapse action | boolean | false |
| expanded | Expanded state (controlled; internal when absent) | boolean | — |
| actionText | Action label (falls back to i18n ellipsis.expand / collapse) | string | — |
| position | Truncation position (end / middle; middle is single-line JS) | 'end' | 'middle' | 'end' |
| ellipsisLabel | Accessibility name (falls back to a 40-char content summary) | string | — |
| sx | Quick layout props | LhSxProps | — |
| onExpandedChange | Expanded state change (action click, write-back included) | (expanded: boolean) => void | — |
| onClickAction | Action clicked (fires together with onExpandedChange) | () => void | — |
Accessibility
- The action is a standalone focusable element (
role="button"+tabIndex={0}, Enter / Space activate) witharia-expandedsynced.