Back to Woocommerce

Search

packages/js/components/src/search/README.md

10.8.0-dev1.8 KB
Original Source

Search

A search box which autocompletes results while typing, allowing for the user to select an existing object (product, order, customer, etc). Currently only products are supported.

Usage

jsx
<Search
 type="products"
 placeholder="Search for a product"
 selected={ selected }
 onChange={ items => setState( { selected: items } ) }
/>

Props

NameTypeDefaultDescription
allowFreeTextSearchBooleanfalseRender additional options in the autocompleter to allow free text entering depending on the type
classNameStringnullClass name applied to parent div
onChangeFunctionnoopFunction called when selected results change, passed result list
typeOne of: 'categories', 'countries', 'coupons', 'customers', 'downloadIps', 'emails', 'orders', 'products', 'taxes', 'usernames', 'variations', 'custom'null(required) The object type to be used in searching
autocompleterCompleternullCustom completer to be used in searching. Required when type is 'custom'
placeholderStringnullA placeholder for the search input
selectedArray[]An array of objects describing selected values. If the label of the selected value is omitted, the Tag of that value will not be rendered inside the search box.
inlineTagsBooleanfalseRender tags inside input, otherwise render below input
showClearButtonBooleanfalseRender a 'Clear' button next to the input box to remove its contents
staticResultsBooleanfalseRender results list positioned statically instead of absolutely
disabledBooleanfalseWhether the control is disabled or not

selected item structure

  • id: One of type: number, string
  • label: String