Giter Club home page Giter Club logo

Comments (3)

davidrojo avatar davidrojo commented on May 26, 2024

I think this is the same issue but has no answers: #1117

from react-widgets.

jquense avatar jquense commented on May 26, 2024

That's not how a drop-down works generally, the text inputs is just for filtering it's not the "value" of the drop-down. The filter input is empty when you focus the input. If you want to control what the starting search term is you can control and provide the searchTerm prop

from react-widgets.

davidrojo avatar davidrojo commented on May 26, 2024

Thanks, that is what I was looking for. A little bit of state management and I've been able to accomplish what I needed.

For those in the same situation, What I've done is maintain the searchTerm in a state variable, and update it on onSearch. Also added a useEffect when the DropdownList is open to establish again the filter, as when the DropdownList closes it sets the filter to empty string.

  // defaultFilter is a variable with the filter I want to be shown on open. 
  // When a value is selected in the dropdown I update defaultFilter to the new value, so on open, the new value is used as filter
  const [filter, setFilter] = useState(defaultFilter);
  const [isOpen, setIsOpen] = useState(false);

  useEffect(() => {
    if (isOpen) {
      setFilter(defaultFilter);
    }
  }, [isOpen]);

  return (
    <DropdownList
      onSearch={ search => { setFilter(search); } }
      searchTerm={ isOpen ? filter : '' }
      onToggle={ isOpen => setIsOpen(isOpen) }
      ....
    />

from react-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.