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

@zendeskgarden/react-dropdowns

v9.4.0

Published

Components relating to dropdowns in the Garden Design System

Downloads

683,376

Readme

@zendeskgarden/react-dropdowns npm version

This package includes components relating to dropdowns in the Garden Design System.

Installation

npm install @zendeskgarden/react-dropdowns

# Peer Dependencies - Also Required
npm install react react-dom styled-components @zendeskgarden/react-theming

Basic Example

import { ThemeProvider } from '@zendeskgarden/react-theming';
import { Dropdown, Menu, Item, Trigger } from '@zendeskgarden/react-dropdowns';

/**
 * Place a `ThemeProvider` at the root of your React application
 */
<ThemeProvider>
  <Dropdown onSelect={value => console.log(`Selected: ${value}`)}>
    <Trigger>
      <button>This triggers a menu</button>
    </Trigger>
    <Menu placement="end" hasArrow>
      <Item value="option-1">Option 1</Item>
      <Item value="option-2">Option 2</Item>
      <Item value="option-3">Option 3</Item>
    </Menu>
  </Dropdown>
</ThemeProvider>;

For all components within the react-dropdowns package, the menu layouts and implementations are interchangeable.

Whether you're making a Select, Autocomplete, or a traditional Menu the <Menu> implementation will adapted to its consumer.

Usage

Overview

The react-dropdowns package abstracts the common concepts of Menus, Selects, and Autocompletes into a common API. This includes consistent visuals, common keyboard interaction, and a fully accessible experience for sighted and non-sighted users.

The customizations available within this can be broken into two groups: placement / positioning and dropdown state

Placement / Positioning

Internally, the <Dropdown> component uses PopperJS for its positioning calculations.

The <Menu> component accepts all customizations regarding placement, boundaries, overflows, etc. via the popperModifiers prop.

/** Customize default overflow settings to position against the `viewport` */
<Menu popperModifiers={{ preventOverflow: { boundariesElement: 'viewport' } }}>
  <Item value="item-1">Item 1</Item>
  <Item value="item-2">Item 2</Item>
  <Item value="item-3">Item 3</Item>
</Menu>

Dropdown State

We use the Downshift render-prop library to handle our keyboard and accessibility logic.

The following states can be controlled directly from the <Dropdown> component:

  • isOpen Whether the dropdown is currently open
  • highlightedIndex Which index is currently highlighted
  • inputValue The value of the input when it's used as an Autocomplete
  • selectedItem The currently selected item
  • selectedItems The currently selected items

All other customizations may be provided directly to the Downshift provider via the downshiftProps prop.

Downshift provides several advanced customization features that can be very helpful when customizing this component. The stateReducer pattern is a common customization strategy.

Server Side Rendering

If you are using server side rendering you may need to configure specific Downshift settings. This package re-exports the Downshift resetIdCounter utility. It allows resetting the internal id counter which is used to generate unique ids for Downshift.