fix(dify-ui): preserve link semantics in button story (#39430)

This commit is contained in:
yyh 2026-07-23 09:07:08 +08:00 committed by GitHub
parent d5788cc019
commit 018fe7a9d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react-vite'
import * as React from 'react'
import { expect, fn } from 'storybook/test'
import { Button } from '.'
import { Button, buttonVariants } from '.'
const meta = {
title: 'Base/UI/Button',
@ -151,11 +151,24 @@ export const LargeSize: Story = {
},
}
export const AsLink: Story = {
args: {
variant: 'ghost-accent',
render: <a href="https://example.com" />,
nativeButton: false,
children: 'Link Button',
export const StyledLink: Story = {
render: () => (
<a className={buttonVariants({ variant: 'ghost-accent' })} href="https://example.com">
Link styled as a button
</a>
),
play: async ({ canvas }) => {
await expect(canvas.getByRole('link', { name: 'Link styled as a button' })).toHaveAttribute(
'href',
'https://example.com',
)
},
parameters: {
docs: {
description: {
story:
'Rendering an anchor through `Button` is an anti-pattern because Base UI enforces button semantics. Keep the native link and apply `buttonVariants` directly when a link needs button styling. See the [Base UI Button usage guidelines](https://base-ui.com/react/components/button#rendering-links-as-buttons).',
},
},
},
}

View File

@ -6,7 +6,7 @@ import { Button as BaseButton } from '@base-ui/react/button'
import { cva } from 'class-variance-authority'
import { cn } from '../cn'
const buttonVariants = cva(
export const buttonVariants = cva(
'inline-flex cursor-pointer items-center justify-center whitespace-nowrap outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid data-[disabled]:cursor-not-allowed',
{
variants: {