Usage

Props

NameTypeRequiredDefaultDescription
afterHide
((e?: Event) => void)
false
afterShow
(() => void)
false
beforeHide
BeforeCallback
false
since

10.19.0

beforeShow
BeforeCallback
false
since

10.19.0

block
boolean
false
since

10.19.0

disabled
boolean
false
since

10.19.0

error
boolean
false
since

10.19.0

footer
ReactNode
false

Prop to define a custom footer for the tiered select. Accepts a React.ReactNode. Takes precedence over quick create footer.

Example:

<TieredSelect
  ...
  footer={<div>Custom Footer</div>}
  ...
/>
default

undefined

since

11.4.0

getValueString
GetValueString
false
since

10.19.0

i18nScope
string
false

The i18n key to use for the tiered select's configurable strings. Defaults to using the core library's default strings.

since

10.19.0

loading
boolean
false
since

10.19.0

loadingMore
boolean
false

Used to display a loading indicator as the last item of the list. Can be used with onScrollBottom or onSearch{' '} (empty options during search async call) to indicate the loading of new items.

since

10.19.0

onClear
((event: MouseEvent<HTMLButtonElement, MouseEvent>) => void)
false
onScrollBottom
((e: UIEvent<HTMLDivElement, UIEvent>) => void)
false
onSearch
((event: ChangeEvent<HTMLInputElement>) => void)
false
options
any[]
false

Flat array of tier objects, this array is used as data for the component

since

10.19.0

selectableTiers
boolean
false

If true, any tier is selectable. If false, only leaf nodes are selectable

default

true

since

10.19.0

tabIndex
number
false
since

10.19.0

value
any[]
false

Flat array of tier objects that represents the selected value

since

10.19.0

getGroupId
Function
false

Callback for using a custom tier shape {'(tier: any) => Id'} Defaults to {'(tier: any) => tier.GroupId'}

since

10.19.0

getId
Function
false

Callback for using a custom tier shape {'(tier: any) => Id'} Defaults to {'(tier: any) => tier.Id'}

since

10.19.0

getLabel
Function
false

Callback for using a custom tier shape {'(tier: any) => string'} Defaults to {'(tier: any) => tier.Label'}

since

10.19.0

getNextGroupId
Function
false

Callback for using a custom tier shape {'(tier: any) => Id'} Defaults to {'(tier: any) => tier.NextGroupId'}

since

10.19.0

isLeaf
Function
false
since

10.19.0

isTierDisabled
Function
false
since

10.19.0

onChange
Function
false
Callback for selecting an item from the tiered select. Returns the{' '} Selection object from the Menu api, along with the updated value
{'(Selection: { event, item, group }, value) =>'}
since

10.19.0

onNavigate
Function
false

Callback for when navigation occurs. Triggered by the left and right arrow keys, or clicking a navigable item. Returns the id of the next group that will be navigated to, and the updated path. {'(nextGroupId: string | number | undefined, path: any[]) => '}

since

10.19.0

onQuickCreate
Function
false

Pass this callback when a quick create experience is desired. Called when the "create" button in quick create mode is clicked. Returns the value of the quick create input. {'(string) =>'}

since

10.19.0

Data

Default

By default, the TieredSelect assumes the data takes the shape seen below. Additionally, getter functions can be supplied to the getId, getGroupId, getNextGroupId, and getLabel props if a custom shape is desired. Important: root groupIds are expected to be null. Leaf nodes are not expected to have a nextGroupId

Non-Selectable Tiers

No Quick Create and all defaulted values

Selectable Tiers with Quick Create

Note: selectableTiers is true by default

I18n

The TieredSelect will look to the i18nScope prop to figure out which scope to call in the I18n.t function, like so:

For example,

The following keys can be configured:

  • emptyMessage
  • placeholder
  • quickCreateActionLabel
  • quickCreateCancelLabel
  • quickCreateCreateLabel
  • quickCreatePlaceholder
  • searchEmptyMessage
  • searchPlaceholder
  • spinnerLabel

The i18n-js package is used internally, so there is no need to pass a t or l function to the I18nProvider, only locale and translations

Controlled and Initial Value

Selectable Tiers

By providing an array of tiers to the value prop, the TieredSelect can hold an initial value. It looks at the last tier in the value prop, and populates the menu with tiers belonging to the nextGroupId of that last tier. It can also be used in a controlled manner, by using the onChange along with value.

The TieredSelect figures out which items to render by looking through options and filtering by which groupIds match the current tier. The rendered items display whatever getLabel(item) returns.

Non Selectable Tiers

A special case arises when tiers are not selectable. If the last tier in the value array passed to the TieredSelect is a leaf node, it will open to the parent of the leaf node so that the leaf is displayed as selected. For instance:

An initial value not terminating in a leaf node can also be passed to a TieredSelect with non-selectable tiers. It will open to that tier and show any child nodes of that tier.

Search Behavior

When searching a TieredSelect, all possible tiers should be flattened into a single list, and selecting one will fill in the value to the selected value. Due to potentially unknown data shapes, as well as the probable need to make requests for search results, this behavior has been left up to the implementor.

In TieredSelect the onChange will return the a selection object, similar to our Menu onChange api, with an added value key. When searching, the value key will have the value of the value from where the search was performed.

There are many ways to implement the desired UX. The approach below turns all search results into what are essentially value objects (i.e an array of Tier arrays), which it filters then feeds to the TieredSelect when a search is made. This way, the value of the TieredSelect can be set from the selection.item value inside of the onChange callback. The TieredSelect automatically closes after selecting a search result, so the next time it is opened, it will open to the selected value and the normal options will be used.