9.0.0 • Published 14 days ago

@leafygreen-ui/combobox v9.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
14 days ago

Combobox

npm (scoped)

View on MongoDB.design

Installation

Yarn

yarn add @leafygreen-ui/combobox

NPM

npm install @leafygreen-ui/combobox

Example

import { Combobox, ComboboxOption } from '@leafygreen-ui/combobox';

<Combobox
  label="Choose a fruit"
  description="Please pick one"
  placeholder="Select fruit"
>
  <ComboboxOption value="apple" />
  <ComboboxOption value="banana" />
  <ComboboxOption value="carrot" />
  <ComboboxOption value="dragonfruit" />
  <ComboboxGroup label="Peppers">
    <ComboboxOption value="cayenne" />
    <ComboboxOption value="habanero" />
    <ComboboxOption value="jalapeno" displayName="Jalapeño" />
  </ComboboxGroup>
</Combobox>;

Output HTML

<div>
  <div>
    <label id="combobox-label-1" for="combobox-input-1"> Choose a fruit </label>
    <p>Please pick one</p>
  </div>
  <div>
    <div
      role="combobox"
      aria-expanded="true"
      aria-controls="combobox-menu-1"
      aria-owns="combobox-menu-1"
      tabindex="-1"
      data-disabled="false"
      data-state="none"
    >
      <div>
        <input
          aria-label="Choose a fruit"
          aria-autocomplete="list"
          aria-controls="combobox-menu-1"
          aria-labelledby="combobox-label-1"
          id="combobox-input-1"
          placeholder="Select fruit"
          value=""
        />
      </div>
      <svg aria-label="Caret Down Icon">...</svg>
    </div>
  </div>
</div>

Properties

PropTypeDescriptionDefault
children<ComboboxOption>, <ComboboxGroup>Define the Combobox Options by passing children
multiselectbooleanDefines whether a user can select multiple options, or only a single option. When using TypeScript, multiselect affects the valid values of initialValue, value, and onChangefalse
initialValueArray<string>, stringThe initial selection. Must be a string (or array of strings) that matches the value prop of a ComboboxOption. Changing the initialValue after initial render will not change the selection.
valueArray<string>, stringThe controlled value of the Combobox. Must be a string (or array of strings) that matches the value prop of a ComboboxOption. Changing value after initial render will affect the selection. value will always take precedence over initialValue if both are provided.
onChange(Array<string>) => void, (string) => voidA callback called when the selection changes. Callback recieves a single argument that is the new selection, either string, or string array
overflow'expand-y', 'expand-x', 'scroll-x'Defines the overflow behavior of a multiselect combobox. expand-y: Combobox has fixed width, and additional selections will cause the element to grow in the block direction. expand-x: Combobox has fixed height, and additional selections will cause the elemenet to grow in the inline direction. scroll-x: Combobox has fixed height and width, and additional selections will cause the element to be scrollable in the x (horizontal) direction.'expand-y'
labelstringAn accessible label for the input, rendered in a <label> to the DOM
aria-labelstringAn accessible label for the input, used only for screen-readers
descriptionReact.ReactNodeA description for the input
placeholderstringA placeholder for the input element. Uses the native placeholder attribute.'Select'
disabledbooleanDisables all interaction with the componentfalse
size'default'Defines the visual size of the component'default'
darkModebooleanToggles dark modefalse
state'error', 'none'The error state of the component. Defines whether the error message is displayed.'none'
errorMessagestringThe message shown below the input when state is error'This input needs your attention'
successMessagestringThe message shown below the input when state is valid'Success'
onFilter(value: string) => voidA callback called when the search input changes. Recieves a single argument that is the current input value. Use this callback to set searchState and/or filteredOptions appropriately
searchState'unset', 'error', 'loading'The state of search results. Toggles search messages within the menu.'unset'
searchErrorMessagestringA message shown within the menu when searchState is error'Could not get results!'
searchLoadingMessagestringA message shown within the menu when searchState is loading'Loading results...'
searchEmptyMessagestringA message shown within the menu when there are no options passed in as children, or filteredOptions is an empty array'No results found'
clearablebooleanDefines whether the Clear button appears to the right of the input
onClear(e: MouseEvent) => voidA callback fired when the Clear button is pressed. Fired after onChange, and before onFilter
filteredOptionsArray<string>, nullAn array used to define which options are displayed. Do not remove Options from the JSX children, as this will affect the selected options
chipTruncationLocation'start', 'middle', 'end', 'none'Defines where the ellipses appear in a Chip when the length exceeds the chipCharacterLimit'none'
chipCharacterLimitnumberDefined the character limit of a multiselect Chip before they start truncating. Note: the three ellipses dots are included in the character limit.12
classNamestringThe className passed to the root element of the component.
usePortalbooleanWill position Popover's children relative to its parent without using a Portal, if usePortal is set to false. NOTE: The parent element should be CSS position relative, fixed, or absolute if using this option.true
portalContainerHTMLElement | nullSets the container used for the popover's portal.
scrollContainerHTMLElement | nullIf the popover portal has a scrollable ancestor other than the window, this prop allows passing a reference to that element to allow the portal to position properly.
portalClassNamestringPasses the given className to the popover's portal container if the default portal container is being used.
popoverZIndexnumberSets the z-index CSS property for the popover.

