Skip to content

Commit 674b154

Browse files
committed
fix: reset hoverIndex when popup is close
1 parent 78997ac commit 674b154

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/components/select/hooks/useKeyboardControl.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { useState, useRef, useEffect } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22

33
import useConfig from '../../hooks/useConfig';
44
import { getSelectValueArr } from '../util/helper';
55

6-
import type { SelectOption, TdOptionProps, SelectValueChangeTrigger, SelectValue } from '../type';
6+
import type { SelectOption, SelectValue, SelectValueChangeTrigger, TdOptionProps } from '../type';
77

88
export type useKeyboardControlType = {
99
max: number;
@@ -63,11 +63,17 @@ export default function useKeyboardControl({
6363
}
6464
};
6565

66+
useEffect(() => {
67+
if (!innerPopupVisible) {
68+
changeHoverIndex(-1);
69+
}
70+
}, [innerPopupVisible]);
71+
6672
useEffect(() => {
6773
changeHoverOption(hoverIndex === -1 ? undefined : displayOptions[hoverIndex]);
6874
}, [hoverIndex, displayOptions]);
6975

70-
const handleKeyDown = (_value, { e }: { e: React.KeyboardEvent<HTMLInputElement> }) => {
76+
const handleKeyDown = (_value: string, { e }: { e: React.KeyboardEvent<HTMLInputElement> }) => {
7177
const optionsListLength = displayOptions.length;
7278

7379
let newIndex = hoverIndex;

0 commit comments

Comments
 (0)