Skip to content

Commit fc60073

Browse files
committed
fix: only mark hovered stacked notifications expanded
1 parent 5ddb565 commit fc60073

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/NotificationList/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
7676
const placementMotion = typeof motion === 'function' ? motion(placement) : motion;
7777
const [stackEnabled, { offset, threshold }] = useStack(stackConfig);
7878
const [listHovering, setListHovering] = React.useState(false);
79+
const stackCollapsed = stackEnabled && keys.length > threshold;
7980
const expanded = stackEnabled && (listHovering || keys.length <= threshold);
81+
const stackExpanded = stackCollapsed && listHovering;
8082
const stackPosition = React.useMemo<StackConfig | undefined>(() => {
8183
if (!stackEnabled || expanded) {
8284
return undefined;
@@ -123,7 +125,7 @@ const NotificationList: React.FC<NotificationListProps> = (props) => {
123125
className,
124126
{
125127
[`${prefixCls}-stack`]: stackEnabled,
126-
[`${prefixCls}-stack-expanded`]: expanded,
128+
[`${prefixCls}-stack-expanded`]: stackExpanded,
127129
},
128130
)}
129131
onMouseEnter={() => {

tests/stack.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ describe('stack', () => {
3333
}
3434
expect(document.querySelectorAll('.rc-notification-notice')).toHaveLength(3);
3535
expect(document.querySelector('.rc-notification-stack')).toBeTruthy();
36-
expect(document.querySelector('.rc-notification-stack-expanded')).toBeTruthy();
36+
expect(document.querySelector('.rc-notification-stack-expanded')).toBeFalsy();
37+
38+
fireEvent.mouseEnter(document.querySelector('.rc-notification-list'));
39+
expect(document.querySelector('.rc-notification-stack-expanded')).toBeFalsy();
40+
fireEvent.mouseLeave(document.querySelector('.rc-notification-list'));
3741

3842
for (let i = 0; i < 2; i++) {
3943
fireEvent.click(container.querySelector('button'));

0 commit comments

Comments
 (0)