Krizaka
Documentation

Filter bar

The bar above a list: the controls that narrow it, the filters in force as removable chips, “Clear filters”, and the count of results — the state kept by the app, in the address.

WebBêtaFormulaires

Web uniquement — React, depuis @krizaka/ui/filter-bar. Bêta : son API peut encore changer à une version mineure.

Quand l’utiliser

  • Above a table or a grid people narrow with several criteria at once: status, type, owner, period, a query.
  • When the filters must be visible and undoable one by one, and shared in a link.

Quand ne pas l’utiliser

  • For one choice among a few views of a list: chips in a single group.À la place : Chip
  • For a search alone: a search field.À la place : Search field

Installation

Installer

npm install @krizaka/ui @krizaka/tailwind @krizaka/tokens tailwindcss

Styles

@import "tailwindcss";
@import "@krizaka/tailwind";
@import "@krizaka/ui/tailwind.css";

Importer

import { FilterBar, FilterMenu, readFilterParams, writeFilterParams } from "@krizaka/ui/filter-bar";

Exemples

Jobs

A search, a status menu (several values), a model menu (one value), the chips and the count.

Status: FailedModel: Flux 1.1

6 jobs

A filter's menu

FilterMenu open: checkboxes with the count each value would give.

In the address

The filters read from and written to URLSearchParams, the page reset on change.

Role: CreatorRole: Admin

?role=creator%2Cadmin&page=3

Props

FilterBar

The bar of filters above a list: controls, active filters as chips, clear all, the count of results.

PropTypeDéfautDescription
labelrequisstring—The accessible name of the bar ("Filter jobs"), passed translated.
activereadonly ActiveFilter[][]The filters in force, each a removable chip.
childrenReactNode—The controls: SearchField, FilterMenu, DateRangePicker, a Chip.Group…
clearLabelstringClear filtersThe "Clear all" button ("Clear filters"), passed translated.
onClearAll(() => void)—Clears every filter; the "Clear all" button shows when there is at least one.
removeLabel((label: string) => string)(text) => `Remove ${text}`A chip's remove button: (label) => "Remove " + label, passed translated.
resultsstring—The count of results ("42 jobs"), announced politely when it changes.

FilterMenu

A filter's button and its menu of options — checkboxes (several values) or radios (one) — with a count of chosen ones.

PropTypeDéfautDescription
labelrequisstring—The name of the filter on its button ("Status"), passed translated.
onValueChangerequis((value: string[]) => void) | ((value: string) => void)—Called with the values chosen. Called with the value chosen.
optionsrequisreadonly FilterOption[]—The choices.
valuerequisstring | readonly string[]—The values chosen. The value chosen, "" for none.
classNamestring—Classes merged on the button.
defaultOpenboolean—Opens the menu at first (a story, a test).
multipleboolean—Several values (checkboxes, default) or one (radios). One value: the options are radios.

Accessibilité

  • The bar is a group named by label; each chip's remove button is named by removeLabel (“Remove Status: Failed”).
  • The count of results is a polite live region: a change of filter is heard without moving the focus.
  • FilterMenu is a Radix menu of checkbox (or radio) items: their state is announced as they toggle.

Clavier

TouchesAction
Enter / Space / Arrow DownOpens a filter's menu.
Arrow keysMove between the options of an open menu; Space checks one, the menu stays open.
EscCloses the menu and returns to its button.

Bonnes pratiques

  • Keep the filters in the address: readFilterParams on load, writeFilterParams (which resets the page) on change.
  • Give each active chip the filter's name and value (“Status: Failed”), not the value alone.
  • Count the results in results (“42 jobs”): it is announced when it changes.
  • Use FilterMenu for a list of values (checkboxes, or radios with multiple={false}), a DateRangePicker for a period.

Générée depuis le code de @krizaka/ui 2.4.0 : son meta.ts, ses exemples et ses types.Modifier cette documentation sur GitHub

Sur cette page