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(chat): enhance pointer event handling in chat components (#38385)

Wu Tianwei5b4ceacbe720
diff --git a/web/app/components/base/chat/chat-with-history/__tests__/chat-wrapper.spec.tsx b/web/app/components/base/chat/chat-with-history/__tests__/chat-wrapper.spec.tsx
index 93fe71e59e7..be62a5a2115 100644
--- a/web/app/components/base/chat/chat-with-history/__tests__/chat-wrapper.spec.tsx
+++ b/web/app/components/base/chat/chat-with-history/__tests__/chat-wrapper.spec.tsx
@@ -136,6 +136,9 @@ const defaultChatHookReturn: Partial<ChatHookReturn> = {
suggestedQuestions: [],
}
+const getChatInputDisabledSurface = (element: HTMLElement) =>
+ element.closest('.pointer-events-none.opacity-50')
+
describe('ChatWrapper', () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -327,7 +330,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textboxes = screen.getAllByRole('textbox')
const chatInput = textboxes[textboxes.length - 1]
- const disabledContainer = chatInput!.closest('.pointer-events-none')
+ const disabledContainer = getChatInputDisabledSurface(chatInput!)
expect(disabledContainer)!.toBeInTheDocument()
expect(disabledContainer)!.toHaveClass('opacity-50')
})
@@ -344,7 +347,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textboxes = screen.getAllByRole('textbox')
const chatInput = textboxes[textboxes.length - 1]
- const container = chatInput!.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(chatInput!)
expect(container).not.toBeInTheDocument()
})
@@ -368,7 +371,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textboxes = screen.getAllByRole('textbox')
const chatInput = textboxes[textboxes.length - 1]
- const container = chatInput!.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(chatInput!)
expect(container)!.toBeInTheDocument()
})
@@ -391,7 +394,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textarea = screen.getByRole('textbox')
- const container = textarea.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(textarea)
expect(container).not.toBeInTheDocument()
})
@@ -418,7 +421,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textboxes = screen.getAllByRole('textbox')
const chatInput = textboxes[textboxes.length - 1]
- const container = chatInput!.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(chatInput!)
expect(container)!.toBeInTheDocument()
})
@@ -444,7 +447,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textarea = screen.getByRole('textbox')
- const container = textarea.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(textarea)
expect(container).not.toBeInTheDocument()
})
@@ -463,7 +466,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textarea = screen.getByRole('textbox')
- const container = textarea.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(textarea)
expect(container)!.toBeInTheDocument()
})
@@ -479,7 +482,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textarea = screen.getByRole('textbox')
- const container = textarea.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(textarea)
expect(container).not.toBeInTheDocument()
})
@@ -1108,7 +1111,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textboxes = screen.getAllByRole('textbox')
const chatInput = textboxes[textboxes.length - 1]
- const container = chatInput!.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(chatInput!)
expect(container)!.toBeInTheDocument()
})
@@ -1250,7 +1253,7 @@ describe('ChatWrapper', () => {
// This tests line 106 - early return when hasEmptyInput is set
const textboxes = screen.getAllByRole('textbox')
const chatInput = textboxes[textboxes.length - 1]
- const container = chatInput!.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(chatInput!)
expect(container)!.toBeInTheDocument()
})
@@ -1278,7 +1281,7 @@ describe('ChatWrapper', () => {
// This tests line 109 - early return when fileIsUploading is set
const textboxes = screen.getAllByRole('textbox')
const chatInput = textboxes[textboxes.length - 1]
- const container = chatInput!.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(chatInput!)
expect(container)!.toBeInTheDocument()
})
@@ -1821,7 +1824,7 @@ describe('ChatWrapper', () => {
render(<ChatWrapper />)
const textboxes = screen.getAllByRole('textbox')
const chatInput = textboxes[textboxes.length - 1]
- const container = chatInput!.closest('.pointer-events-none')
+ const container = getChatInputDisabledSurface(chatInput!)
// Should not be disabled because it's not required
// Should not be disabled because it's not required
// Should not be disabled because it's not required
diff --git a/web/app/components/base/chat/chat/__tests__/index.spec.tsx b/web/app/components/base/chat/chat/__tests__/index.spec.tsx
index cfb19edd520..440022ff23e 100644
--- a/web/app/components/base/chat/chat/__tests__/index.spec.tsx
+++ b/web/app/components/base/chat/chat/__tests__/index.spec.tsx
@@ -955,6 +955,22 @@ describe('Chat', () => {
expect(screen.getByTestId('chat-footer')).toHaveClass('bg-chat-input-mask')
})
+ it('should let footer blank space pass pointer events through', () => {
+ renderChat({ noChatInput: false })
+ const footer = screen.getByTestId('chat-footer')
+ expect(footer).toHaveClass('pointer-events-none')
+ expect(footer.firstElementChild).toHaveClass('pointer-events-none')
+ })
+
+ it('should keep the stop responding button clickable inside the pass-through footer', () => {
+ renderChat({
+ isResponding: true,
+ noStopResponding: false,
+ noChatInput: true,
+ })
+ expect(screen.getByRole('button', { name: /stopResponding/i })).toHaveClass('pointer-events-auto')
+ })
+
it('should apply chatFooterClassName when footer has content', () => {
renderChat({
noChatInput: false,
diff --git a/web/app/components/base/chat/chat/chat-input-area/__tests__/index.spec.tsx b/web/app/components/base/chat/chat/chat-input-area/__tests__/index.spec.tsx
index a10b7652fdf..7fa4623b3a4 100644
--- a/web/app/components/base/chat/chat/chat-input-area/__tests__/index.spec.tsx
+++ b/web/app/components/base/chat/chat/chat-input-area/__tests__/index.spec.tsx
@@ -316,7 +316,12 @@ describe('ChatInputArea', () => {
it('should apply disabled styles when the disabled prop is true', () => {
const { container } = render(<ChatInputArea visionConfig={mockVisionConfig} disabled />)
- expect(container.firstChild).toHaveClass('opacity-50')
+ expect(container.firstChild).toHaveClass('pointer-events-none', 'opacity-50')
+ })
+
+ it('should restore pointer events on the input surface', () => {
+ const { container } = render(<ChatInputArea visionConfig={mockVisionConfig} />)
+ expect(container.firstChild).toHaveClass('pointer-events-auto')
})
it('should apply drag-active styles when a file is being dragged over', () => {
diff --git a/web/app/components/base/chat/chat/chat-input-area/index.tsx b/web/app/components/base/chat/chat/chat-input-area/index.tsx
index 1fbb779c5ee..a30dddd2b2b 100644
--- a/web/app/components/base/chat/chat/chat-input-area/index.tsx
+++ b/web/app/components/base/chat/chat/chat-input-area/index.tsx
@@ -164,7 +164,7 @@ const ChatInputArea = ({ readonly, botName, customPlaceholder, showFeatureBar, s
const operation = (<Operation ref={holdSpaceRef} readonly={readonly} fileConfig={visionConfig} speechToTextConfig={speechToTextConfig} onShowVoiceInput={handleShowVoiceInput} onSend={handleSend} sendButtonLabel={sendButtonLabel} disabled={!canSend} theme={theme} />)
return (
<>
- <div className={cn('relative z-10 overflow-hidden rounded-xl border border-components-chat-input-border bg-components-panel-bg-blur pb-[9px] shadow-md', isDragActive && 'border border-dashed border-components-option-card-option-selected-border', disabled && 'pointer-events-none border-components-panel-border opacity-50 shadow-none')}>
+ <div className={cn('pointer-events-auto relative z-10 overflow-hidden rounded-xl border border-components-chat-input-border bg-components-panel-bg-blur pb-[9px] shadow-md', isDragActive && 'border border-dashed border-components-option-card-option-selected-border', disabled && 'pointer-events-none border-components-panel-border opacity-50 shadow-none')}>
<div className="relative max-h-[158px] overflow-x-hidden overflow-y-auto px-[9px] pt-[9px]">
<FileListInChatInput fileConfig={visionConfig!} />
<div ref={wrapperRef} className="flex items-center justify-between">
@@ -201,7 +201,11 @@ const ChatInputArea = ({ readonly, botName, customPlaceholder, showFeatureBar, s
</div>
{isMultipleLine && (<div className="px-[9px]">{operation}</div>)}
</div>
- {showFeatureBar && (<FeatureBar showFileUpload={showFileUpload} disabled={featureBarDisabled} onFeatureBarClick={featureBarReadonly ? noop : onFeatureBarClick} hideEditEntrance={featureBarReadonly} />)}
+ {showFeatureBar && (
+ <div className="pointer-events-auto">
+ <FeatureBar showFileUpload={showFileUpload} disabled={featureBarDisabled} onFeatureBarClick={featureBarReadonly ? noop : onFeatureBarClick} hideEditEntrance={featureBarReadonly} />
+ </div>
+ )}
</>
)
}
diff --git a/web/app/components/base/chat/chat/index.tsx b/web/app/components/base/chat/chat/index.tsx
index db495386516..b48973c2963 100644
--- a/web/app/components/base/chat/chat/index.tsx
+++ b/web/app/components/base/chat/chat/index.tsx
@@ -219,17 +219,20 @@ const Chat: FC<ChatProps> = ({
</div>
<div
data-testid="chat-footer"
- className={`absolute bottom-0 z-10 flex justify-center bg-chat-input-mask ${(hasTryToAsk || !noChatInput || !noStopResponding) && chatFooterClassName}`}
+ className={cn(
+ 'pointer-events-none absolute bottom-0 z-10 flex justify-center bg-chat-input-mask',
+ (hasTryToAsk || !noChatInput || !noStopResponding) && chatFooterClassName,
+ )}
ref={chatFooterRef}
>
<div
ref={chatFooterInnerRef}
- className={cn('relative', chatFooterInnerClassName, isTryApp && 'px-0')}
+ className={cn('pointer-events-none relative', chatFooterInnerClassName, isTryApp && 'px-0')}
>
{
!noStopResponding && isResponding && (
<div data-testid="stop-responding-container" className="mb-2 flex justify-center">
- <Button className="border-components-panel-border bg-components-panel-bg text-components-button-secondary-text" onClick={onStopResponding}>
+ <Button className="pointer-events-auto border-components-panel-border bg-components-panel-bg text-components-button-secondary-text" onClick={onStopResponding}>
<div className="mr-[5px] i-custom-vender-solid-mediaAndDevices-stop-circle h-3.5 w-3.5" />
<span className="text-xs font-normal">{t('operation.stopResponding', { ns: 'appDebug' })}</span>
</Button>
diff --git a/web/app/components/base/chat/chat/try-to-ask.tsx b/web/app/components/base/chat/chat/try-to-ask.tsx
index a74b49fb51a..e6e9465e2f3 100644
--- a/web/app/components/base/chat/chat/try-to-ask.tsx
+++ b/web/app/components/base/chat/chat/try-to-ask.tsx
@@ -29,7 +29,7 @@ const TryToAsk: FC<TryToAskProps> = ({
size="small"
key={index}
variant="secondary-accent"
- className="mr-1 mb-1 last:mr-0"
+ className="pointer-events-auto mr-1 mb-1 last:mr-0"
onClick={() => onSend(suggestQuestion)}
>
{suggestQuestion}