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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(web): improve snippet run panel accessibility (#43028)
平衡世界的BOY27cdf50c7dd0
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.jsonindex 0450c8208bf..dfea6b67a0a 100644--- a/oxlint-suppressions.json+++ b/oxlint-suppressions.json@@ -2472,17 +2472,6 @@"count": 2}},- "web/app/components/snippets/components/snippet-run-panel.tsx": {- "jsx-a11y/click-events-have-key-events": {- "count": 5- },- "jsx-a11y/no-autofocus": {- "count": 1- },- "jsx-a11y/no-static-element-interactions": {- "count": 5- }- },"web/app/components/snippets/hooks/use-nodes-sync-draft.ts": {"dify/require-disable-directive-description": {"count": 1diff --git a/web/app/components/snippets/components/__tests__/snippet-run-panel.spec.tsx b/web/app/components/snippets/components/__tests__/snippet-run-panel.spec.tsxindex 0b057cb75c4..e718cf55759 100644--- a/web/app/components/snippets/components/__tests__/snippet-run-panel.spec.tsx+++ b/web/app/components/snippets/components/__tests__/snippet-run-panel.spec.tsx@@ -65,6 +65,7 @@ vi.mock('@/app/components/workflow/nodes/_base/components/before-run-form/form-i}) => (<div><span>{`${payload.label}:${payload.type}:${String(value)}`}</span>+ {payload.type === InputVarType.textInput && <input aria-label={payload.label} />}<button type="button" onClick={() => onChange('changed topic')}>{`change-${payload.variable}`}</button>@@ -120,6 +121,94 @@ describe('SnippetRunPanel', () => {expect(handle).toHaveAttribute('aria-valuenow', '400')})+ it('closes the panel with an accessible button using Enter and Space', async () => {+ const user = userEvent.setup()+ renderWorkflowComponent(<SnippetRunPanel fields={[]} />, {+ initialStoreState: { previewPanelWidth: 480 },+ })++ const closeButton = screen.getByRole('button', { name: 'common.operation.close' })+ closeButton.focus()+ await user.keyboard('{Enter}')+ closeButton.focus()+ await user.keyboard('[Space]')++ expect(workflowHookMocks.handleCancelDebugAndPreviewPanel).toHaveBeenCalledTimes(2)+ })++ it('navigates between enabled tabs with the arrow keys', async () => {+ const user = userEvent.setup()+ renderWorkflowComponent(<SnippetRunPanel fields={fields} />, {+ initialStoreState: {+ showInputsPanel: true,+ previewPanelWidth: 480,+ workflowRunningData: {+ task_id: 'task-1',+ resultText: 'final answer',+ tracing: [],+ result: {+ status: WorkflowRunningStatus.Succeeded,+ files: [],+ inputs_truncated: false,+ process_data_truncated: false,+ outputs_truncated: false,+ },+ },+ },+ })++ const inputTab = screen.getByRole('tab', { name: 'runLog.input' })+ const resultTab = screen.getByRole('tab', { name: 'runLog.result' })+ const detailTab = screen.getByRole('tab', { name: 'runLog.detail' })+ inputTab.focus()++ expect(inputTab).toHaveAttribute('aria-selected', 'true')+ await user.keyboard('{ArrowRight}')+ expect(resultTab).toHaveFocus()+ expect(resultTab).toHaveAttribute('aria-selected', 'true')+ await user.keyboard('{ArrowRight}')+ expect(detailTab).toHaveFocus()+ expect(detailTab).toHaveAttribute('aria-selected', 'true')+ await user.keyboard('{ArrowLeft}{ArrowLeft}')+ expect(inputTab).toHaveFocus()+ expect(inputTab).toHaveAttribute('aria-selected', 'true')+ expect(screen.getByRole('textbox', { name: 'Topic' })).not.toHaveFocus()+ })++ it('disables result tabs until a workflow run is available', async () => {+ const user = userEvent.setup()+ renderWorkflowComponent(<SnippetRunPanel fields={fields} />, {+ initialStoreState: {+ showInputsPanel: true,+ previewPanelWidth: 480,+ },+ })++ const inputTab = screen.getByRole('tab', { name: 'runLog.input' })+ const resultTab = screen.getByRole('tab', { name: 'runLog.result' })+ const detailTab = screen.getByRole('tab', { name: 'runLog.detail' })+ const tracingTab = screen.getByRole('tab', { name: 'runLog.tracing' })++ expect(resultTab).toHaveAttribute('aria-disabled', 'true')+ expect(detailTab).toHaveAttribute('aria-disabled', 'true')+ expect(tracingTab).toHaveAttribute('aria-disabled', 'true')+ inputTab.focus()+ await user.keyboard('{ArrowRight}')+ expect(resultTab).toHaveFocus()+ expect(inputTab).toHaveAttribute('aria-selected', 'true')+ })++ it('focuses the first input when the input tab is active', () => {+ renderWorkflowComponent(<SnippetRunPanel fields={fields} />, {+ initialStoreState: {+ showInputsPanel: true,+ previewPanelWidth: 480,+ },+ })++ expect(screen.getByRole('textbox', { name: 'Topic' })).toHaveFocus()+ })+it('should render snippet input fields with defaults and run with edited inputs', async () => {const user = userEvent.setup()diff --git a/web/app/components/snippets/components/snippet-run-panel.tsx b/web/app/components/snippets/components/snippet-run-panel.tsxindex 9adf780bddb..f648c58e2d1 100644--- a/web/app/components/snippets/components/snippet-run-panel.tsx+++ b/web/app/components/snippets/components/snippet-run-panel.tsx@@ -4,8 +4,10 @@ import type { InputForm } from '@/app/components/base/chat/chat/type'import type { InputVar as WorkflowInputVar } from '@/app/components/workflow/types'import type { SnippetInputField } from '@/models/snippet'import { Button } from '@langgenius/dify-ui/button'+import { IconButton } from '@langgenius/dify-ui/icon-button'+import { Tabs, TabsList, TabsPanel, TabsTab } from '@langgenius/dify-ui/tabs'import copy from 'copy-to-clipboard'-import { memo, useCallback, useEffect, useId, useMemo, useState } from 'react'+import { memo, useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'import { useTranslation } from 'react-i18next'import { useStore as useReactFlowStore } from 'reactflow'import { useCheckInputsForms } from '@/app/components/base/chat/chat/check-input-forms-hooks'@@ -86,6 +88,8 @@ const SnippetRunPanel = ({ fields }: SnippetRunPanelProps) => {const [inputOverrides, setInputOverrides] = useState<Record<string, unknown> | null>(null)const [selectedTab, setSelectedTab] = useState<string | null>(null)const [isResizing, setIsResizing] = useState(false)+ const inputPanelRef = useRef<HTMLDivElement>(null)+ const isInitialMountRef = useRef(true)const inputs = inputOverrides ?? initialInputsconst hasInputTab = showInputsPanel && previewFields.length > 0@@ -97,6 +101,11 @@ const SnippetRunPanel = ({ fields }: SnippetRunPanelProps) => {!workflowRunningData.resultText &&!workflowRunningData.result.files?.lengthconst currentTab = selectedTab ?? (shouldShowDetailByDefault ? 'DETAIL' : defaultTab)+ const shouldFocusFirstInput = [+ InputVarType.textInput,+ InputVarType.paragraph,+ InputVarType.number,+ ].some((type) => type === previewFields[0]?.type)const handleValueChange = useCallback((variable: string, value: unknown) => {@@ -145,6 +154,15 @@ const SnippetRunPanel = ({ fields }: SnippetRunPanelProps) => {}}, [resize, stopResizing])+ useEffect(() => {+ if (!isInitialMountRef.current) return+ isInitialMountRef.current = false++ if (currentTab !== 'INPUT' || !hasInputTab || !shouldFocusFirstInput) return++ inputPanelRef.current?.querySelector<HTMLElement>('input, textarea')?.focus()+ }, [currentTab, hasInputTab, shouldFocusFirstInput])+return (<divid={panelId}@@ -164,70 +182,82 @@ const SnippetRunPanel = ({ fields }: SnippetRunPanelProps) => {/><div className="flex items-center justify-between p-4 pb-1 text-base font-semibold text-text-primary">{`Test Run${formatWorkflowRunIdentifier(workflowRunningData?.result.finished_at, workflowRunningData?.result.status)}`}- <div className="cursor-pointer p-1" onClick={handleCancelDebugAndPreviewPanel}>- <span className="i-ri-close-line h-4 w-4 text-text-tertiary" />- </div>+ <IconButton+ aria-label={t(($) => $['operation.close'], { ns: 'common' })}+ onClick={handleCancelDebugAndPreviewPanel}+ >+ <span aria-hidden className="i-ri-close-line h-4 w-4" />+ </IconButton></div>- <div className="relative flex grow flex-col">- <div className="flex shrink-0 items-center border-b-[0.5px] border-divider-subtle px-4">+ <Tabs+ value={currentTab}+ onValueChange={(value) => setSelectedTab(value as string)}+ className="relative flex grow flex-col"+ >+ <TabsList+ aria-label={t(($) => $['singleRun.testRun'], { ns: 'workflow' })}+ activateOnFocus+ className="shrink-0 items-center gap-6 border-b-[0.5px] border-divider-subtle px-4"+ >{hasInputTab && (- <div- className={`mr-6 cursor-pointer border-b-2 py-3 text-[13px] leading-4.5 font-semibold ${currentTab === 'INPUT' ? 'border-[rgb(21,94,239)]! text-text-secondary' : 'border-transparent text-text-tertiary'}`}- onClick={() => setSelectedTab('INPUT')}- >+ <TabsTab value="INPUT" className="py-3 text-[13px] leading-4.5 font-semibold">{t(($) => $.input, { ns: 'runLog' })}- </div>+ </TabsTab>)}- <div- className={`mr-6 cursor-pointer border-b-2 py-3 text-[13px] leading-4.5 font-semibold ${currentTab === 'RESULT' ? 'border-[rgb(21,94,239)]! text-text-secondary' : 'border-transparent text-text-tertiary'} ${!workflowRunningData ? 'cursor-not-allowed! opacity-30' : ''}`}- onClick={() => workflowRunningData && setSelectedTab('RESULT')}+ <TabsTab+ value="RESULT"+ disabled={!workflowRunningData}+ className="py-3 text-[13px] leading-4.5 font-semibold">{t(($) => $.result, { ns: 'runLog' })}- </div>- <div- className={`mr-6 cursor-pointer border-b-2 py-3 text-[13px] leading-4.5 font-semibold ${currentTab === 'DETAIL' ? 'border-[rgb(21,94,239)]! text-text-secondary' : 'border-transparent text-text-tertiary'} ${!workflowRunningData ? 'cursor-not-allowed! opacity-30' : ''}`}- onClick={() => workflowRunningData && setSelectedTab('DETAIL')}+ </TabsTab>+ <TabsTab+ value="DETAIL"+ disabled={!workflowRunningData}+ className="py-3 text-[13px] leading-4.5 font-semibold">{t(($) => $.detail, { ns: 'runLog' })}- </div>- <div- className={`mr-6 cursor-pointer border-b-2 py-3 text-[13px] leading-4.5 font-semibold ${currentTab === 'TRACING' ? 'border-[rgb(21,94,239)]! text-text-secondary' : 'border-transparent text-text-tertiary'} ${!workflowRunningData ? 'cursor-not-allowed! opacity-30' : ''}`}- onClick={() => workflowRunningData && setSelectedTab('TRACING')}+ </TabsTab>+ <TabsTab+ value="TRACING"+ disabled={!workflowRunningData}+ className="py-3 text-[13px] leading-4.5 font-semibold">{t(($) => $.tracing, { ns: 'runLog' })}- </div>- </div>+ </TabsTab>+ </TabsList><divclassName={`h-0 grow overflow-y-auto rounded-b-2xl ${currentTab === 'RESULT' || currentTab === 'TRACING' ? 'bg-background-section-burn!' : 'bg-components-panel-bg'}`}>- {currentTab === 'INPUT' && hasInputTab && (- <>- <div className="px-4 pt-3 pb-2">- {previewFields.map((field, index) => (- <div key={field.variable} className="mb-2 last-of-type:mb-0">- <FormItem- autoFocus={index === 0}- className="block!"- payload={field}- value={inputs[field.variable]}- onChange={(value) => handleValueChange(field.variable, value)}- />- </div>- ))}- </div>- <div className="flex items-center justify-between px-4 py-2">- <Button- variant="primary"- className="w-full"- disabled={workflowRunningData?.result?.status === WorkflowRunningStatus.Running}- onClick={handleSubmit}- >- {t(($) => $['singleRun.startRun'], { ns: 'workflow' })}- </Button>- </div>- </>- )}- {currentTab === 'RESULT' && (+ <TabsPanel value="INPUT">+ {hasInputTab && (+ <>+ <div ref={inputPanelRef} className="px-4 pt-3 pb-2">+ {previewFields.map((field) => (+ <div key={field.variable} className="mb-2 last-of-type:mb-0">+ <FormItem+ className="block!"+ payload={field}+ value={inputs[field.variable]}+ onChange={(value) => handleValueChange(field.variable, value)}+ />+ </div>+ ))}+ </div>+ <div className="flex items-center justify-between px-4 py-2">+ <Button+ variant="primary"+ className="w-full"+ disabled={workflowRunningData?.result?.status === WorkflowRunningStatus.Running}+ onClick={handleSubmit}+ >+ {t(($) => $['singleRun.startRun'], { ns: 'workflow' })}+ </Button>+ </div>+ </>+ )}+ </TabsPanel>+ <TabsPanel value="RESULT"><div className="p-2"><ResultTextisRunning={@@ -237,7 +267,7 @@ const SnippetRunPanel = ({ fields }: SnippetRunPanelProps) => {outputs={workflowRunningData?.resultText}allFiles={workflowRunningData?.result?.files}error={workflowRunningData?.result?.error}- onClick={() => setSelectedTab('DETAIL')}+ onClick={() => workflowRunningData && setSelectedTab('DETAIL')}/>{workflowRunningData?.result.status === WorkflowRunningStatus.Succeeded &&workflowRunningData?.resultText &&@@ -254,46 +284,48 @@ const SnippetRunPanel = ({ fields }: SnippetRunPanelProps) => {</Button>)}</div>- )}- {currentTab === 'DETAIL' && workflowRunningData?.result && (- <ResultPanel- inputs={workflowRunningData.result?.inputs}- inputs_truncated={workflowRunningData.result?.inputs_truncated}- process_data={workflowRunningData.result?.process_data}- process_data_truncated={workflowRunningData.result?.process_data_truncated}- outputs={workflowRunningData.result?.outputs}- outputs_truncated={workflowRunningData.result?.outputs_truncated}- outputs_full_content={workflowRunningData.result?.outputs_full_content}- status={workflowRunningData.result?.status || ''}- error={workflowRunningData.result?.error}- elapsed_time={workflowRunningData.result?.elapsed_time}- total_tokens={workflowRunningData.result?.total_tokens}- created_at={workflowRunningData.result?.created_at}- created_by={- (workflowRunningData.result?.created_by as unknown as { name: string })?.name- }- steps={workflowRunningData.result?.total_steps}- exceptionCounts={workflowRunningData.result?.exceptions_count}- />- )}- {currentTab === 'DETAIL' && !workflowRunningData?.result && (- <div className="flex h-full items-center justify-center bg-components-panel-bg">- <LoadingPlaceholder />- </div>- )}- {currentTab === 'TRACING' && (+ </TabsPanel>+ <TabsPanel value="DETAIL">+ {workflowRunningData?.result && (+ <ResultPanel+ inputs={workflowRunningData.result?.inputs}+ inputs_truncated={workflowRunningData.result?.inputs_truncated}+ process_data={workflowRunningData.result?.process_data}+ process_data_truncated={workflowRunningData.result?.process_data_truncated}+ outputs={workflowRunningData.result?.outputs}+ outputs_truncated={workflowRunningData.result?.outputs_truncated}+ outputs_full_content={workflowRunningData.result?.outputs_full_content}+ status={workflowRunningData.result?.status || ''}+ error={workflowRunningData.result?.error}+ elapsed_time={workflowRunningData.result?.elapsed_time}+ total_tokens={workflowRunningData.result?.total_tokens}+ created_at={workflowRunningData.result?.created_at}+ created_by={+ (workflowRunningData.result?.created_by as unknown as { name: string })?.name+ }+ steps={workflowRunningData.result?.total_steps}+ exceptionCounts={workflowRunningData.result?.exceptions_count}+ />+ )}+ {!workflowRunningData?.result && (+ <div className="flex h-full items-center justify-center bg-components-panel-bg">+ <LoadingPlaceholder />+ </div>+ )}+ </TabsPanel>+ <TabsPanel value="TRACING"><TracingPanelclassName="bg-background-section-burn"list={workflowRunningData?.tracing || []}/>- )}- {currentTab === 'TRACING' && !workflowRunningData?.tracing?.length && (- <div className="flex h-full items-center justify-center bg-background-section-burn!">- <LoadingPlaceholder />- </div>- )}+ {!workflowRunningData?.tracing?.length && (+ <div className="flex h-full items-center justify-center bg-background-section-burn!">+ <LoadingPlaceholder />+ </div>+ )}+ </TabsPanel></div>- </div>+ </Tabs></div>)}