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

Suggestion list is removed when more than one dropdown is available #110

Open
lorenc-tomasz opened this issue Feb 29, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@lorenc-tomasz
Copy link

lorenc-tomasz commented Feb 29, 2024

Hi,
I have noticed issue with multiple dropdown when at least one of have onChangeText implemented and it changes parent's state.

  1. Add at least two dropdowns within the same component.
  2. Implement onChangeText that will set state e.g.
onChangeText={(text) => {
setState(text); 
}}
  1. Setting the state will cause re-render of component with dropdowns.
  2. This useEffect will be called for each dropdown:
    useEffect(() => {
      if (isOpened && Array.isArray(dataSet)) {
        if (activeInputRef) {
          activeInputRef.current = containerRef.current
        }

        setContent(
          <Dropdown
            {...{
              ...props,
              direction,
              inputHeight,
              dataSet,
              suggestionsListMaxHeight,
              renderItem,
              ListEmptyComponent
            }}
          />
        )
      } else {
        setContent(undefined)
      }
    }, [
      isOpened,
      dataSet,
      props,
      direction,
      inputHeight,
      suggestionsListMaxHeight,
      renderItem,
      ListEmptyComponent,
      activeInputRef,
      setContent
    ])
  1. As other dropdowns will not be openend the setContent(undefined) will be called and suggestion list will be hidden from the view.

  2. The easiest fix I have found was to add check to mentioned useEffect :

    const close = () => {
      setIsOpened(false)
      setDirection(props.direction)
      setContent(undefined)
      activeInputRef.current = null <-- reset active ref
    }

    useEffect(() => {
      // check if active ref is the correct one
      if (activeInputRef.current && activeInputRef.current !== containerRef.current) {
        return;
      }

      if (isOpened && Array.isArray(dataSet)) {
        if (activeInputRef) {
          activeInputRef.current = containerRef.current
        }

with this check useEffect will not be called for not active input.

Can you please look into this, please?

@harshilmobmaxime
Copy link

harshilmobmaxime commented Mar 28, 2024

@lorenc-tomasz all previous changes, change on node_modules/react-native-autocomplete-dropdown then run command "yarn patch-package react-native-autocomplete-dropdown" that can be work for me

@imarsiglia
Copy link

I have the same problem and need to use 5 Dropdowns in the same view. When searching in autocomplete the application becomes extremely slow and the list appears for a few seconds and then disappears. @lorenc-tomasz able to find any solution?

@onmotion onmotion added the bug Something isn't working label Mar 29, 2024
@vijayanandof
Copy link

@onmotion Any updates or work around for this bug?

@onmotion
Copy link
Owner

onmotion commented Oct 4, 2024

@vijayanandof I'll try to reproduce

onmotion added a commit that referenced this issue Oct 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants