Skip to main content

Filter Button

Filter Button is a component with an inline label and highlighted value. It lets users choose one or more items from an options menu.

Use a Filter Button to offer a list of choices where multiple selection is possible.

Example

Live Editor
Result
Loading...

Variants

Anchor Size

The anchor is available in two sizes: small and medium can be accessed using size prop.

Live Editor
Result
Loading...

Custom Sorting

You can use sortPredicate property to have custom sorting on the results when typing your query. In this example when searching for 'us' or 'ru', unlike the default sorting, 'United States (US)' or 'Russia (RU)' will appear first, respectively.

Live Editor
Result
Loading...

Custom Controls

You have Search input and SelectAll checkbox shown by default, which can be hidden using showSearch and showSelectAll props.

Live Editor
Result
Loading...

Default Items

You can provide default items which will be used to populate filter once user clicks reset. If not specified filter with multiple selection will reset all items and with single selction filter will reset to initially selected item

Live Editor
Result
Loading...

Disabled

Live Editor
Result
Loading...

DisableSort

Live Editor
Result
Loading...

DisableSort - Custom Sorting with disabled default sorting

Here is an example of using custom sorting when defaut sorting is disabled.

Live Editor
Result
Loading...

Disable Sort when less items

Sorting is disabled by default when there are less than 6 items. This does not apply to search results.

Live Editor
Result
Loading...

Enable Zero Selection

To have no filters applied, you can enable the prop enableZeroSelection to true.

Live Editor
Result
Loading...

You can use this prop to display a warning message in the footer. Important note: footerWarningMessage prop and the Reset Button cannot be used at the same time.

Live Editor
Result
Loading...

isApplyButtonDisabled

You can use this prop to disable the Apply button.

Live Editor
Result
Loading...

Loading

You can use a isLoading property in order to display the loading indicator.

Live Editor
Result
Loading...

onSelectionChange

The onSelectionChange prop is an onChange callback. You can use this prop to send information about the selected items to the parent component.

Live Editor
Result
Loading...

RenderItem

You can use a renderItem property to define custom render function for filter items.

info

The filter uses the virtualization so if you are about to change the height of items do not forget to specify an itemSize property.

Live Editor
Result
Loading...

Custom List Component

You can use a customList property to define custom component for filter items.

info

Utilize this property to customize the component of the specific filter items. Please keep in mind that you will be responsible for managing styles and keyboard navigation if you opt to pass a custom component. This functionality is most effectively employed in conjunction with the FilterButtonContext context.

Live Editor
Result
Loading...

Mode Shifter

In FilterButton we have a mode shifter which can be enabled when modeShifter is true and onModeChange handler is provided. We have 2 mode include and exclude, which can be controlled using onModeChange handler which uses an argument of either of 2 modes.

Live Editor
Result
Loading...

You can also change the Mode labels using the modeLabels property.

Live Editor
Result
Loading...

RenderValue

You can use a renderValue property to define custom render function for the filter value. When specified this function is used to render a custom element within the trigger.

Live Editor
Result
Loading...

Reset Button

You can use a showResetButton property in order to display the reset button. The reset button selects all option items.

Live Editor
Result
Loading...

The menu list is available in three sizes: small, medium and large can be accessed using menuSize prop. It is ignored if isFullWidthTrigger is true. In this case the menu takes the same width as the trigger.

Live Editor
Result
Loading...

Single Value Selection

You can use multiple property to define if you want to have multiple or single selection for defined options.

Live Editor
Result
Loading...

Full width trigger

You can use isFullWidthTrigger property to allow the trigger to take the available width. If isFullWidthTrigger is true the menu takes the same width as the trigger.

Live Editor
Result
Loading...

Translate

You can use a getElementLabel property to define the text for all elements within the Filter. This function will be called with one of the following values as an argument:

  type FilterButtonTextElements =
| 'apply-button'
| 'reset-button'
| 'select-all-default'
| 'select-all-searched'
| 'loading-message'
| 'not-found-message'
| 'all-selected-badge-label'
| 'search-input-placeholder'

Each value matches the element within the Filter, e.g. 'apply-button' specifies the label for the Apply button etc.

Live Editor
Result
Loading...

Props

NameTypeDefault
selectedItems *
Array of options that populates the filter button.
T[]
items *
Array of items that populate the filter button. The item has two required properties of type string: value and label. It can be extended with any additional properties.
T[]
name *
The name of the Filter. It will be used for displaying the value for Select Button
string
multiple
Use this prop to switch between multiple and single selections
boolean
true
id
Native HTML attribute: Link . Internally, this component uses a random id. We use it to associate an input with a label element. As the random id might break snapshot tests it can be overridden by setting an explicit id.
string
defaultItems
Array of options which will be selected once user will reset selection
T[]
disabled
Use this prop if the component should not be interactive
boolean
getElementLabel
Use this prop to override the default elements texts and labels. FilterButtonTextElements contains elements: | 'apply-button' | 'reset-button' | 'select-all-default' | 'select-all-searched' | 'loading-message' | 'not-found-message' | 'all-selected-badge-label' | 'search-input-placeholder'
((element: FilterButtonTextElements) => string)
isApplyButtonDisabled
Use this prop to disable the Apply button regardless of selection state
boolean
isLoading
Use this prop if the component should display loading indicator.
boolean
itemSize
The base height of every item within the Filter.
number
32
size
The size of the FilterAnchor.
"small" | "medium"
"small"
menuSize
The size of the FilterList.
"small" | "medium" | "large"
"small"
showResetButton
Use this prop if the component should display the Reset button inside the Filter.
boolean
onReset
Use this prop to override the default behavior of the handler called when a user clicks on Reset button. Returned items will be the ones selected after handler is applied.
((initialSelectedItems: T[]) => T[])
onApply
The handler will be called when a user closes the Filter.
((selectedItems: T[], currentModeType?: modeType) => void)
onSelectionChange
Callback that fires whenever checkbox selections change
((selectedItems: T[]) => void)
renderItem
Use this prop to override the default rendering function for Filter items.
((item: T) => ReactNode)
customList
Use this prop to render a custom list component for each Filter items
ComponentType<T>
searchPredicate
Use this prop to override the default search function. The default function make a local comparing between an item label and a search string.
SearchItemPredicate<T>
sortPredicate
Use this prop to custom sort filtered options By default options will come in order defined in useSortedItems hook
SortPredicate<T>
renderValue
Use this prop to override the default rendering function for the Filter anchor.
(<T extends FilterItem>(selectedItems: T[]) => ReactNode)
aria-label
Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link
string
aria-labelledby
Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link
string
zIndex
Use this prop if you need to custom z-index for filter content
number
showSelectAll
Boolean prop showing Select all checkbox
boolean
true
showSearch
Boolean prop showing Search input field
boolean
true
disableSort
disable sorting
boolean
false
modeShifter
This is a boolean prop to show the mode shifter
boolean
modeType
This is the modeType to either include or exclude
"include" | "exclude"
modeLabels
Label string for modeType
modeLabels
onModeChange
The handler will be called when a user change the mode.
(() => void)
isFullWidthTrigger
Allows the trigger to take the available width
boolean
enableZeroSelection
Boolean for enabling zero items selection
boolean
false
footerWarningMessage
Use this prop to provide a warning message in the footer area
string
data-{foo}
Data attributes can be used by testing libraries to retrieve components or assert their existence
string
* - the prop is required.