![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@zendeskgarden/react-dropdowns
Advanced tools
Components relating to dropdowns in the Garden Design System
@zendeskgarden/react-dropdowns is a React component library that provides a set of accessible and customizable dropdown components. These components are designed to be used in building user interfaces that require dropdown functionality, such as select menus, autocomplete inputs, and more.
Select Dropdown
The Select Dropdown feature allows users to choose from a list of options. The code sample demonstrates how to create a dropdown with three options using the Dropdown, Select, and Item components.
import { Dropdown, Select, Item } from '@zendeskgarden/react-dropdowns';
const Example = () => (
<Dropdown>
<Select>
Select an option
</Select>
<Item value="option-1">Option 1</Item>
<Item value="option-2">Option 2</Item>
<Item value="option-3">Option 3</Item>
</Dropdown>
);
Autocomplete Input
The Autocomplete Input feature provides a text input that suggests options as the user types. The code sample shows how to implement an autocomplete input with three fruit options.
import { Dropdown, Autocomplete, Item } from '@zendeskgarden/react-dropdowns';
const Example = () => (
<Dropdown>
<Autocomplete placeholder="Type to search...">
<Item value="apple">Apple</Item>
<Item value="banana">Banana</Item>
<Item value="orange">Orange</Item>
</Autocomplete>
</Dropdown>
);
Multiselect Dropdown
The Multiselect Dropdown feature allows users to select multiple options from a list. The code sample illustrates how to create a multiselect dropdown with three options.
import { Dropdown, Multiselect, Item } from '@zendeskgarden/react-dropdowns';
const Example = () => (
<Dropdown>
<Multiselect placeholder="Select options">
<Item value="option-1">Option 1</Item>
<Item value="option-2">Option 2</Item>
<Item value="option-3">Option 3</Item>
</Multiselect>
</Dropdown>
);
react-select is a flexible and customizable library for building dropdowns and select inputs in React. It offers a wide range of features including single and multi-select, async options, and customizable styles. Compared to @zendeskgarden/react-dropdowns, react-select provides more advanced customization options and is widely used in the React community.
downshift is a library that provides primitives to build flexible and accessible dropdown components. It focuses on providing the necessary building blocks for creating custom dropdowns, rather than pre-styled components. Compared to @zendeskgarden/react-dropdowns, downshift offers more control over the dropdown behavior and is ideal for developers who need to implement highly customized dropdowns.
react-autosuggest is a library for building autocomplete inputs in React. It provides a simple API for creating inputs that suggest options as the user types. Compared to @zendeskgarden/react-dropdowns, react-autosuggest is specifically focused on autocomplete functionality and offers more features related to suggestion handling and customization.
This package includes components relating to dropdowns in the Garden Design System.
npm install @zendeskgarden/react-dropdowns
# Peer Dependencies - Also Required
npm install react react-dom styled-components @zendeskgarden/react-theming
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.
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
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>
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:
Autocomplete
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.
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.
FAQs
Components related to dropdowns in the Garden Design System
We found that @zendeskgarden/react-dropdowns demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.