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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@iazadur/hierarchical-select

v1.0.1

Published

A modern React component for hierarchical/dependent dropdowns with Ant Design and Shadcn UI support

Downloads

5

Readme

Hierarchical Select

📖 Live Documentation & Demos

Check out our interactive component documentation to see live examples and explore all features.

✨ Features

  • Hierarchical Dependency: Support for up to 5 select fields with parent-child relationships
  • Single and Multiple Select: Configure fields for single or multiple selection
  • Dynamic Loading: Load options statically or fetch dynamically from APIs
  • Design System Integration: Seamless integration with both Ant Design and Shadcn UI
  • Fully Customizable: Customize labels, placeholders, error messages, and styling
  • TypeScript Support: Fully typed with comprehensive type definitions
  • Accessibility: WAI-ARIA compliant with keyboard navigation support
  • Performance Optimized: Memoization, lazy loading, and response caching

🚀 Installation

npm install @iazadur/hierarchical-select

# Peer dependencies
npm install react react-dom

With Ant Design

npm install antd

With Shadcn UI

npm install @radix-ui/react-select

💻 Basic Usage

import React from "react";
import HierarchicalSelect from "@iazadur/hierarchical-select";

const App = () => {
  const fields = [
    {
      index: 0,
      options: [
        { value: "us", label: "United States" },
        { value: "ca", label: "Canada" },
        { value: "uk", label: "United Kingdom" },
      ],
      placeholder: "Select Country",
      label: "Country",
    },
    {
      index: 1,
      options: [],
      placeholder: "Select Region",
      label: "Region",
      fetchOptions: async (parentValue) => {
        // Fetch regions based on selected country
        // Simulated API call with static data
        await new Promise((resolve) => setTimeout(resolve, 500));

        const regions = {
          us: [
            { value: "ca", label: "California" },
            { value: "ny", label: "New York" },
          ],
          ca: [
            { value: "on", label: "Ontario" },
            { value: "qc", label: "Quebec" },
          ],
          uk: [
            { value: "eng", label: "England" },
            { value: "sct", label: "Scotland" },
          ],
        };

        return regions[parentValue] || [];
      },
    },
    {
      index: 2,
      options: [],
      placeholder: "Select City",
      label: "City",
      multiple: true, // Allow multiple selections
      fetchOptions: async (parentValue) => {
        // Fetch cities based on selected region
        await new Promise((resolve) => setTimeout(resolve, 500));

        const cities = {
          ca: [
            { value: "sf", label: "San Francisco" },
            { value: "la", label: "Los Angeles" },
          ],
          ny: [
            { value: "nyc", label: "New York City" },
            { value: "buf", label: "Buffalo" },
          ],
          // ... more cities
        };

        return cities[parentValue] || [];
      },
    },
  ];

  return (
    <HierarchicalSelect
      fields={fields}
      designSystem="shadcn" // or "antd"
      onChange={(values) => console.log("Selected:", values)}
      onError={(error) => console.error("Error:", error)}
    />
  );
};

export default App;

🎨 Custom Styling

The component supports custom styling to match your application design. You can add custom styles to each field:

<HierarchicalSelect
  fields={[
    {
      index: 0,
      options: [...],
      // Custom styling
      className: 'my-custom-field',
      customStyle: {
        background: '#f8fafc',
        padding: '12px',
        borderRadius: '8px'
      },
      // Style just the select element
      selectClassName: 'my-custom-select',
      selectStyle: { borderWidth: '2px' }
    },
    // ...more fields
  ]}
  designSystem="shadcn"
/>

📝 API Reference

HierarchicalSelect Props

| Property | Type | Default | Description | | ------------ | --------------------------------------------------------------- | -------- | -------------------------------------- | | fields | FieldConfig[] | required | Array of field configurations | | designSystem | 'antd' | 'shadcn' | 'antd' | The design system to use | | onChange | (values: (string | number | (string | number)[])[] ) => void | - | Callback when any value changes | | onError | (error: Error) => void | - | Callback for handling errors | | className | string | '' | Additional CSS class for the container | | disabled | boolean | false | Disables all fields |

FieldConfig Interface

| Property | Type | Default | Description | | --------------- | ----------------------------------------------------------- | -------------------- | ---------------------------------------- | | index | number | required | The position of the field (0-based) | | options | { value: string | number; label: string }[] | required | Static options for the field | | multiple | boolean | false | Whether multiple selections are allowed | | placeholder | string | 'Select an option' | Placeholder text | | label | string | Level ${index + 1} | Label for the field | | fetchOptions | (parentValue: any) => Promise<OptionType[]> | OptionType[] | - | Function to fetch dependent options | | disabled | boolean | false | Disables the specific field | | errorMessage | string | - | Custom error message | | className | string | - | Custom CSS class for the field container | | customStyle | React.CSSProperties | - | Custom styles for the field container | | selectClassName | string | - | Custom CSS class for the select element | | selectStyle | React.CSSProperties | - | Custom styles for the select element |

👍 Design System Support

Ant Design

The component integrates seamlessly with Ant Design, using the official Select component with proper styling and error states.

Shadcn UI

For Shadcn UI, we've built a custom implementation based on Radix UI's primitives that follows Shadcn's design principles, with:

  • Clean, minimal styling
  • Proper focus and hover states
  • Accessible keyboard navigation
  • Elegant tags for multiple selection
  • Error and loading states

🧩 Browser Support

  • Chrome (latest 2 versions)
  • Firefox (latest 2 versions)
  • Safari (latest 2 versions)
  • Edge (latest 2 versions)

🛠️ Troubleshooting

If you encounter any issues with the component, please check our GitHub issues or submit a new one.

📚 Documentation

For more examples and detailed documentation, visit our Storybook site.

📄 License

MIT © iazadur