Skip to content

An AI-powered search engine with a generative UI

feat: add accordion behavior to ResearchProcessSection

Yoshiki Miura24432dbfb587
diff --git a/components/fetch-section.tsx b/components/fetch-section.tsx
index ce101430..67e503e7 100644
--- a/components/fetch-section.tsx
+++ b/components/fetch-section.tsx
@@ -74,7 +74,6 @@ export function FetchSection({
contentLength={contentLength}
status={displayStatus}
error={error}
- borderless={borderless}
/>
</div>
)
diff --git a/components/research-process-section.tsx b/components/research-process-section.tsx
index fd9eac0c..c1a2010c 100644
--- a/components/research-process-section.tsx
+++ b/components/research-process-section.tsx
@@ -1,5 +1,7 @@
'use client'
+import { useState } from 'react'
+
import { UseChatHelpers } from '@ai-sdk/react'
import type { UIDataTypes, UIMessage, UITools } from '@/lib/types/ai'
@@ -70,9 +72,29 @@ export function ResearchProcessSection({
}: Props) {
const allParts = partsOverride ?? (message.parts || [])
const segments = partsOverride ? [allParts] : splitByText(allParts)
+
+ // Track which section is open within grouped sections (accordion behavior)
+ const [openSectionId, setOpenSectionId] = useState<string | null>(null)
if (segments.length === 0) return null
+ // Handle accordion-style open/close for grouped sections
+ const handleAccordionChange = (id: string, open: boolean, isSingle: boolean) => {
+ if (isSingle) {
+ // For single sections, use the original behavior
+ onOpenChange(id, open)
+ } else {
+ // For grouped sections, implement accordion behavior
+ if (open) {
+ setOpenSectionId(id)
+ } else {
+ setOpenSectionId(null)
+ }
+ // Still notify parent for tracking purposes
+ onOpenChange(id, open)
+ }
+ }
+
return (
<div className="space-y-2">
{segments.map((seg, sidx) => {
@@ -94,12 +116,16 @@ export function ResearchProcessSection({
const hasNext = pidx < grp.length - 1
if (part.type === 'reasoning') {
const rid = `${messageId}-reasoning-${sidx}-${gidx}-${pidx}`
+ const isOpen = isSingle
+ ? getIsOpen(rid, 'reasoning', hasNext)
+ : openSectionId === rid
+
return (
<ReasoningSection
key={rid}
content={{ reasoning: part.text, isDone: !hasNext }}
- isOpen={getIsOpen(rid, 'reasoning', hasNext)}
- onOpenChange={open => onOpenChange(rid, open)}
+ isOpen={isOpen}
+ onOpenChange={open => handleAccordionChange(rid, open, isSingle)}
isSingle={isSingle}
isFirst={isFirstGroup && pidx === 0}
isLast={isLastGroup && pidx === grp.length - 1}
@@ -109,12 +135,16 @@ export function ResearchProcessSection({
if (part.type?.startsWith?.('tool-')) {
const id = part.toolCallId
+ const isOpen = isSingle
+ ? getIsOpen(id, part.type, hasNext)
+ : openSectionId === id
+
return (
<ToolSection
key={id}
tool={part}
- isOpen={getIsOpen(id, part.type, hasNext)}
- onOpenChange={open => onOpenChange(id, open)}
+ isOpen={isOpen}
+ onOpenChange={open => handleAccordionChange(id, open, isSingle)}
status={status}
addToolResult={addToolResult}
onQuerySelect={onQuerySelect}