Skip to content

Commit

Permalink
fix: (FormItem) help icon click stopPropagation (#6549)
Browse files Browse the repository at this point in the history
* fix: (FormItem) help icon click stopPropagation

* test: add test case

* chore: clean up

---------

Co-authored-by: 二货机器人 <[email protected]>
  • Loading branch information
damonyoungcc and zombieJ authored Feb 29, 2024
1 parent 5ebd04e commit 8468a08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/form/form-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const FormItemLayout: FC<FormItemLayoutProps> = props => {
<span
className={`${classPrefix}-label-help`}
onClick={e => {
e.stopPropagation()
e.preventDefault()
}}
>
Expand Down
24 changes: 24 additions & 0 deletions src/components/form/tests/form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,28 @@ describe('Form', () => {
expect(renderTimes).toEqual(1)
})
})

test('click help not propagate', () => {
jest.useFakeTimers()
const onClick = jest.fn()

const { container } = render(
<div onClick={onClick}>
<Form>
<Form.Item name='name' label='name' help='hello world'>
<Input />
</Form.Item>
</Form>
</div>
)

fireEvent.click(container.querySelector('.adm-form-item-label-help')!)

Check warning on line 348 in src/components/form/tests/form.test.tsx

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion
expect(onClick).not.toHaveBeenCalled()

// Click input
fireEvent.click(container.querySelector('input')!)

Check warning on line 352 in src/components/form/tests/form.test.tsx

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion
expect(onClick).toHaveBeenCalled()

jest.useRealTimers()
})
})

0 comments on commit 8468a08

Please sign in to comment.