Compact Multi-Select

A space-efficient component for selecting multiple options from a list.

The Compact Multi-Select component provides a user-friendly way to select multiple items from a dropdown list. It is designed to be compact and is ideal for use in forms and filters where space is limited.

Import

import { CompactMultiSelect } from 'h2o-library';
import type { CompactMultiSelectOption } from 'h2o-library';

Usage

The example below shows a compact multi-select for choosing medical specialties, with a limit on the number of selections.

Bariatrics
Dermatology
"use client";

import React, { useState } from "react";
import {
  CompactMultiSelect,
  CompactMultiSelectOption,
} from "h2o-library";

const options: CompactMultiSelectOption[] = [
    { label: "Bariatrics", value: "Bariatrics" },
    { label: "Cardiology", value: "Cardiology" },
    { label: "Dermatology", value: "Dermatology" },
    // ... more options
];

export const CompactMultiSelectExample = () => {
  const [selected, setSelected] = useState<CompactMultiSelectOption[]>([
    options[0],
    options[2],
  ]);

  return (
    <div style={{ width: "400px" }}>
      <CompactMultiSelect
        label="Select specialties"
        options={options}
        selected={selected}
        onChange={setSelected}
        placeholder="Select up to 4"
        maxSelections={4}
      />
    </div>
  );
};

Props

PropTypeRequiredDescription
labelstringNoA label for the select input.
optionsCompactMultiSelectOption[]YesAn array of options to display in the dropdown.
selectedCompactMultiSelectOption[]YesAn array of the currently selected options.
onChange(selected: CompactMultiSelectOption[]) => voidYesCallback function that is called when the selected options change.
placeholderstringNoPlaceholder text to display when no options are selected.
maxSelectionsnumberNoThe maximum number of options that can be selected.

CompactMultiSelectOption Type

PropTypeDescription
labelstringThe text displayed for the option.
valuestringThe unique value for the option.

Accessibility

  • The component is fully keyboard accessible, allowing users to navigate and select options using the keyboard.
  • The selected options are clearly indicated.
  • ARIA attributes are used to ensure the component is understandable by screen readers.