ComboboxOption

Props

PropTypeDescriptionDefault
valuestringThe internal value of the option. Used as the identifier in Combobox initialValue, value and filteredOptions. When undefined, this is set to _.kebabCase(displayName)
displayNamestringThe display value of the option. Used as the rendered string within the menu and chips. When undefined, this is set to value
glyph<Icon/>The icon to display to the left of the option in the menu.
classNamestringThe className passed to the root element of the component.
descriptionstringOptional descriptive text under the displayName.
onClick(event: React.SyntheticEvent<HTMLLIElement, Event>, value: string) => voidCallback fired when an option is clicked. Returns the event and the option value.

ComboboxGroup

Props

PropTypeDescriptionDefault
labelstringLabel for the group of options
children<ComboboxOption>Options in the group
classNamestringThe className passed to the root element of the component.
9.0.0

14 days ago

8.1.4

25 days ago

8.1.3

1 month ago

8.1.2

2 months ago

8.1.1

2 months ago

8.1.0

3 months ago

8.0.0

3 months ago

7.2.0

3 months ago

7.1.0

4 months ago

7.0.2-popover.0

4 months ago

7.0.0-alpha.1

10 months ago

7.0.0-alpha.0

10 months ago

6.0.7

10 months ago

6.0.9

9 months ago

6.0.8

10 months ago

7.0.0

7 months ago

7.0.1

7 months ago

6.0.15

8 months ago

6.0.14

8 months ago

6.0.13

9 months ago

6.0.12

9 months ago

6.0.11

9 months ago

6.0.10

9 months ago

6.0.3-next.7

12 months ago

6.0.3-next.3

12 months ago

6.0.3-next.4

12 months ago

6.0.3-next.5

12 months ago

6.0.3-next.6

12 months ago

6.0.3-next.0

12 months ago

6.0.3-next.1

12 months ago

6.0.3-next.2

12 months ago

6.0.6

11 months ago

6.0.1

12 months ago

6.0.3

12 months ago

6.0.2

12 months ago

6.0.5

11 months ago

6.0.4

11 months ago

5.0.10

1 year ago

5.0.11

1 year ago

6.0.0

1 year ago

5.0.9

1 year ago

5.0.8

1 year ago

5.0.7

1 year ago

5.0.6

1 year ago

5.0.5

1 year ago

5.0.4

1 year ago

5.0.3

1 year ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

3.1.0-test.1

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.0.1

2 years ago

3.1.0-test.0

2 years ago

3.0.0

2 years ago

3.1.0-next.1

2 years ago

3.1.0-next.0

2 years ago

3.1.0-next.2

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.0.2

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.9.0

2 years ago