跳到主要内容

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​

PropDescriptionTypeDefault
contentText contentstring—
rowsVisible rows when collapsed (>= 1; invalid values fall back to 1)number1
expandableRender the expand / collapse actionbooleanfalse
expandedExpanded state (controlled; internal when absent)boolean—
actionTextAction label (falls back to i18n ellipsis.expand / collapse)string—
positionTruncation position (end / middle; middle is single-line JS)'end' | 'middle''end'
ellipsisLabelAccessibility name (falls back to a 40-char content summary)string—
sxQuick layout propsLhSxProps—
onExpandedChangeExpanded state change (action click, write-back included)(expanded: boolean) => void—
onClickActionAction clicked (fires together with onExpandedChange)() => void—

Accessibility​

  • The action is a standalone focusable element (role="button" + tabIndex={0}, Enter / Space activate) with aria-expanded synced.