Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize NoticeBar close #294

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('NoticeBar actions', () => {
const closeIcon = container.querySelectorAll(`.${prefixCls}-icon-close`)[0];
userEvent.click(closeIcon);
expect(onClickRight.mock.calls.length).toBe(1);
expect(container.querySelectorAll(`.${prefix}`).length).toBe(0);
});

it('Should support using ref to update', () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/arcodesign/components/notice-bar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cls, removeElement, fadeColor, nextTick } from '@arco-design/mobile-utils';
import { cls, fadeColor, nextTick } from '@arco-design/mobile-utils';
import React, {
useRef,
forwardRef,
Expand Down Expand Up @@ -142,6 +142,7 @@ const NoticeBar = forwardRef((props: NoticeBarProps, ref: Ref<NoticeBarRef>) =>
const wrapRef = useRef<HTMLDivElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
const timerRef = useRef<number | null>(null);
const [visible, setVisible] = useState(true);
const [needMarquee, setNeedMarquee] = useState(false);
const extraClass = useMemo(() => {
const classList: string[] = [];
Expand Down Expand Up @@ -185,9 +186,8 @@ const NoticeBar = forwardRef((props: NoticeBarProps, ref: Ref<NoticeBarRef>) =>
}, [useRtl]);

function close() {
if (domRef.current) {
removeElement(domRef.current);
}
setVisible(false);
clear();
}

function handleClose(e: React.MouseEvent<HTMLDivElement, MouseEvent>) {
Expand Down Expand Up @@ -252,7 +252,7 @@ const NoticeBar = forwardRef((props: NoticeBarProps, ref: Ref<NoticeBarRef>) =>
}

function renderNoticeBar(prefix: string) {
return (
return visible ? (
<div
className={cls(prefix, className, extraClass)}
style={style}
Expand Down Expand Up @@ -281,7 +281,7 @@ const NoticeBar = forwardRef((props: NoticeBarProps, ref: Ref<NoticeBarRef>) =>
</div>
) : null}
</div>
);
) : null;
}

return (
Expand Down
Loading