Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): use buttons for plugin type switch (#40353)

yyhd2d07d0345b4
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index e2ca46bb818..bad55d147a9 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -2978,14 +2978,6 @@
"count": 1
}
},
- "web/app/components/plugins/marketplace/plugin-type-switch.tsx": {
- "jsx_a11y/click-events-have-key-events": {
- "count": 1
- },
- "jsx_a11y/no-static-element-interactions": {
- "count": 1
- }
- },
"web/app/components/plugins/plugin-auth/authorized/index.tsx": {
"no-restricted-imports": {
"count": 1
diff --git a/web/app/components/plugins/marketplace/__tests__/plugin-type-switch.spec.tsx b/web/app/components/plugins/marketplace/__tests__/plugin-type-switch.spec.tsx
index 2b780acd597..85788c98e96 100644
--- a/web/app/components/plugins/marketplace/__tests__/plugin-type-switch.spec.tsx
+++ b/web/app/components/plugins/marketplace/__tests__/plugin-type-switch.spec.tsx
@@ -28,23 +28,32 @@ describe('PluginTypeSwitch', () => {
it('renders every supported plugin category', () => {
renderSwitch()
- expect(screen.getByText('category.all')).toBeInTheDocument()
- expect(screen.getByText('category.models')).toBeInTheDocument()
- expect(screen.getByText('category.tools')).toBeInTheDocument()
- expect(screen.getByText('category.datasources')).toBeInTheDocument()
- expect(screen.getByText('category.agents')).toBeInTheDocument()
- expect(screen.getByText('category.triggers')).toBeInTheDocument()
- expect(screen.getByText('category.extensions')).toBeInTheDocument()
- expect(screen.getByText('category.bundles')).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'category.all' })).toHaveAttribute(
+ 'aria-pressed',
+ 'true',
+ )
+ expect(screen.getByRole('button', { name: 'category.models' })).toHaveAttribute(
+ 'aria-pressed',
+ 'false',
+ )
+ expect(screen.getByRole('button', { name: 'category.tools' })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'category.datasources' })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'category.agents' })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'category.triggers' })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'category.extensions' })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'category.bundles' })).toBeInTheDocument()
})
it('updates the category in the URL when selected', async () => {
const user = userEvent.setup()
const { onUrlUpdate } = renderSwitch('?category=all')
- await user.click(screen.getByText('category.models'))
+ const modelsButton = screen.getByRole('button', { name: 'category.models' })
+ modelsButton.focus()
+ await user.keyboard('{Enter}')
await waitFor(() => expect(onUrlUpdate).toHaveBeenCalled())
expect(onUrlUpdate.mock.calls.at(-1)?.[0].searchParams.get('category')).toBe('model')
+ expect(modelsButton).toHaveAttribute('aria-pressed', 'true')
})
})
diff --git a/web/app/components/plugins/marketplace/plugin-type-switch.tsx b/web/app/components/plugins/marketplace/plugin-type-switch.tsx
index 8ca737cd8da..6c3d6f876a5 100644
--- a/web/app/components/plugins/marketplace/plugin-type-switch.tsx
+++ b/web/app/components/plugins/marketplace/plugin-type-switch.tsx
@@ -91,9 +91,11 @@ const PluginTypeSwitch = ({ className, variant = 'default' }: PluginTypeSwitchPr
return (
<Fragment key={option.value}>
- <div
+ <button
+ type="button"
+ aria-pressed={isActive}
className={cn(
- 'flex h-8 cursor-pointer items-center rounded-lg border border-transparent px-2.5 system-md-medium whitespace-nowrap',
+ 'flex h-8 cursor-pointer appearance-none items-center rounded-lg border border-transparent px-2.5 system-md-medium whitespace-nowrap outline-hidden focus-visible:ring-2 focus-visible:ring-state-accent-solid',
isHero ? 'text-text-primary-on-surface' : 'text-text-tertiary',
!isActive &&
(isHero
@@ -113,7 +115,7 @@ const PluginTypeSwitch = ({ className, variant = 'default' }: PluginTypeSwitchPr
>
{option.icon}
{option.text}
- </div>
+ </button>
{isHero && index === 0 && (
<div
aria-hidden