JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q47246F
  • License MIT

React hook. Simple dropdown. (Lib)

Package Exports

  • react-dropdown-z
  • react-dropdown-z/build/index.esm.js
  • react-dropdown-z/build/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-dropdown-z) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-dropdown-z

react-dropdown-z

LIVE EXAMPLE

NPM JavaScript Style Guide Downloads


Description

  • Simple, quick dropdown (group) for react.

  • Append perfect scrollbar. (if need)

  • Support show top, hide, select empty...

  • Fit to window size if exceeding the height beyond the window.

  • Auto change show top or bootom.(if need).

  • Add tooltip if-need (rc-tc-ifn)

  • If you want more, please use react-select.


Usage

Install the package

// if use perfectScroll = true
// npm i --D react-perfect-scrollbar-z

npm i --D react-dropdown-z

Import the module in the place you want to use:

// if use perfectScroll = true
// import 'react-perfect-scrollbar-z/build/styles.css';

import "react-dropdown-z/build/styles.css";
import Dropdown from "react-dropdown-z";

Snippet

    const [value, setValue] = React.useState();

    // flat options
    const options = [ "o1", "tw2", "th3", "f4" ];

    <Dropdown
      // placeholder="Abcd"
      options={options}
      width="200px"
      perfectScroll // if need
      // heightDropdown="100px" // fit with window
      value={value}
      handleSelection={setValue}
      showTop
    />

    // Object array
    // keyName and labelName
    const options2 = [
      // { dsds: 'dsd' }, // => please set key and value
      {
        val: 0,
        text: 'this one',
      },
      {
        val: 2,
        text: 'this one 2',
      },
      {
        val: 3,
        text: 'this one 3',
        className: 'class-3'
      },
      {
        val: 10,
        text: 'this one 10',
        disabled: true
      },

      // group
      {
        isGroup: true,
        groupName: 'group a',
        className: 'groupclass'
        items: [
          {
            val: 4,
            text: 'this one 4',
          },
        ],
      },
    ]

    <Dropdown
      // placeholder="Abcd"
      keyName="val"  // only set when array option is object
      labelName="text" // only set when array option is object
      options={options2}
      width="200px"
      value={value}
      handleSelection={setValue}
      // showTop
      // resizeClose={false}
    />

props

Prop Name Type Description
className string? 'Custom class for the main component'
arrowClassName string? Class for arrow icon
groupItemClassName string? Class for grouped items
dropdownClassName string? Class for dropdown menu
placeholderClassName string? Class for placeholder text
showTop boolean? Show dropdown above instead of below
options any[] Array of selectable options
keyName string? Key field name in option objects
labelName string? Label field name in option objects
value string / number / null Currently selected value
customizeArrow string / React.ReactNode? Custom arrow icon or element
placeholder string? Text to display when no selection
noDataMessage string? Message shown when options are empty
width string / number? Width of the component
height string / number? Height of the component
perfectScroll boolean? Use Perfect Scrollbar if true
tabIndex number? Tab index for focus management
disabled boolean? Disable the dropdown
heightDropdown string / number? Height of the dropdown list
open boolean? Control dropdown visibility externally
keepScrollPosition boolean? Maintain scroll position on open (default: true)
resizeClose boolean? Auto-close on resize (default: true)
tooltipIfProps tooltipProps? Tooltip props if enabled
handleSelection (value, selectItem?) => any Callback when item is selected
handleShown () => void Callback when dropdown is shown
handleHidden () => void Callback when dropdown is hidden

Note

tooltipIfProps: react-tooltip-z / rc-tc-ifn

RUN

LIVE EXAMPLE


License

MIT