Skip to content
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

[BUG] Select 远程搜索,搜索之后,点击选项会多触发一次 search 函数 #2678

Open
1 task done
DaiQiangReal opened this issue Jan 20, 2025 · 0 comments
Open
1 task done

Comments

@DaiQiangReal
Copy link
Collaborator

Is there an existing issue for this?

  • I have searched the existing issues

Which Component

Select

Semi Version

latest

Current Behavior

搜索之后,点击选项

Image

Expected Behavior

只在用户输入时触发搜索

Steps To Reproduce

import React from 'react';
import { debounce } from 'lodash-es';
import { Select } from '@douyinfe/semi-ui';
() => {
    const [loading, setLoading] = useState(false);
    const optionList = [
        { value: 'douyin', label: '抖音', type: 1 },
        { value: 'xingtu', label: '醒图', type: 2 },
        { value: 'jianying', label: '剪映', type: 3 },
        { value: 'toutiao', label: '今日头条', type: 4 },
    ];
    const [list, setList] = useState(optionList);
    const [value, setValue] = useState('');

    const handleMultipleChange = newValue => {
        setValue(newValue);
    };

    const handleSearch = inputValue => {
        setLoading(true);
        console.log('======')
        let result = [];
        if (inputValue) {
            let length = Math.ceil(Math.random() * 100);
            result = Array.from({ length }, (v, i) => {
                return { value: inputValue + i, label: `相近业务 ${inputValue}${i}`, type: i + 1 };
            });
            setTimeout(() => {
                setLoading(false);
                setList(result);
            }, 1000);
        } else {
            setLoading(false);
        }
    };

    return (
        <Select
            style={{ width: 300 }}
            filter
            remote
            onChangeWithObject
            multiple
            value={value}
            onSearch={debounce(handleSearch, 1000)}
            optionList={list}
            loading={loading}
            onChange={handleMultipleChange}
            emptyContent={null}
        />
    );
};

ReproducibleCode

Environment

- OS:
- browser:

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant