Socket
Socket
Sign inDemoInstall

@ds-kit/autocomplete

Package Overview
Dependencies
155
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ds-kit/autocomplete

Autocomplete component


Version published
Maintainers
4
Install size
10.2 MB
Created

Readme

Source

title: "Autocomplete" slug: "/packages/autocomplete" category: "control" componentNames:

  • "Autocomplete"
  • "AutocompleteVirtualized"

Autocomplete

The autocomplete component gives users suggestions when choosing one or more values from a predefined list. It should be used where users have to select from a longer, searchable list of items.

To see the autocomplete component in action, check out the input patterns.

import Autocomplete from "@ds-kit/autocomplete"

Basic example

For the most basic example, pass in a list of objects with a value and a label key to the autocomplete.

<>
  <Autocomplete
    options={[
      { value: "AGO", label: "Angola" },
      { value: "COL", label: "Colombia" },
      { value: "SWE", label: "Sweden" },
      { value: "TZA", label: "Tanzania" },
    ]}
    mb="12rem"
  />
</>

Virtualized example

For long list of options, use virtualized version of Autocomplete to maintain performance.

import { AutocompleteVirtualized } from "@ds-kit/autocomplete"
<AutocompleteVirtualized
  options={new Array(5000).fill().map((d, i) => ({
    value: `${i}`,
    label: !i
      ? `Element with a very very very long label or even much longer one #${i}`
      : `Element #${i}`,
  }))}
  mb="22rem"
/>

Raised Autocomplete

The autocomplete can take a raised prop to make it stand out a bit more on a page. Use the raised version of the autocomplete when placing the autocomplete on colored backgrounds.

<Div bg="green.400" py="2rem" px="1.5rem">
  <Autocomplete
    raised
    options={[
      { value: "AGO", label: "Angola" },
      { value: "COL", label: "Colombia" },
      { value: "SWE", label: "Sweden" },
      { value: "TZA", label: "Tanzania" },
    ]}
    mb="12rem"
  />
</Div>

Multiselect Autocomplete

<>
  <Autocomplete
    isMulti
    options={[
      { value: "AGO", label: "Angola" },
      { value: "COL", label: "Colombia" },
      { value: "SWE", label: "Sweden" },
      { value: "TZA", label: "Tanzania" },
    ]}
    mb="12rem"
  />
</>

Limited selected value width

In the case of very long labels, you can use the valueMaxWidth prop to limit the size of the selected value containers in the multiselect.

<>
  <Autocomplete
    isMulti
    valueMaxWidth="8rem"
    options={[
      { value: "AGO", label: "Angola" },
      { value: "DRC", label: "Democratic Republic of the Congo" },
      { value: "COL", label: "Colombia" },
      { value: "SWE", label: "Sweden" },
      { value: "TZA", label: "Tanzania" },
    ]}
    mb="14rem"
  />
</>

Sizes

Use the size prop to determine the overall size of the autocomplete. The available options (sm, md, lg) are aligned with other control elements, such as buttons and textfields.

<>
  <Autocomplete
    isMulti
    size="lg"
    options={[
      { value: "AGO", label: "Angola" },
      { value: "COL", label: "Colombia" },
      { value: "SWE", label: "Sweden" },
      { value: "TZA", label: "Tanzania" },
    ]}
    mb="14rem"
  />

  <Autocomplete
    isMulti
    size="md"
    options={[
      { value: "AGO", label: "Angola" },
      { value: "COL", label: "Colombia" },
      { value: "SWE", label: "Sweden" },
      { value: "TZA", label: "Tanzania" },
    ]}
    mb="12rem"
  />

  <Autocomplete
    isMulti
    size="sm"
    options={[
      { value: "AGO", label: "Angola" },
      { value: "COL", label: "Colombia" },
      { value: "SWE", label: "Sweden" },
      { value: "TZA", label: "Tanzania" },
    ]}
    mb="10rem"
  />
</>

FAQs

Last updated on 13 Feb 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc