Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zendeskgarden/container-combobox

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zendeskgarden/container-combobox

Containers relating to Combobox in the Garden Design System

  • 2.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
90K
increased by8.16%
Maintainers
0
Weekly downloads
 
Created
Source

@zendeskgarden/container-combobox npm version

This package includes containers relating to Combobox in the Garden Design System.

Installation

npm install @zendeskgarden/container-combobox

Features

The combobox container encapsulates complexity while supporting a wide variety of standard features. Core logic and events are backed by Downshift. Standard naming and behaviors are finessed to suit Garden's point of view.

  • single and multiple option selection
  • non-editable select-only (similar to a native HTML <select>)
  • autocomplete (on by default) with user-provided option filtering
  • support for trigger as input parent (Garden layout) vs. trigger as input sibling (Downshift layout)

Usage

Check out storybook for live examples.

useCombobox

import { useCombobox } from '@zendeskgarden/container-combobox';

const Combobox = () => {
  const triggerRef = createRef();
  const inputRef = createRef();
  const listboxRef = createRef();
  const options = [
    { value: 'value-1', label: 'One' },
    { value: 'value-2', label: 'Two' },
    { value: 'value-3', label: 'Three' }
  ];
  const {
    getLabelProps,
    getInputProps,
    getTriggerProps,
    getListboxProps,
    getOptionProps,
    isExpanded
  } = useCombobox({
    triggerRef,
    inputRef,
    listboxRef,
    options
  });

  return (
    <>
      <label {...getLabelProps()}>Label</label>
      <input {...getInputProps()} />
      <button {...getTriggerProps()}>&#9660;</button>
      <ul
        {...getListboxProps({ 'aria-label': 'Options' })}
        style={{ visibility: isExpanded ? 'visible' : 'hidden' }}
      >
        {options.map((option, index) => (
          <li key={index} {...getOptionProps({ option })}>
            {option.label}
          </li>
        ))}
      </ul>
    </>
  );
};

ComboboxContainer

import { ComboboxContainer } from '@zendeskgarden/container-combobox';

const Combobox = () => {
  const triggerRef = createRef();
  const inputRef = createRef();
  const listboxRef = createRef();
  const options = [
    { value: 'value-1', label: 'One' },
    { value: 'value-2', label: 'Two' },
    { value: 'value-3', label: 'Three' }
  ];

  return (
    <ComboboxContainer
      triggerRef={triggerRef}
      inputRef={inputRef}
      listboxRef={listboxRef}
      options={options}
    >
      {({
        getLabelProps,
        getInputProps,
        getTriggerProps,
        getListboxProps,
        getOptionProps,
        isExpanded
      }) => (
        <>
          <label {...getLabelProps()}>Label</label>
          <input {...getInputProps()} />
          <button {...getTriggerProps()}>&#9660;</button>
          <ul
            {...getListboxProps({ 'aria-label': 'Options' })}
            style={{ visibility: isExpanded ? 'visible' : 'hidden' }}
          >
            {options.map((option, index) => (
              <li key={index} {...getOptionProps({ option })}>
                {option.label}
              </li>
            ))}
          </ul>
        </>
      )}
    </ComboboxContainer>
  );
};

Keywords

FAQs

Package last updated on 25 Sep 2024

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