11"use client" ;
22
3- import { BotIcon , ChevronDownIcon } from "lucide-react" ;
3+ import { BotIcon , ChevronDownIcon , XIcon } from "lucide-react" ;
44
5- import { type FC , forwardRef , useState , useEffect } from "react" ;
5+ import { type FC , forwardRef , useState , useEffect , useCallback } from "react" ;
66import { AssistantModalPrimitive } from "@assistant-ui/react" ;
77
88import { Thread } from "@/app/components/assistant-ui/thread" ;
@@ -30,6 +30,13 @@ export const AssistantModal: FC<AssistantModalProps> = ({
3030 isLoadingWelcome,
3131} ) => {
3232 const [ showBubble , setShowBubble ] = useState ( false ) ;
33+ // 受控状态:允许模态框内部的 X 按钮主动关闭窗口
34+ // issue #285: 原先只能靠 Trigger/点击外部/Esc 关闭,用户反馈不知道怎么关窗
35+ const [ open , setOpen ] = useState ( false ) ;
36+
37+ const handleCloseModal = useCallback ( ( ) => {
38+ setOpen ( false ) ;
39+ } , [ ] ) ;
3340
3441 useEffect ( ( ) => {
3542 // 检查本次访问是否已关闭过气泡
@@ -61,7 +68,7 @@ export const AssistantModal: FC<AssistantModalProps> = ({
6168 } ;
6269
6370 return (
64- < AssistantModalPrimitive . Root >
71+ < AssistantModalPrimitive . Root open = { open } onOpenChange = { setOpen } >
6572 < AssistantModalPrimitive . Anchor className = "aui-root aui-modal-anchor fixed right-4 bottom-4 size-14" >
6673 { /* 自定义气泡组件 */ }
6774 { showBubble && (
@@ -88,8 +95,18 @@ export const AssistantModal: FC<AssistantModalProps> = ({
8895 </ AssistantModalPrimitive . Anchor >
8996 < AssistantModalPrimitive . Content
9097 sideOffset = { 16 }
91- className = "aui-root aui-modal-content z-50 h-[500px] w-[400px] overflow-clip rounded-xl border bg-popover p-0 text-popover-foreground shadow-md outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-bottom-1/2 data-[state=closed]:slide-out-to-right-1/2 data-[state=closed]:zoom-out data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:slide-in-from-bottom-1/2 data-[state=open]:slide-in-from-right-1/2 data-[state=open]:zoom-in [&>.aui-thread-root]:bg-inherit"
98+ className = "aui-root aui-modal-content relative z-50 h-[500px] w-[400px] overflow-clip rounded-xl border bg-popover p-0 text-popover-foreground shadow-md outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-bottom-1/2 data-[state=closed]:slide-out-to-right-1/2 data-[state=closed]:zoom-out data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:slide-in-from-bottom-1/2 data-[state=open]:slide-in-from-right-1/2 data-[state=open]:zoom-in [&>.aui-thread-root]:bg-inherit"
9299 >
100+ { /* 右上角关闭按钮,issue #285:用户找不到关闭模态框的显式入口 */ }
101+ < button
102+ type = "button"
103+ onClick = { handleCloseModal }
104+ aria-label = "Close assistant"
105+ className = "aui-modal-close absolute top-2 right-2 z-10 inline-flex size-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
106+ >
107+ < XIcon className = "size-4" />
108+ < span className = "sr-only" > Close assistant</ span >
109+ </ button >
93110 < Thread
94111 errorMessage = { errorMessage }
95112 showSettingsAction = { showSettingsAction }
0 commit comments