Socket
Socket
Sign inDemoInstall

downshift

Package Overview
Dependencies
Maintainers
2
Versions
354
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.


Version published
Weekly downloads
1.6M
decreased by-3.28%
Maintainers
2
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

FAQs

Package last updated on 29 Sep 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc