Skip to content

Commit 989dfc5

Browse files
committed
fix: preserve zero notification offset
1 parent 777f878 commit 989dfc5

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/Notification.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
152152

153153
// ======================== Position ========================
154154
const offsetRef = React.useRef(offset);
155-
if (offset) {
155+
if (offset !== undefined) {
156156
offsetRef.current = offset;
157157
}
158158

@@ -209,7 +209,7 @@ const Notification = React.forwardRef<HTMLDivElement, NotificationProps>((props,
209209
...style,
210210
};
211211

212-
if (mergedOffset) {
212+
if (mergedOffset !== undefined) {
213213
mergedStyle['--notification-y'] = `${mergedOffset}px`;
214214
}
215215

tests/index.test.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fireEvent, render } from '@testing-library/react';
22
import React from 'react';
33
import { act } from 'react-dom/test-utils';
44
import type { NotificationAPI, NotificationConfig, NotificationProgressProps } from '../src';
5-
import { useNotification } from '../src';
5+
import { Notification, useNotification } from '../src';
66

77
require('../assets/index.less');
88

@@ -618,6 +618,22 @@ describe('Notification.Basic', () => {
618618
expect(document.querySelector('.rc-notification-notice')).toHaveClass('bamboo');
619619
});
620620

621+
it('should support zero offset', () => {
622+
const { container, rerender } = render(
623+
<Notification prefixCls="rc-notification" description="little" offset={10} />,
624+
);
625+
626+
expect(container.querySelector('.rc-notification-notice')).toHaveStyle({
627+
'--notification-y': '10px',
628+
});
629+
630+
rerender(<Notification prefixCls="rc-notification" description="little" offset={0} />);
631+
632+
expect(container.querySelector('.rc-notification-notice')).toHaveStyle({
633+
'--notification-y': '0px',
634+
});
635+
});
636+
621637
it('should not render section for single content node', () => {
622638
const { instance } = renderDemo();
623639

0 commit comments

Comments
 (0)