Browse Source

fix: [Select] Fixed the problem that Select did not focus on the first item when searching after the focused item was changed (#1126)

YyumeiZhang 3 năm trước cách đây
mục cha
commit
640eb82381
1 tập tin đã thay đổi với 7 bổ sung1 xóa
  1. 7 1
      packages/semi-foundation/select/foundation.ts

+ 7 - 1
packages/semi-foundation/select/foundation.ts

@@ -544,9 +544,15 @@ export default class SelectFoundation extends BaseFoundation<SelectAdapter> {
     handleInputChange(sugInput: string) {
         // Input is a controlled component, so the value needs to be updated
         this._adapter.updateInputValue(sugInput);
-        const { options, isOpen } = this.getStates();
+        const { options, isOpen, focusIndex } = this.getStates();
         const { allowCreate, remote } = this.getProps();
 
+        // Hight first option when search
+        // if last focusIndex isn't first option, change focusIndex to 0(first option);
+        if (focusIndex !== 0) {
+            this._adapter.updateFocusIndex(0);
+        }
+
         let optionsAfterFilter = options;
         if (!remote) {
             // Filter options based on input