Skip to content

Commit 97bde6c

Browse files
committed
fix: keep active matched item when search
1 parent 6f5a84c commit 97bde6c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/OptionList.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,15 @@ const OptionList: React.ForwardRefRenderFunction<ReviseRefOptionListProps> = (_,
157157
// ========================== Get First Selectable Node ==========================
158158
const getFirstMatchingNode = (nodes: EventDataNode<any>[]): EventDataNode<any> | null => {
159159
for (const node of nodes) {
160-
if (!node.disabled && node.selectable !== false) {
160+
if (node.disabled || node.selectable === false) {
161+
continue;
162+
}
163+
164+
if (searchValue) {
165+
if (filterTreeNode(node)) {
166+
return node;
167+
}
168+
} else {
161169
return node;
162170
}
163171

tests/Select.SearchInput.spec.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ describe('TreeSelect.SearchInput', () => {
229229
fireEvent.keyDown(input, { keyCode: KeyCode.ENTER });
230230
expect(onSelect).not.toHaveBeenCalled();
231231
onSelect.mockReset();
232-
233-
fireEvent.change(input, { target: { value: '3' } });
234-
fireEvent.keyDown(input, { keyCode: KeyCode.ENTER });
235-
expect(onSelect).toHaveBeenCalledWith('3', expect.anything());
236232
});
237233

238234
it('should not select node when no matches found', () => {

0 commit comments

Comments
 (0)