Skip to content

fix(ui): give the default button variant a hover state on <button> elements - #213

Merged
zuohuadong merged 1 commit into
mainfrom
fix/button-default-hover
Aug 8, 2026
Merged

fix(ui): give the default button variant a hover state on <button> elements#213
zuohuadong merged 1 commit into
mainfrom
fix/button-default-hover

Conversation

@zuohuadong

Copy link
Copy Markdown
Owner

问题

buttonVariants 的 default 变体使用了 badge 的锚点作用域写法 [a]:hover:bg-primary/80。Button 组件默认渲染为原生 <button>,该选择器编译后为 .[a]:hover:bg-primary/80:is(a):hover,只对 <a> 生效——普通按钮的 primary 变体没有任何 hover 反馈,只有 <Button href> 渲染的锚点按钮才有。

同文件内 outline / secondary / ghost / destructive / link 变体的 hover 均不带 [a]: 作用域,badge.svelte 的 [a]: 模式(非锚点渲染为静态 span,只需给链接态 hover)不适用于 button,应为移植时的笔误。

修复

[a]:hover:bg-primary/80hover:bg-primary/80,与其余变体保持一致。

验证

  • 新增 button.test.ts:断言 default 变体含 hover:bg-primary/80 且所有变体不含 [a]: 作用域;packages/ui vitest 43/43 通过。
  • 端到端:在下游消费方(xigu-fa)构建产物中,修复后生成 .hover\:bg-primary\/80:hover(对 <button> 生效),修复前仅有 :is(a):hover 规则;badge 的 [a]: 规则保持不变。

…ements

The default variant carried badge's anchor-scoped [a]:hover:bg-primary/80,
so a Button rendered as a native <button> (the component's default branch)
got no hover feedback at all; only anchor buttons did. Every other variant
already scopes hover to the element itself, and shadcn's [a]: pattern only
fits Badge, whose non-anchor rendering is a static span.

Verified end to end: a consumer build now emits .hover:bg-primary/80:hover
instead of .[a]:hover:bg-primary/80:is(a):hover.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying svadmin-example with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7112413
Status: ✅  Deploy successful!
Preview URL: https://23d78ef7.svadmin-example.pages.dev
Branch Preview URL: https://fix-button-default-hover.svadmin-example.pages.dev

View logs

@zuohuadong
zuohuadong merged commit ebb1b38 into main Aug 8, 2026
3 of 4 checks passed
@zuohuadong
zuohuadong deleted the fix/button-default-hover branch August 8, 2026 00:19
@zuohuadong zuohuadong mentioned this pull request Aug 8, 2026
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.

1 participant