Skip to content

feat(ellipsis): support expand only when the text is overflowed - #2022

Merged
haoziqaq merged 2 commits into
varletjs:devfrom
william-xue:feat/ellipsis-expand-on-overflow
Oct 12, 2026
Merged

haoziqaq merged 2 commits into
varletjs:devfrom
william-xue:feat/ellipsis-expand-on-overflow

Conversation

@william-xue

Copy link
Copy Markdown
Member

Checklist

  • Fix linting errors
  • Tests have been added / updated (or snapshots)

Change information

var-ellipsis 新增 expand-on-overflow 属性:开启后组件自己判断内容有没有被省略,只有被省略时才显示手型光标、才响应点击展开。

  • 单行比较 scrollWidth / clientWidth,line-clamp 场景比较 scrollHeight / clientHeight
  • 尺寸变化用 @varlet/use 的 useResizeObserver 监听,挂载与 line-clamp 变化时也会重新测量
  • 默认关闭,没开这个属性时行为与现在完全一致;tooltip 的显示时机也没动,避免影响已经在用的项目

Validation:

  • pnpm exec varlet-cli test -c ellipsis 13 个用例通过(新增 6 个:未省略不展开、已省略可展开、line-clamp 下按高度判断、未省略且 line-clamp 时不展开、默认关闭时行为不变)
  • pnpm lint 通过
  • 文档(zh-CN / en-US)、示例与 locale、类型声明已同步

Issues

close #2012

Related Links

None.

The component measures the content and the container, and only enables the
pointer cursor and the expand interaction when the text is overflowed.
Measure on mount, container resize and line-clamp change.
@vercel

vercel Bot commented Oct 12, 2026

Copy link
Copy Markdown

@william-xue is attempting to deploy a commit to the varletjs Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new

pkg-pr-new Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@varlet/cli

npm i https://pkg.pr.new/@varlet/cli@2022

@varlet/icons

npm i https://pkg.pr.new/@varlet/icons@2022

@varlet/import-resolver

npm i https://pkg.pr.new/@varlet/import-resolver@2022

@varlet/preset-tailwindcss

npm i https://pkg.pr.new/@varlet/preset-tailwindcss@2022

@varlet/preset-unocss

npm i https://pkg.pr.new/@varlet/preset-unocss@2022

@varlet/shared

npm i https://pkg.pr.new/@varlet/shared@2022

@varlet/touch-emulator

npm i https://pkg.pr.new/@varlet/touch-emulator@2022

@varlet/ui

npm i https://pkg.pr.new/@varlet/ui@2022

@varlet/use

npm i https://pkg.pr.new/@varlet/use@2022

@varlet/vite-plugins

npm i https://pkg.pr.new/@varlet/vite-plugins@2022

commit: e1a356e

@haoziqaq
haoziqaq merged commit 786420f into varletjs:dev Oct 12, 2026
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

希望ellipsis组件更加聪明

2 participants