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

Incorrect useSelect types #271

Open
joe223 opened this issue Aug 8, 2024 · 2 comments
Open

Incorrect useSelect types #271

joe223 opened this issue Aug 8, 2024 · 2 comments

Comments

@joe223
Copy link

joe223 commented Aug 8, 2024

Describe the bug

type declaration in src/index.d.ts

export function useSelect(Options: {
    defaultValue?: string | string[];
    value?: string | string[];
    multiple?: boolean;
    search?: boolean;
    options?: SelectSearchOption[];
    onChange?: (
        selectedValue: SelectedOptionValue | SelectedOptionValue[],
        selectedOption: SelectedOption | SelectedOption[],
        optionSnapshot: SelectSearchProps,
    ) => void;
    getOptions?: (query: string) => Promise<SelectSearchOption[]>;
    useFuzzySearch?: boolean;
    filterOptions?: ((
        options: SelectSearchOption[],
        query: string,
    ) => SelectSearchOption[])[];
    allowEmpty?: boolean;
    closeOnSelect?: boolean;
    closable?: boolean;
    debounce?: number;
}): [
    Snapshot,
    {
        tabIndex: string;
        readOnly: boolean;
-      onChange: (
-          selectedValue: SelectedOptionValue | SelectedOptionValue[],
-           selectedOption: SelectedOption | SelectedOption[],
-           optionSnapshot: SelectSearchProps,
-       ) => void;
        disabled: boolean;
        onMouseDown: (event: MouseEvent) => void;
        onKeyDown: (event: KeyboardEvent) => void;
        onKeyUp: (event: KeyboardEvent) => void;
        onKeyPress: (event: KeyboardEvent) => void;
        onBlur: () => void;
        onFocus: () => void;
        ref: MutableRefObject<any>;
    },

but in src/useSelect.js

    const valueProps = {
        tabIndex: '0',
        readOnly: !search,
        placeholder,
        value: focus && search ? q : snapshot.displayValue,
        ref,
        ...keyHandlers,
        onFocus: (e) => {
            setFocus(true);
            onFocus(e);
        },
        onBlur: (e) => {
            setFocus(false);
            setSearch('');
            setHighlighted(-1);
            onBlur(e);
        },
        onMouseDown: (e) => {
            if (focus) {
                e.preventDefault();
                ref.current.blur();
            }
        },
+       onChange: search
+           ? ({ target }) => setSearch(target.value)
+           : null,
    };

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@joe223
Copy link
Author

joe223 commented Aug 9, 2024

placeholder also has a problem.

I was wondering if we could rewrite it using TypsScript, so that all type declarations could be generated by tsc.

@AlreNux
Copy link

AlreNux commented Aug 27, 2024

placeholder also has a problem.

I was wondering if we could rewrite it using TypsScript, so that all type declarations could be generated by tsc.

I think you should rewrite your project on TS, because now when you use useSelect (according to the example from ReadMe) or SelectSearch - you get typing errors immediately. That would be nice...

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

2 participants