🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

downshift

Package Overview
Dependencies
Maintainers
0
Versions
355
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

downshift

🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.

9.0.9
latest
Source
npm
Version published
Weekly downloads
1.9M
1.55%
Maintainers
0
Weekly downloads
 
Created

What is downshift?

Downshift is a React library that provides a set of primitives to build simple, flexible, WAI-ARIA compliant enhanced input React components. Its major use cases include creating customizable dropdowns, comboboxes, and autocomplete/autosuggest inputs.

What are downshift's main functionalities?

Autocomplete

This code sample demonstrates how to create a basic autocomplete input using Downshift. It includes a label, an input field, and a list of suggestions that appear as the user types.

{"import Downshift from 'downshift';\n\nfunction BasicAutocomplete() {\n  return (\n    <Downshift\n      onChange={selection => alert(selection.value)}\n      itemToString={item => (item ? item.value : '')}\n    >\n      {({\n        getInputProps,\n        getItemProps,\n        getLabelProps,\n        getMenuProps,\n        isOpen,\n        inputValue,\n        highlightedIndex,\n        selectedItem,\n        getRootProps\n      }) => (\n        <div {...getRootProps({}, { suppressRefError: true })}>\n          <label {...getLabelProps()}>Enter a fruit</label>\n          <input {...getInputProps()} />\n          <ul {...getMenuProps()}>\n            {isOpen\n              ? items\n                  .filter(item => !inputValue || item.value.includes(inputValue))\n                  .map((item, index) => (\n                    <li\n                      {...getItemProps({\n                        key: item.value,\n                        index,\n                        item,\n                        style: {\n                          backgroundColor:\n                            highlightedIndex === index ? 'lightgray' : 'white',\n                          fontWeight: selectedItem === item ? 'bold' : 'normal',\n                        },\n                      })}\n                    >\n                      {item.value}\n                    </li>\n                  ))\n              : null}\n          </ul>\n        </div>\n      )}\n    </Downshift>\n  );\n}\n\nconst items = [{ value: 'apple' }, { value: 'pear' }, { value: 'orange' }, { value: 'grape' }, { value: 'banana' }];"}

Dropdown

This code sample shows how to create a dropdown menu using Downshift. It includes a button to toggle the dropdown and a list of selectable items.

{"import Downshift from 'downshift';\n\nfunction BasicDropdown() {\n  return (\n    <Downshift\n      onChange={selection => alert(selection.value)}\n      itemToString={item => (item ? item.value : '')}\n    >\n      {({\n        getToggleButtonProps,\n        getMenuProps,\n        isOpen,\n        getItemProps,\n        highlightedIndex,\n        selectedItem\n      }) => (\n        <div>\n          <button {...getToggleButtonProps()}>\n            {selectedItem ? selectedItem.value : 'Select an item'}\n          </button>\n          <ul {...getMenuProps()}>\n            {isOpen\n              ? items.map((item, index) => (\n                  <li\n                    {...getItemProps({\n                      key: item.value,\n                      index,\n                      item,\n                      style: {\n                        backgroundColor:\n                          highlightedIndex === index ? 'lightgray' : 'white',\n                        fontWeight: selectedItem === item ? 'bold' : 'normal',\n                      },\n                    })}\n                  >\n                    {item.value}\n                  </li>\n                ))\n              : null}\n          </ul>\n        </div>\n      )}\n    </Downshift>\n  );\n}\n\nconst items = [{ value: 'apple' }, { value: 'pear' }, { value: 'orange' }, { value: 'grape' }, { value: 'banana' }];"}

Other packages similar to downshift

Keywords

enhanced input

FAQs

Package last updated on 14 Mar 2025

Did you know?

Socket

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.

Install

Related posts