npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dependent-dropdowns-utils

v2.0.2

Published

Allows users to select multiple options from a dropdown list which are interdependent to each other. The available options in drop-downs are dynamically updated based on the values selected in all the drop-downs, creating a dependency relationship between

Downloads

483

Readme

dependent-dropdowns-utils

Allows users to select multiple options from a dropdown list which are interdependent to each other. The available options in drop-downs are dynamically updated based on the values selected in all the drop-downs, creating a dependency relationship between the drop-downs.

dependent-dropdowns-utils provide a convenient way to handle complex data structures and allow users to select multiple options while ensuring that the available options in subsequent drop-downs are updated accordingly. They enhance the user experience by providing a more intuitive and streamlined interface, reducing manual input and potential errors.

By incorporating dependent-dropdowns-utils in your application, you can create a more interactive and efficient user interface for managing complex selections and dependencies, providing a better overall user experience.

Introduction

This type of dropdown is commonly used when there is a hierarchical or dependent relationship between the options. For example, imagine a scenario where the drop-downs represents a list of regions, countries, cities and population, and the drop-downs should display the countries, cities and population corresponding to the selected region. As the user selects different regions, the options in the drop-downs should change to reflect the countries, cities and populations associated with the selected region. Similarly, the drop-downs should display the regions, countries, and populations corresponding to the selected city.

Overview

-This package has two functions "getOptionsAfterClick" and "getOptionsBeforeClick". -Both functions return the options list based on values selected in drop-downs. -The state that saves the selected dropdown values should have the same naming convention as the options data. -This package works for both multi-select and single-select drop-downs

const [selectedOptions, setSelectedOptions] = React.useState({
  region: [],
  country: [],
  city: [],
  population: null, //null is for single select dropdowns,
});

const OptionsDataArray = [
  { region: "a", country: "a1", city: "a11", population: "10" },
  { region: "a", country: "a1", city: "a12", population: "20" },
  { region: "a", country: "a1", city: "a13", population: "10" },
  { region: "a", country: "a2", city: "a21", population: "10" },
  { region: "a", country: "a2", city: "a22", population: "20" },
  { region: "a", country: "a2", city: "a23", population: "10" },
  { region: "b", country: "b1", city: "b11", population: "10" },
  { region: "b", country: "b1", city: "b12", population: "20" },
  { region: "b", country: "b1", city: "b13", population: "20" },
  { region: "b", country: "b2", city: "b21", population: "10" },
  { region: "b", country: "b2", city: "b22", population: "10" },
  { region: "b", country: "b2", city: "b23", population: "20" },
];

here the state object property names are the same as the property names in OptionsDataArray

getOptionsAfterClick

getOptionsAfterClick will give the list of options for the dropdown on which the user clicks, Also it will give a list of options to a dropdown based on the values selected in other drop-downs. This is the recommended function to use if your dropdown supports getting an options list on click of it since it has less time complexity.

Click here to see the Example for getOptionsAfterClick

getOptionsBeforeClick

getOptionsBeforeClick will give the list of options for all the dropdowns and display it when the user clicks on any dropdown or selects any option from any dropdown, returning a new set of options list.

Click here to see the Example for getOptionsBeforeClick