-
Notifications
You must be signed in to change notification settings - Fork 52
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: Do not respond to the Enter event when data is loading #257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ export interface MentionsProps extends BaseTextareaAttrs { | |
prefix?: string | string[]; | ||
prefixCls?: string; | ||
value?: string; | ||
silent?: boolean; | ||
filterOption?: false | typeof defaultFilterOption; | ||
validateSearch?: typeof defaultValidateSearch; | ||
onChange?: (text: string) => void; | ||
|
@@ -101,6 +102,7 @@ const InternalMentions = forwardRef<MentionsRef, MentionsProps>( | |
options, | ||
open, | ||
allowClear, | ||
silent, | ||
|
||
// Events | ||
validateSearch = defaultValidateSearch, | ||
|
@@ -330,6 +332,11 @@ const InternalMentions = forwardRef<MentionsRef, MentionsProps>( | |
} else if (which === KeyCode.ENTER) { | ||
// Measure hit | ||
event.preventDefault(); | ||
// loading skip | ||
if (silent) { | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 需要 stopMeasure 么? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 应该不用吧 这里关掉的话 就需要重新输入才会搜索了(input 里的text就不完整了) |
||
|
||
if (!mergedOptions.length) { | ||
stopMeasure(); | ||
return; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,15 +40,15 @@ describe('Mentions', () => { | |
return render(createMentions(props)); | ||
} | ||
|
||
describe('focus test', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 把下面的 beforeEach 和 afterEach 挪上来把,反正也是 fakeTimer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
done |
||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
describe('focus test', () => { | ||
it('autoFocus', () => { | ||
const { container } = renderMentions({ autoFocus: true }); | ||
expect(document.activeElement).toBe(container.querySelector('textarea')); | ||
|
@@ -135,6 +135,24 @@ describe('Mentions', () => { | |
}); | ||
expect(onChange).toHaveBeenCalledWith('bamboo'); | ||
}); | ||
|
||
it('Keyboard Enter event', () => { | ||
const { container, rerender } = renderMentions(); | ||
simulateInput(container, '@lig'); | ||
fireEvent.keyDown(container.querySelector('textarea'), { | ||
which: KeyCode.ENTER, | ||
keyCode: KeyCode.ENTER, | ||
}); | ||
expect(container.querySelector('textarea').value).toBe('@light '); | ||
|
||
rerender(createMentions({ silent: true })); | ||
simulateInput(container, '@lig'); | ||
fireEvent.keyDown(container.querySelector('textarea'), { | ||
which: KeyCode.ENTER, | ||
keyCode: KeyCode.ENTER, | ||
}); | ||
expect(container.querySelector('textarea').value).toBe('@lig'); | ||
}); | ||
}); | ||
|
||
describe('support children Option', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
怎么改成 silent 了?不是 loading 么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loading 是 antd 中的,rc-mentions 里是没有 loading 态的