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): clear Storybook and file preview lint suppressions (#44233)

Stephen Zhou9a00d853be20
diff --git a/lint.config.ts b/lint.config.ts
index d071b9e44f1..3b59024ce89 100644
--- a/lint.config.ts
+++ b/lint.config.ts
@@ -4,6 +4,7 @@ import type { OxlintConfig } from 'vite-plus/lint'
import path from 'node:path'
const rootDir = import.meta.dirname
+const webPackageJson = path.resolve(rootDir, 'web/package.json')
const difyUiPackageJson = path.resolve(rootDir, 'packages/dify-ui/package.json')
const enableTailwindCanonicalClasses = process.env.TAILWIND_CANONICAL_CLASSES === 'true'
@@ -846,7 +847,7 @@ export const lintConfig = {
{
files: ['web/.storybook/main.{js,cjs,mjs,ts}'],
rules: {
- 'storybook/no-uninstalled-addons': 'error',
+ 'storybook/no-uninstalled-addons': ['error', { packageJsonLocation: webPackageJson }],
},
},
{
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index ea3909e3092..68a3fb0a124 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -29,11 +29,6 @@
"count": 1
}
},
- "web/.storybook/main.ts": {
- "storybook/no-uninstalled-addons": {
- "count": 3
- }
- },
"web/__mocks__/zustand.ts": {
"dify/require-disable-directive-description": {
"count": 1
@@ -523,11 +518,6 @@
"count": 2
}
},
- "web/app/components/base/agent-log-modal/index.stories.tsx": {
- "no-console": {
- "count": 1
- }
- },
"web/app/components/base/agent-log-modal/index.tsx": {
"eslint-react/set-state-in-effect": {
"count": 1
@@ -575,11 +565,6 @@
"count": 1
}
},
- "web/app/components/base/auto-height-textarea/index.stories.tsx": {
- "no-console": {
- "count": 2
- }
- },
"web/app/components/base/auto-height-textarea/index.tsx": {
"dify/require-disable-directive-description": {
"count": 1
@@ -799,11 +784,6 @@
"count": 1
}
},
- "web/app/components/base/file-uploader/file-list-in-log.tsx": {
- "eslint-react/no-missing-key": {
- "count": 1
- }
- },
"web/app/components/base/file-uploader/file-preview-content.tsx": {
"jsx-a11y/media-has-caption": {
"count": 2
@@ -985,21 +965,11 @@
"count": 2
}
},
- "web/app/components/base/message-log-modal/index.stories.tsx": {
- "no-console": {
- "count": 1
- }
- },
"web/app/components/base/node-status/index.tsx": {
"react/only-export-components": {
"count": 1
}
},
- "web/app/components/base/notion-connector/index.stories.tsx": {
- "no-console": {
- "count": 1
- }
- },
"web/app/components/base/notion-page-selector/index.tsx": {
"no-barrel-files/no-barrel-files": {
"count": 1
@@ -1013,14 +983,6 @@
"count": 2
}
},
- "web/app/components/base/prompt-editor/index.stories.tsx": {
- "jsx-a11y/label-has-associated-control": {
- "count": 4
- },
- "no-console": {
- "count": 1
- }
- },
"web/app/components/base/prompt-editor/plugins/component-picker-block/index.tsx": {
"no-restricted-imports": {
"count": 1
@@ -1166,24 +1128,11 @@
"count": 3
}
},
- "web/app/components/base/prompt-log-modal/index.stories.tsx": {
- "no-console": {
- "count": 1
- }
- },
"web/app/components/base/prompt-log-modal/index.tsx": {
"eslint-react/set-state-in-effect": {
"count": 1
}
},
- "web/app/components/base/tag-input/index.stories.tsx": {
- "jsx-a11y/label-has-associated-control": {
- "count": 12
- },
- "no-console": {
- "count": 2
- }
- },
"web/app/components/base/text-generation/__tests__/hooks.spec.ts": {
"no-restricted-imports": {
"count": 1
@@ -1214,15 +1163,9 @@
"jsx-a11y/click-events-have-key-events": {
"count": 2
},
- "jsx-a11y/label-has-associated-control": {
- "count": 2
- },
"jsx-a11y/no-static-element-interactions": {
"count": 2
},
- "no-console": {
- "count": 2
- },
"typescript/no-explicit-any": {
"count": 1
}
diff --git a/web/app/components/base/agent-log-modal/index.stories.tsx b/web/app/components/base/agent-log-modal/index.stories.tsx
index 1aedc7bf759..9270a103ca1 100644
--- a/web/app/components/base/agent-log-modal/index.stories.tsx
+++ b/web/app/components/base/agent-log-modal/index.stories.tsx
@@ -2,6 +2,7 @@ import type { AgentLogResponse } from '@dify/contracts/api/console/apps/types.ge
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
import type { IChatItem } from '@/app/components/base/chat/chat/type'
import { useEffect, useRef } from 'react'
+import { fn } from 'storybook/test'
import { AppToastHost } from '@/app/notifications/host'
import AgentLogModal from '.'
@@ -63,7 +64,7 @@ const MOCK_CHAT_ITEM: IChatItem = {
conversationId: 'conv-123',
}
-const AgentLogModalDemo = ({ width = 960 }: { width?: number }) => {
+const AgentLogModalDemo = ({ width = 960, onCancel }: { width?: number; onCancel: () => void }) => {
const originalFetchRef = useRef<typeof globalThis.fetch>(null)
useEffect(() => {
@@ -101,9 +102,7 @@ const AgentLogModalDemo = ({ width = 960 }: { width?: number }) => {
appId="app-1"
currentLogItem={MOCK_CHAT_ITEM}
width={width}
- onCancel={() => {
- console.log('Agent log modal closed')
- }}
+ onCancel={onCancel}
/>
</div>
</>
@@ -124,6 +123,7 @@ const meta = {
},
args: {
width: 960,
+ onCancel: fn(),
},
tags: ['autodocs'],
} satisfies Meta<typeof AgentLogModalDemo>
diff --git a/web/app/components/base/auto-height-textarea/index.stories.tsx b/web/app/components/base/auto-height-textarea/index.stories.tsx
index 09ea8f3943d..c2d727f20b9 100644
--- a/web/app/components/base/auto-height-textarea/index.stories.tsx
+++ b/web/app/components/base/auto-height-textarea/index.stories.tsx
@@ -1,6 +1,7 @@
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
import type { ComponentProps } from 'react'
import { useState } from 'react'
+import { fn } from 'storybook/test'
import AutoHeightTextarea from '.'
const meta = {
@@ -51,9 +52,7 @@ const meta = {
},
},
args: {
- onChange: (e) => {
- console.log('Text changed:', e.target.value)
- },
+ onChange: fn(),
},
} satisfies Meta<typeof AutoHeightTextarea>
@@ -71,7 +70,7 @@ const AutoHeightTextareaDemo = (args: ComponentProps<typeof AutoHeightTextarea>)
value={value}
onChange={(e) => {
setValue(e.target.value)
- console.log('Text changed:', e.target.value)
+ args.onChange?.(e)
}}
/>
</div>
diff --git a/web/app/components/base/file-uploader/file-list-in-log.tsx b/web/app/components/base/file-uploader/file-list-in-log.tsx
index 7a72b14384f..e39d567fe9f 100644
--- a/web/app/components/base/file-uploader/file-list-in-log.tsx
+++ b/web/app/components/base/file-uploader/file-list-in-log.tsx
@@ -62,12 +62,12 @@ const FileListInLog = ({
const { id, name, type, supportFileType, base64Url, url } = file
const isImageFile = supportFileType === SupportUploadFileTypes.image
return (
- <>
+ <React.Fragment key={id}>
{isImageFile && (
<Tooltip>
<TooltipTrigger
render={
- <div key={id}>
+ <div>
<FileImageRender className="size-8" imageUrl={base64Url || url || ''} />
</div>
}
@@ -79,10 +79,7 @@ const FileListInLog = ({
<Tooltip>
<TooltipTrigger
render={
- <div
- key={id}
- className="rounded-md border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg p-1.5 shadow-xs"
- >
+ <div className="rounded-md border-[0.5px] border-components-panel-border bg-components-panel-on-panel-item-bg p-1.5 shadow-xs">
<FileTypeIcon type={getFileAppearanceType(name, type)} size="lg" />
</div>
}
@@ -90,7 +87,7 @@ const FileListInLog = ({
<TooltipContent>{name}</TooltipContent>
</Tooltip>
)}
- </>
+ </React.Fragment>
)
})}
</div>
diff --git a/web/app/components/base/message-log-modal/index.stories.tsx b/web/app/components/base/message-log-modal/index.stories.tsx
index afb87338493..8cecb1f2bd0 100644
--- a/web/app/components/base/message-log-modal/index.stories.tsx
+++ b/web/app/components/base/message-log-modal/index.stories.tsx
@@ -3,6 +3,7 @@ import type { IChatItem } from '@/app/components/base/chat/chat/type'
import type { WorkflowRunDetailResponse } from '@/models/log'
import type { NodeTracing, NodeTracingListResponse } from '@/types/workflow'
import { useEffect } from 'react'
+import { fn } from 'storybook/test'
import { WorkflowContextProvider } from '@/app/components/workflow/context'
import { BlockEnum } from '@/app/components/workflow/types'
import MessageLogModal from '.'
@@ -153,9 +154,7 @@ const meta = {
defaultTab: 'DETAIL',
width: 960,
fixedWidth: true,
- onCancel: () => {
- console.log('Modal closed')
- },
+ onCancel: fn(),
},
tags: ['autodocs'],
} satisfies Meta<typeof MessageLogPreview>
diff --git a/web/app/components/base/notion-connector/index.stories.tsx b/web/app/components/base/notion-connector/index.stories.tsx
index 3a86524cc4f..36d101f5172 100644
--- a/web/app/components/base/notion-connector/index.stories.tsx
+++ b/web/app/components/base/notion-connector/index.stories.tsx
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
+import { fn } from 'storybook/test'
import NotionConnector from '.'
const meta = {
@@ -14,9 +15,7 @@ const meta = {
},
},
args: {
- onSetting: () => {
- console.log('Open Notion settings')
- },
+ onSetting: fn(),
},
tags: ['autodocs'],
} satisfies Meta<typeof NotionConnector>
diff --git a/web/app/components/base/prompt-editor/index.stories.tsx b/web/app/components/base/prompt-editor/index.stories.tsx
index f3161766bd2..da55ba9404f 100644
--- a/web/app/components/base/prompt-editor/index.stories.tsx
+++ b/web/app/components/base/prompt-editor/index.stories.tsx
@@ -1,7 +1,9 @@
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
-import { useState } from 'react'
+import { useId, useState } from 'react'
+import { fn } from 'storybook/test'
type PromptEditorMockProps = {
+ id?: string
value?: string
onChange?: (value: string) => void
placeholder?: string
@@ -13,6 +15,7 @@ type PromptEditorMockProps = {
// Mock component to avoid complex initialization issues
const PromptEditorMock = ({
+ id,
value,
onChange,
placeholder,
@@ -31,6 +34,7 @@ const PromptEditorMock = ({
return (
<div className={wrapperClassName}>
<textarea
+ id={id}
className={`w-full resize-none outline-hidden ${compact ? 'text-[13px] leading-5' : 'text-sm/6'} ${className}`}
value={content}
onChange={handleChange}
@@ -81,6 +85,7 @@ const meta = {
description: 'CSS class for editor wrapper',
},
},
+ args: { onChange: fn() },
} satisfies Meta<typeof PromptEditorMock>
export default meta
@@ -98,7 +103,7 @@ const PromptEditorDemo = (args: PromptEditorMockProps) => {
value={value}
onChange={(text: string) => {
setValue(text)
- console.log('Content changed:', text)
+ args.onChange?.(text)
}}
/>
</div>
@@ -192,15 +197,19 @@ export const CustomPlaceholder: Story = {
// Multiple editors
const MultipleEditorsDemo = () => {
+ const id = useId()
const [systemPrompt, setSystemPrompt] = useState('You are a helpful assistant.')
const [userPrompt, setUserPrompt] = useState('')
return (
<div style={{ width: '700px' }} className="flex flex-col gap-6">
<div className="flex flex-col gap-2">
- <label className="text-sm font-medium text-gray-700">System Prompt</label>
+ <label htmlFor={`${id}-system`} className="text-sm font-medium text-gray-700">
+ System Prompt
+ </label>
<div className="min-h-25 rounded-lg border border-gray-300 bg-blue-50 p-4">
<PromptEditorMock
+ id={`${id}-system`}
value={systemPrompt}
onChange={setSystemPrompt}
placeholder="Enter system instructions..."
@@ -209,9 +218,12 @@ const MultipleEditorsDemo = () => {
</div>
</div>
<div className="flex flex-col gap-2">
- <label className="text-sm font-medium text-gray-700">User Prompt</label>
+ <label htmlFor={`${id}-user`} className="text-sm font-medium text-gray-700">
+ User Prompt
+ </label>
<div className="min-h-25 rounded-lg border border-gray-300 p-4">
<PromptEditorMock
+ id={`${id}-user`}
value={userPrompt}
onChange={setUserPrompt}
placeholder="Enter user message template..."
@@ -247,6 +259,7 @@ export const MultipleEditors: Story = {
// Real-world example - Email template
const EmailTemplateDemo = () => {
+ const id = useId()
const [subject, setSubject] = useState('Welcome to our platform!')
const [body, setBody] = useState(`Hi,
@@ -262,9 +275,12 @@ The Team`)
<h3 className="mb-4 text-lg font-semibold">Email Template Editor</h3>
<div className="flex flex-col gap-4">
<div className="flex flex-col gap-2">
- <label className="text-sm font-medium text-gray-700">Subject Line</label>
+ <label htmlFor={`${id}-subject`} className="text-sm font-medium text-gray-700">
+ Subject Line
+ </label>
<div className="rounded-lg border border-gray-300 p-3">
<PromptEditorMock
+ id={`${id}-subject`}
value={subject}
onChange={setSubject}
placeholder="Enter email subject..."
@@ -273,9 +289,12 @@ The Team`)
</div>
</div>
<div className="flex flex-col gap-2">
- <label className="text-sm font-medium text-gray-700">Email Body</label>
+ <label htmlFor={`${id}-body`} className="text-sm font-medium text-gray-700">
+ Email Body
+ </label>
<div className="min-h-50 rounded-lg border border-gray-300 p-4">
<PromptEditorMock
+ id={`${id}-body`}
value={body}
onChange={setBody}
placeholder="Type your email content... Use / to insert variables"
diff --git a/web/app/components/base/prompt-log-modal/index.stories.tsx b/web/app/components/base/prompt-log-modal/index.stories.tsx
index efd4f67176d..f26b3cd17ae 100644
--- a/web/app/components/base/prompt-log-modal/index.stories.tsx
+++ b/web/app/components/base/prompt-log-modal/index.stories.tsx
@@ -1,5 +1,6 @@
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
import type { IChatItem } from '@/app/components/base/chat/chat/type'
+import { fn } from 'storybook/test'
import PromptLogModal from '.'
type PromptLogModalProps = React.ComponentProps<typeof PromptLogModal>
@@ -46,9 +47,7 @@ const meta = {
},
args: {
width: 960,
- onCancel: () => {
- console.log('Prompt log closed')
- },
+ onCancel: fn(),
},
tags: ['autodocs'],
} satisfies Meta<typeof PromptLogPreview>
diff --git a/web/app/components/base/tag-input/__tests__/index.spec.tsx b/web/app/components/base/tag-input/__tests__/index.spec.tsx
index 8eddf775564..28ccf3a1825 100644
--- a/web/app/components/base/tag-input/__tests__/index.spec.tsx
+++ b/web/app/components/base/tag-input/__tests__/index.spec.tsx
@@ -85,6 +85,23 @@ describe('TagInput', () => {
})
})
+ it('associates an external label with the tag entry input', async () => {
+ const user = userEvent.setup()
+ const onChange = vi.fn()
+ render(
+ <>
+ <label htmlFor="recipient-tags">Recipients</label>
+ <TagInput id="recipient-tags" items={[]} onChange={onChange} />
+ </>,
+ )
+
+ const input = screen.getByRole('textbox', { name: 'Recipients' })
+ await user.click(screen.getByText('Recipients'))
+ expect(input).toHaveFocus()
+ await user.keyboard('alice{Enter}')
+ expect(onChange).toHaveBeenCalledWith(['alice'])
+ })
+
describe('User Interactions', () => {
it('should remove item when remove control is clicked', async () => {
const { onChange } = renderTagInput({ items: ['alpha', 'beta'] })
diff --git a/web/app/components/base/tag-input/index.stories.tsx b/web/app/components/base/tag-input/index.stories.tsx
index ffffcabe9d0..9056910d445 100644
--- a/web/app/components/base/tag-input/index.stories.tsx
+++ b/web/app/components/base/tag-input/index.stories.tsx
@@ -1,6 +1,7 @@
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
import type { ComponentProps } from 'react'
-import { useState } from 'react'
+import { useId, useState } from 'react'
+import { fn } from 'storybook/test'
import TagInput from '.'
const meta = {
@@ -48,9 +49,7 @@ const meta = {
},
},
args: {
- onChange: (items) => {
- console.log('Tags updated:', items)
- },
+ onChange: fn(),
},
} satisfies Meta<typeof TagInput>
@@ -68,7 +67,7 @@ const TagInputDemo = (args: ComponentProps<typeof TagInput>) => {
items={items}
onChange={(newItems) => {
setItems(newItems)
- console.log('Tags updated:', newItems)
+ args.onChange(newItems)
}}
/>
{items.length > 0 && (
@@ -172,6 +171,7 @@ export const SkillTags: Story = {
// Real-world example - Email tags
const EmailTagsDemo = () => {
+ const id = useId()
const [recipients, setRecipients] = useState(['[email protected]', '[email protected]'])
return (
@@ -179,8 +179,14 @@ const EmailTagsDemo = () => {
<h3 className="mb-4 text-lg font-semibold">Send Email</h3>
<div className="space-y-4">
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">To:</label>
+ <label
+ htmlFor={`${id}-recipients`}
+ className="mb-2 block text-sm font-medium text-gray-700"
+ >
+ To:
+ </label>
<TagInput
+ id={`${id}-recipients`}
items={recipients}
onChange={setRecipients}
placeholder="Add recipient email..."
@@ -188,8 +194,11 @@ const EmailTagsDemo = () => {
/>
</div>
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Subject:</label>
+ <label htmlFor={`${id}-subject`} className="mb-2 block text-sm font-medium text-gray-700">
+ Subject:
+ </label>
<input
+ id={`${id}-subject`}
type="text"
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
placeholder="Enter subject..."
@@ -214,6 +223,7 @@ export const EmailTags: Story = {
// Real-world example - Search filters
const SearchFiltersDemo = () => {
+ const id = useId()
const [filters, setFilters] = useState(['urgent', 'pending'])
const mockResults = [
@@ -232,8 +242,11 @@ const SearchFiltersDemo = () => {
<div style={{ width: '600px' }} className="rounded-lg border border-gray-200 bg-white p-6">
<h3 className="mb-4 text-lg font-semibold">Filter Tasks</h3>
<div className="mb-4">
- <label className="mb-2 block text-sm font-medium text-gray-700">Active Filters:</label>
+ <label htmlFor={`${id}-filters`} className="mb-2 block text-sm font-medium text-gray-700">
+ Active Filters:
+ </label>
<TagInput
+ id={`${id}-filters`}
items={filters}
onChange={setFilters}
placeholder="Add filter tag..."
@@ -273,6 +286,7 @@ export const SearchFilters: Story = {
// Real-world example - Product categories
const ProductCategoriesDemo = () => {
+ const id = useId()
const [categories, setCategories] = useState(['Electronics', 'Computers'])
return (
@@ -280,8 +294,11 @@ const ProductCategoriesDemo = () => {
<h3 className="mb-4 text-lg font-semibold">Product Details</h3>
<div className="space-y-4">
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Product Name</label>
+ <label htmlFor={`${id}-name`} className="mb-2 block text-sm font-medium text-gray-700">
+ Product Name
+ </label>
<input
+ id={`${id}-name`}
type="text"
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
placeholder="Enter product name..."
@@ -289,8 +306,14 @@ const ProductCategoriesDemo = () => {
/>
</div>
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Categories</label>
+ <label
+ htmlFor={`${id}-categories`}
+ className="mb-2 block text-sm font-medium text-gray-700"
+ >
+ Categories
+ </label>
<TagInput
+ id={`${id}-categories`}
items={categories}
onChange={setCategories}
placeholder="Add category..."
@@ -301,8 +324,14 @@ const ProductCategoriesDemo = () => {
</p>
</div>
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Description</label>
+ <label
+ htmlFor={`${id}-description`}
+ className="mb-2 block text-sm font-medium text-gray-700"
+ >
+ Description
+ </label>
<textarea
+ id={`${id}-description`}
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
rows={3}
placeholder="Enter product description..."
@@ -320,14 +349,18 @@ export const ProductCategories: Story = {
// Real-world example - Keyword extraction
const KeywordExtractionDemo = () => {
+ const id = useId()
const [keywords, setKeywords] = useState(['AI', 'machine learning', 'automation'])
return (
<div style={{ width: '600px' }} className="rounded-lg border border-gray-200 bg-white p-6">
<h3 className="mb-4 text-lg font-semibold">SEO Keywords</h3>
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Meta Keywords</label>
+ <label htmlFor={`${id}-keywords`} className="mb-2 block text-sm font-medium text-gray-700">
+ Meta Keywords
+ </label>
<TagInput
+ id={`${id}-keywords`}
items={keywords}
onChange={setKeywords}
placeholder="Add keyword..."
@@ -356,6 +389,7 @@ export const KeywordExtraction: Story = {
// Real-world example - Tags with suggestions
const TagsWithSuggestionsDemo = () => {
+ const id = useId()
const [tags, setTags] = useState(['design', 'frontend'])
const suggestions = ['backend', 'devops', 'mobile', 'testing', 'security']
@@ -363,8 +397,11 @@ const TagsWithSuggestionsDemo = () => {
<div style={{ width: '600px' }} className="rounded-lg border border-gray-200 bg-white p-6">
<h3 className="mb-4 text-lg font-semibold">Project Tags</h3>
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Add Tags</label>
+ <label htmlFor={`${id}-tags`} className="mb-2 block text-sm font-medium text-gray-700">
+ Add Tags
+ </label>
<TagInput
+ id={`${id}-tags`}
items={tags}
onChange={setTags}
placeholder="Type or select..."
@@ -398,6 +435,7 @@ export const TagsWithSuggestions: Story = {
// Real-world example - Stop sequences (Tab mode)
const StopSequencesDemo = () => {
+ const id = useId()
const [stopSequences, setStopSequences] = useState(['Human:', 'AI:'])
return (
@@ -405,12 +443,31 @@ const StopSequencesDemo = () => {
<h3 className="mb-4 text-lg font-semibold">AI Model Configuration</h3>
<div className="space-y-4">
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Temperature</label>
- <input type="range" min="0" max="2" step="0.1" defaultValue="0.7" className="w-full" />
+ <label
+ htmlFor={`${id}-temperature`}
+ className="mb-2 block text-sm font-medium text-gray-700"
+ >
+ Temperature
+ </label>
+ <input
+ id={`${id}-temperature`}
+ type="range"
+ min="0"
+ max="2"
+ step="0.1"
+ defaultValue="0.7"
+ className="w-full"
+ />
</div>
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Stop Sequences</label>
+ <label
+ htmlFor={`${id}-stop-sequences`}
+ className="mb-2 block text-sm font-medium text-gray-700"
+ >
+ Stop Sequences
+ </label>
<TagInput
+ id={`${id}-stop-sequences`}
items={stopSequences}
onChange={setStopSequences}
placeholder="Press Tab to add..."
@@ -421,8 +478,14 @@ const StopSequencesDemo = () => {
</p>
</div>
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Max Tokens</label>
+ <label
+ htmlFor={`${id}-max-tokens`}
+ className="mb-2 block text-sm font-medium text-gray-700"
+ >
+ Max Tokens
+ </label>
<input
+ id={`${id}-max-tokens`}
type="number"
defaultValue="2000"
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
@@ -440,16 +503,21 @@ export const StopSequences: Story = {
// Real-world example - Multi-language tags
const MultiLanguageTagsDemo = () => {
+ const id = useId()
const [tags, setTags] = useState(['Hello', '你好', 'Bonjour', 'Hola'])
return (
<div style={{ width: '600px' }} className="rounded-lg border border-gray-200 bg-white p-6">
<h3 className="mb-4 text-lg font-semibold">Internationalization</h3>
<div>
- <label className="mb-2 block text-sm font-medium text-gray-700">
+ <label
+ htmlFor={`${id}-translations`}
+ className="mb-2 block text-sm font-medium text-gray-700"
+ >
Greeting Translations
</label>
<TagInput
+ id={`${id}-translations`}
items={tags}
onChange={setTags}
placeholder="Add translation..."
diff --git a/web/app/components/base/tag-input/index.tsx b/web/app/components/base/tag-input/index.tsx
index f439a06f907..c10f4975a27 100644
--- a/web/app/components/base/tag-input/index.tsx
+++ b/web/app/components/base/tag-input/index.tsx
@@ -6,7 +6,7 @@ import { toast } from '@/app/notifications'
type TagInputProps = Pick<
InputHTMLAttributes<HTMLInputElement>,
- 'aria-label' | 'aria-describedby' | 'aria-invalid'
+ 'id' | 'aria-label' | 'aria-describedby' | 'aria-invalid'
> & {
items: string[]
onChange: (items: string[]) => void
@@ -20,6 +20,7 @@ type TagInputProps = Pick<
}
const TagInput = ({
+ id,
items,
onChange,
disableAdd,
@@ -132,6 +133,7 @@ const TagInput = ({
)}
>
<input
+ id={id}
aria-label={ariaLabel}
aria-describedby={ariaDescribedBy}
aria-invalid={ariaInvalid}
diff --git a/web/app/components/base/voice-input/index.stories.tsx b/web/app/components/base/voice-input/index.stories.tsx
index 8cd3a073075..baf55932f1d 100644
--- a/web/app/components/base/voice-input/index.stories.tsx
+++ b/web/app/components/base/voice-input/index.stories.tsx
@@ -1,5 +1,6 @@
import type { Meta, StoryObj } from '@storybook/nextjs-vite'
-import { useState } from 'react'
+import { useId, useState } from 'react'
+import { fn } from 'storybook/test'
// Mock component since VoiceInput requires browser APIs and service dependencies
const VoiceInputMock = ({ onConverted, onCancel }: any) => {
@@ -93,6 +94,7 @@ const meta = {
},
},
tags: ['autodocs'],
+ args: { onConverted: fn(), onCancel: fn() },
} satisfies Meta<typeof VoiceInputMock>
export default meta
@@ -148,12 +150,9 @@ export const Default: Story = {
// Recording state
export const RecordingState: Story = {
- render: () => (
+ render: (args) => (
<div style={{ width: '600px' }}>
- <VoiceInputMock
- onConverted={() => console.log('Converted')}
- onCancel={() => console.log('Cancelled')}
- />
+ <VoiceInputMock {...args} />
<div className="mt-3 text-xs text-gray-500">
Recording in progress with live waveform visualization
</div>
@@ -356,6 +355,7 @@ export const NoteTaking: Story = {
// Real-world example - Form with voice
const FormWithVoiceDemo = () => {
+ const id = useId()
const [formData, setFormData] = useState({
name: '',
description: '',
@@ -367,8 +367,10 @@ const FormWithVoiceDemo = () => {
<h3 className="mb-4 text-lg font-semibold">Create Product</h3>
<div className="space-y-4">
- <div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Product Name</label>
+ <fieldset>
+ <legend id={`${id}-name`} className="mb-2 block text-sm font-medium text-gray-700">
+ Product Name
+ </legend>
{activeField === 'name' ? (
<VoiceInputMock
onConverted={(text: string) => {
@@ -380,6 +382,7 @@ const FormWithVoiceDemo = () => {
) : (
<div className="flex gap-2">
<input
+ aria-labelledby={`${id}-name`}
type="text"
className="flex-1 rounded-lg border border-gray-300 px-3 py-2 text-sm"
placeholder="Enter product name..."
@@ -394,10 +397,12 @@ const FormWithVoiceDemo = () => {
</button>
</div>
)}
- </div>
+ </fieldset>
- <div>
- <label className="mb-2 block text-sm font-medium text-gray-700">Description</label>
+ <fieldset>
+ <legend id={`${id}-description`} className="mb-2 block text-sm font-medium text-gray-700">
+ Description
+ </legend>
{activeField === 'description' ? (
<VoiceInputMock
onConverted={(text: string) => {
@@ -409,6 +414,7 @@ const FormWithVoiceDemo = () => {
) : (
<div className="space-y-2">
<textarea
+ aria-labelledby={`${id}-description`}
className="w-full rounded-lg border border-gray-300 px-3 py-2 text-sm"
rows={4}
placeholder="Enter product description..."
@@ -423,7 +429,7 @@ const FormWithVoiceDemo = () => {
</button>
</div>
)}
- </div>
+ </fieldset>
<button className="w-full rounded-lg bg-blue-600 px-4 py-2 text-white hover:bg-blue-700">
Create Product