Socket
Socket
Sign inDemoInstall

@reach/combobox

Package Overview
Dependencies
18
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @reach/combobox

Accessible React Combobox (Autocomplete).


Version published
Maintainers
1
Install size
381 kB
Created

Package description

What is @reach/combobox?

@reach/combobox is a React component library that provides accessible combobox (autocomplete) components. It helps developers create input fields that offer suggestions as the user types, improving the user experience and accessibility.

What are @reach/combobox's main functionalities?

Basic Combobox

This code demonstrates a basic combobox with a few options. The user can type in the input field, and the combobox will display matching options.

```jsx
import { Combobox, ComboboxInput, ComboboxPopover, ComboboxList, ComboboxOption } from "@reach/combobox";
import "@reach/combobox/styles.css";

function BasicCombobox() {
  return (
    <Combobox>
      <ComboboxInput aria-labelledby="demo" />
      <ComboboxPopover>
        <ComboboxList>
          <ComboboxOption value="Apple" />
          <ComboboxOption value="Banana" />
          <ComboboxOption value="Orange" />
        </ComboboxList>
      </ComboboxPopover>
    </Combobox>
  );
}
```

Combobox with Custom Filtering

This code demonstrates a combobox with custom filtering logic. The list of options is filtered based on the user's input.

```jsx
import { useState } from "react";
import { Combobox, ComboboxInput, ComboboxPopover, ComboboxList, ComboboxOption } from "@reach/combobox";
import "@reach/combobox/styles.css";

const items = ["Apple", "Banana", "Orange", "Grape", "Pineapple"];

function CustomFilterCombobox() {
  const [term, setTerm] = useState("");
  const results = items.filter(item => item.toLowerCase().includes(term.toLowerCase()));

  return (
    <Combobox onSelect={item => setTerm(item)}>
      <ComboboxInput aria-labelledby="demo" onChange={e => setTerm(e.target.value)} />
      <ComboboxPopover>
        <ComboboxList>
          {results.map((item, index) => (
            <ComboboxOption key={index} value={item} />
          ))}
        </ComboboxList>
      </ComboboxPopover>
    </Combobox>
  );
}
```

Combobox with Async Data

This code demonstrates a combobox that fetches data asynchronously based on the user's input. The results are fetched from an API and displayed as options.

```jsx
import { useState, useEffect } from "react";
import { Combobox, ComboboxInput, ComboboxPopover, ComboboxList, ComboboxOption } from "@reach/combobox";
import "@reach/combobox/styles.css";

function AsyncCombobox() {
  const [term, setTerm] = useState("");
  const [results, setResults] = useState([]);

  useEffect(() => {
    if (term) {
      fetch(`https://api.example.com/search?q=${term}`)
        .then(response => response.json())
        .then(data => setResults(data.items));
    } else {
      setResults([]);
    }
  }, [term]);

  return (
    <Combobox onSelect={item => setTerm(item)}>
      <ComboboxInput aria-labelledby="demo" onChange={e => setTerm(e.target.value)} />
      <ComboboxPopover>
        <ComboboxList>
          {results.map((item, index) => (
            <ComboboxOption key={index} value={item} />
          ))}
        </ComboboxList>
      </ComboboxPopover>
    </Combobox>
  );
}
```

Other packages similar to @reach/combobox

FAQs

Last updated on 07 Jun 2019

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