-
-
Notifications
You must be signed in to change notification settings - Fork 464
fix: onSearch be call onBlur #1085
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
Closed
su-muzhi
wants to merge
9
commits into
react-component:master
from
su-muzhi:fix/onBlur-onSearch-once
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f325565
fix: onSearch be call onBlur
su-muzhi 567a898
tests: add test case
su-muzhi a47fa76
tests: update tests case
su-muzhi c4fd947
fix: onBlur should trigger blur when mode is null
su-muzhi 53fef45
test: add Select case
su-muzhi 4da3e29
Merge branch 'master' into fix/onBlur-onSearch-once
su-muzhi e57a56a
tests: fix mode is single but not correct behavior
su-muzhi 4402aa5
Merge remote-tracking branch 'origin/fix/onBlur-onSearch-once' into f…
su-muzhi 0152915
tests: clean repetition test case
su-muzhi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import type { OptionListProps, RefOptionListProps } from '@/OptionList'; | ||
import { fireEvent, render } from '@testing-library/react'; | ||
import { forwardRef } from 'react'; | ||
import BaseSelect from '../src/BaseSelect'; | ||
import Select, { Option } from '../src'; | ||
|
||
const OptionList = forwardRef<RefOptionListProps, OptionListProps>(() => ( | ||
<div className="popup">Popup</div> | ||
)); | ||
|
||
describe('Select.Blur', () => { | ||
it('mode with undefined, onBlur source is blur', () => { | ||
const onSearch = jest.fn(); | ||
const { container } = render( | ||
<BaseSelect | ||
prefixCls="rc-select" | ||
id="test" | ||
displayValues={[]} | ||
onDisplayValuesChange={() => {}} | ||
searchValue="1" | ||
showSearch | ||
onSearch={onSearch} | ||
OptionList={OptionList} | ||
emptyOptions | ||
/>, | ||
); | ||
expect(container.querySelector('div.rc-select')).toBeTruthy(); | ||
fireEvent.change(container.querySelector('input'), { target: { value: '2' } }); | ||
expect(onSearch).toHaveBeenCalledWith('2', { source: 'typing' }); | ||
fireEvent.blur(container.querySelector('div.rc-select')); | ||
expect(onSearch).toHaveBeenCalledWith('', { source: 'blur' }); | ||
}); | ||
|
||
it('mode with multiple, onBlur source is blur', () => { | ||
const onSearch = jest.fn(); | ||
const { container } = render( | ||
<BaseSelect | ||
prefixCls="rc-select" | ||
mode="multiple" | ||
id="test" | ||
displayValues={[]} | ||
onDisplayValuesChange={() => {}} | ||
searchValue="1" | ||
showSearch | ||
onSearch={onSearch} | ||
OptionList={OptionList} | ||
emptyOptions | ||
/>, | ||
); | ||
expect(container.querySelector('div.rc-select')).toBeTruthy(); | ||
fireEvent.change(container.querySelector('input'), { target: { value: '2' } }); | ||
expect(onSearch).toHaveBeenCalledWith('2', { source: 'typing' }); | ||
fireEvent.blur(container.querySelector('div.rc-select')); | ||
expect(onSearch).toHaveBeenCalledWith('', { source: 'blur' }); | ||
}); | ||
su-muzhi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
it('click item and blur should trigger onBlur but not trigger onSearch', () => { | ||
const onSearch = jest.fn(); | ||
const onBlur = jest.fn(); | ||
|
||
const Demo = () => ( | ||
<Select onSearch={onSearch} showSearch onBlur={onBlur}> | ||
<Option value="11">11</Option> | ||
<Option value="22">22</Option> | ||
<Option value="33">33</Option> | ||
</Select> | ||
); | ||
|
||
const { container } = render(<Demo />); | ||
const input = container.querySelector('input'); | ||
fireEvent.change(input, { target: { value: '1' } }); | ||
fireEvent.click( | ||
container.querySelectorAll('.rc-select-dropdown .rc-select-item-option-content')[0], | ||
); | ||
fireEvent.blur(input); | ||
expect(container.querySelector('.rc-select-dropdown-hidden')).toBeTruthy(); | ||
expect(onSearch).toHaveBeenCalledTimes(1); | ||
expect(onBlur).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.