Skip to main content

Ellipsis

Text truncation: multi-line CSS line-clamp first, JS fallback for position="middle" (uniform across platforms). 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 (write-back included):

const [open, setOpen] = useState(false)
<LhEllipsis content={longText} rows={2} expandable expanded={open} onExpandedChange={setOpen} />

Ellipsis API​

PropDescriptionTypeDefault
contentstringstring—
rowsnumbernumber1
expandablebooleanbooleanfalse
expandedbooleanboolean—
actionTextstringstring—
position'end' | 'middle''end' | 'middle''end'
ellipsisLabelstringstring—
sxLhSxPropsLhSxProps—
onExpandedChange(expanded: boolean) => void(expanded: boolean) => void—
onClickAction() => void() => void—

Accessibility​

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