Skip to content

Commit

Permalink
feat: optimize NoticeBar close (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziqisia authored Nov 21, 2024
1 parent dc4d2e9 commit a717540
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
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

0 comments on commit a717540

Please sign in to comment.