Back to Woocommerce

README

packages/js/components/src/search-list-control/README.md

10.8.0-dev3.2 KB
Original Source

SearchListControl

Component to display a searchable, selectable list of items.

Usage

jsx
<SearchListControl
	list={ list }
	isLoading={ loading }
	selected={ selected }
	onChange={ items => setState( { selected: items } ) }
/>

Props

NameTypeDefaultDescription
classNameStringnullAdditional CSS classes
isHierarchicalBooleannullWhether the list of items is hierarchical or not. If true, each list item is expected to have a parent property
isLoadingBooleannullWhether the list of items is still loading
isSingleBooleannullRestrict selections to one item
listArraynullA complete list of item objects, each with id, name properties. This is displayed as a clickable/keyboard-able list, and possibly filtered by the search term (searches name)
messagesObjectnullMessages displayed or read to the user. Configure these to reflect your object type. See defaultMessages above for examples
onChangeFunctionnull(required) Callback fired when selected items change, whether added, cleared, or removed. Passed an array of item objects (as passed in via props.list)
onSearchFunctionnullCallback fired when the search field is used
renderItemFunctionnullCallback to render each item in the selection list, allows any custom object-type rendering
selectedArraynull(required) The list of currently selected items
searchStringnull
setStateFunctionnull
debouncedSpeakFunctionnull
instanceIdNumbernull

list item structure:

  • id: Number
  • name: String

messages object structure:

  • clear: String - A more detailed label for the "Clear all" button, read to screen reader users.
  • list: String - Label for the list of selectable items, only read to screen reader users.
  • noItems: String - Message to display when the list is empty (implies nothing loaded from the server or parent component).
  • noResults: String - Message to display when no matching results are found. %s is the search term.
  • search: String - Label for the search input
  • selected: Function - Label for the selected items. This is actually a function, so that we can pass through the count of currently selected items.
  • updated: String - Label indicating that search results have changed, read to screen reader users.

SearchListItem

Usage

Used implicitly by SearchListControl when the renderItem prop is omitted.

Props

NameTypeDefaultDescription
classNameStringnullAdditional CSS classes
countLabelReactNodenullLabel to display in the count bubble. Takes preference over item.count.
depthNumber0Depth, non-zero if the list is hierarchical
itemObjectnullCurrent item to display
isSelectedBooleannullWhether this item is selected
isSingleBooleannullWhether this should only display a single item (controls radio vs checkbox icon)
onSelectFunctionnullCallback for selecting the item
searchString''Search string, used to highlight the substring in the item name