11import type { CSSProperties , FC } from 'react' ;
2- import React , { useContext , useRef , useState } from 'react' ;
2+ import React , { useContext , useEffect , useRef , useState } from 'react' ;
33import clsx from 'classnames' ;
44import type { CSSMotionProps } from 'rc-motion' ;
55import { CSSMotionList } from 'rc-motion' ;
@@ -47,7 +47,7 @@ const NoticeList: FC<NoticeListProps> = (props) => {
4747
4848 const dictRef = useRef < Record < React . Key , HTMLDivElement > > ( { } ) ;
4949 const [ latestNotice , setLatestNotice ] = useState < HTMLDivElement > ( null ) ;
50- const [ hoverCount , setHoverCount ] = useState ( 0 ) ;
50+ const [ hoverKeys , setHoverKeys ] = useState < React . Key [ ] > ( [ ] ) ;
5151
5252 const keys = configList . map ( ( config ) => ( {
5353 config,
@@ -56,10 +56,19 @@ const NoticeList: FC<NoticeListProps> = (props) => {
5656
5757 const [ stack , { offset, threshold, gap } ] = useStack ( stackConfig ) ;
5858
59- const expanded = stack && ( hoverCount > 0 || keys . length <= threshold ) ;
59+ const expanded = stack && ( hoverKeys . length > 0 || keys . length <= threshold ) ;
6060
6161 const placementMotion = typeof motion === 'function' ? motion ( placement ) : motion ;
6262
63+ // Clean hover key
64+ useEffect ( ( ) => {
65+ if ( hoverKeys . length > 1 ) {
66+ setHoverKeys ( ( prev ) =>
67+ prev . filter ( ( key ) => keys . some ( ( { key : dataKey } ) => key === dataKey ) ) ,
68+ ) ;
69+ }
70+ } , [ hoverKeys , keys ] ) ;
71+
6372 return (
6473 < CSSMotionList
6574 key = { placement }
@@ -127,8 +136,10 @@ const NoticeList: FC<NoticeListProps> = (props) => {
127136 ...stackStyle ,
128137 ...configStyle ,
129138 } }
130- onMouseEnter = { ( ) => setHoverCount ( ( c ) => c + 1 ) }
131- onMouseLeave = { ( ) => setHoverCount ( ( c ) => c - 1 ) }
139+ onMouseEnter = { ( ) =>
140+ setHoverKeys ( ( prev ) => ( prev . includes ( key ) ? prev : [ ...prev , key ] ) )
141+ }
142+ onMouseLeave = { ( ) => setHoverKeys ( ( prev ) => prev . filter ( ( k ) => k !== key ) ) }
132143 >
133144 < Notice
134145 { ...config }
@@ -145,7 +156,7 @@ const NoticeList: FC<NoticeListProps> = (props) => {
145156 key = { key }
146157 eventKey = { key }
147158 onNoticeClose = { onNoticeClose }
148- hovering = { hoverCount > 0 }
159+ hovering = { hoverKeys . length > 0 }
149160 />
150161 </ div >
151162 ) ;
0 commit comments