ComboBox

Input with suggestions

A flexible and accessible ComboBox component that combines a button with a dropdown list, supporting various styles, keyboard navigation, and customization options.

VersionLicenseDownloadsBundle Size (minified)Bundle Size (minified + gzip)

Overview

This documentation provides instructions on how to use the ComboBox component in your React projects. The ComboBox component is part of the abaabil.combobox library.

import ComboBox from 'abaabil.combobox';

Key Features

  • Fully accessible with ARIA attributes and keyboard navigation
  • Customizable appearance with icon support
  • Flexible option rendering
  • Controlled component with onChange callback

Basic Usage

The ComboBox component can be used in your JSX to create dropdown selection interfaces. You can customize the component by setting its properties such as options, placeholder, icon, and more.

Usage Example

The ComboBox component can be used in your React projects to create accessible dropdown selection inputs with various properties. You can customize the ComboBox by setting its properties such as options, onChange, placeholder, and more. The following example demonstrates how to use the ComboBox component:

Basic Usage

A simple ComboBox with text-only options:

With Icons

ComboBox with icons for options and custom button icons:

Custom Styles

Applying custom styles to the ComboBox:

Properties

The ComboBox component accepts the following properties:

options

Type: Array<{ key: string, label: string, icon?: string }>

Description: Array of options to display in the dropdown.

onChange

Type: (selectedOption: Object) => void

Description: Callback function called when an option is selected.

placeholder

Type: string

Description: Text to display when no option is selected.

icon

Type: string

Description: Icon ID to display before the selected option or placeholder.

actionIcon

Type: string

Description: Icon ID to display after the selected option or placeholder.

buttonClassName

Type: string

Description: Additional CSS classes to apply to the Button component.

ulClassName

Type: string

Description: Additional CSS classes to apply to the dropdown list.

liClassName

Type: string

Description: Additional CSS classes to apply to the list items.

Accessibility

The ComboBox component is designed with accessibility in mind:

  • Implements ARIA attributes for proper screen reader support
  • Supports full keyboard navigation
  • Manages focus appropriately when opening and closing the dropdown
  • Provides visual feedback for hover and focus states

Keyboard Interactions

The ComboBox component supports the following keyboard interactions:

  • Enter, Space, ArrowDown, ArrowRight: Open the dropdown
  • ArrowDown, ArrowRight: Move to the next option
  • ArrowUp, ArrowLeft: Move to the previous option
  • Enter: Select the highlighted option and close the dropdown
  • Escape: Close the dropdown without selecting
  • Tab: Move focus to the next focusable element

Styling

The ComboBox component uses Tailwind CSS classes for styling:

  • Customizable button appearance through buttonClassName prop
  • Dropdown list styling with ulClassName prop
  • Individual list item styling with liClassName prop
  • Default styles provide a cohesive look with other Abaabil components

Performance Considerations

Tips for optimal performance when using the ComboBox component:

  • Use memoization for the options prop if it's derived from complex calculations
  • Implement virtualization for large option lists to improve rendering performance
  • Consider lazy loading options if dealing with a large dataset

Best Practices

Recommendations for effectively using the ComboBox component:

  • Provide clear and concise option labels
  • Use icons judiciously to enhance visual recognition
  • Implement proper error handling and validation in the onChange callback
  • Consider adding a search functionality for long option lists

Browser Support

The ComboBox component is compatible with modern browsers:

  • Chrome, Firefox, Safari, Edge
  • Internet Explorer 11 with polyfills