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

fix: notice bar close and not propagate #6564

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/components/notice-bar/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ It is applicable to the notification of information in the current page, which i
| delay | Delay to start scrolling, unit `ms` | `number` | `2000` |
| extra | Additional operating area, displayed to the left of the close button | `React.ReactNode` | - |
| icon | Radio icon on the left | `React.ReactNode` | `<SoundOutline />` |
| onClose | Callback when closed | `() => void` | - |
| onClick | Click event | `() => void` | - |
| onClose | Callback when closed | `(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void` | - |
| onClick | Click event | `(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void` | - |
| speed | Scroll speed, unit `px/s` | `number` | `50` |
| wrap | Whether to display multiple lines | `boolean` | `false` |

Expand Down
4 changes: 2 additions & 2 deletions src/components/notice-bar/index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
| delay | 开始滚动的延迟,单位 `ms` | `number` | `2000` |
| extra | 额外操作区域,显示在关闭按钮左侧 | `React.ReactNode` | - |
| icon | 左侧广播图标 | `React.ReactNode` | `<SoundOutline />` |
| onClose | 关闭时的回调 | `() => void` | - |
| onClick | 点击事件 | `() => void` | - |
| onClose | 关闭时的回调 | `(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void` | - |
| onClick | 点击事件 | `(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void` | - |
| speed | 滚动速度,单位 `px/s` | `number` | `50` |
| wrap | 是否多行展示 | `boolean` | `false` |

Expand Down
8 changes: 4 additions & 4 deletions src/components/notice-bar/notice-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export type NoticeBarProps = {
/** Whether it can be closed */
closeable?: boolean
/** Callback when closed */
onClose?: () => void
onClose?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
/** Event when click */
onClick?: () => void
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
/** Additional operating area, displayed to the left of the close button */
extra?: ReactNode
/** Radio icon on the left */
Expand Down Expand Up @@ -144,9 +144,9 @@ export const NoticeBar = memo<NoticeBarProps>(p => {
{props.closeable && (
<div
className={`${classPrefix}-close`}
onClick={() => {
onClick={e => {
setVisible(false)
props.onClose?.()
props.onClose?.(e)
}}
>
<CloseOutline className={`${classPrefix}-close-icon`} />
Expand Down
19 changes: 15 additions & 4 deletions src/components/notice-bar/tests/notice-bar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ describe('NoticeBar', () => {
expect(renderer2.getByTestId('alert')).toHaveClass(`${classPrefix}-alert`)
})

test('can be close', async () => {
const fn = jest.fn()
test('can be close and not propagate', async () => {
const onClose = jest.fn()
const onClick = jest.fn()
const { getByTestId } = render(
<NoticeBar content='notice' closeable data-testid='notice' onClose={fn} />
<NoticeBar
content='notice'
closeable
data-testid='notice'
onClose={e => {
e.stopPropagation()
onClose()
}}
onClick={onClick}
/>
)

const el = getByTestId('notice')
Expand All @@ -35,7 +45,8 @@ describe('NoticeBar', () => {

fireEvent.click(iconEl)
expect(el).not.toBeInTheDocument()
expect(fn).toBeCalled()
expect(onClose).toBeCalled()
expect(onClick).not.toBeCalled()
})

test('`icon` prop', async () => {
Expand Down
Loading