Components · Inputs
TagFilter
A filter of several values that shows each value as a tag in the toolbar, with its own ×, a +N for the ones that don't fit, and a × that clears the filter.
import { TagFilter } from "@botiverse/raft-ui/wip";TagFilter is a toolbar filter that takes several values and shows them. Unset, it is a PickerTriggerButton that says the filter's name. Applied, the whole filter is one info-soft group as high as the button: the name, which opens the list; a 24px tag for each value with its own ×; +N for the tags that don't fit; and, when clearable, a × that clears the filter. People see what the filter holds, take one value out, or clear it all, without opening the list (Select › Filters).
When to use
Anatomy
TagFilter: the group, arole="group"named by the filter. It holds the parts below and carries the applied fill. Required.TagFilterTrigger: the filter's name and its optional 14px icon; the button that opens the list. Unset it carries the chevron; applied it doesn't. Required.TagFilterTag: one value, a 24px tag with a 18px ×. One per value shown.TagFilterMore:+N, the values that don't fit. It opens the list as the trigger does.TagFilterClear: the × at the group's end that clears the filter, after a 1px seam. The seam is as far from what comes before it, a tag's edge or+N's text, as from the × after it. Only withclearable.- The list: the combobox popup, anchored to the group's start. A header with the filter's name and Clear, an optional search, and the values with a check on each chosen one, in groups when
groupsis given.
ComboboxTagFilter puts these together over a multiple Combobox; use the parts yourself only for a structure it doesn't cover.
Options
maxTagCount: how many tags show."responsive"(default): as many as fit the group's room, then+N. The group is at most 320px wide, or what its parent gives it if less (outside a FitToolbar, which measures the room itself); set amax-w-*on it for another cap.- A number: at most that many, then
+N. "none": every tag, and the group wraps onto more lines. Use it only where the toolbar can grow taller.
clearable(defaulttrue): the × at the group's end. Leave it on: clearing a filter of several values one tag at a time is slow. Turn it off only when the filter can't be empty.search: a search row at the top of the list, for a list that can hold many values (people, places). With it, giveemptyLabel. Opened with a mouse or the keyboard, typing goes straight to it, and Enter takes the first match; opened by a tap, it takes no focus, so the keyboard doesn't come up over the list. A list of a few fixed values (statuses, outcomes) has none.searchTextOf: what the search matches for a value,labelOfby default. Give people their display name and handle, so a search for either finds them; give a "Me" row its own word with the person's name and handle, so a search for yourself finds it.disabled: the filter can't open yet, while its values load: the trigger takes PickerTriggerButton's disabled look. An empty list that opens is more confusing than a button that waits.popupClassName: the list's width, 240px (w-60) by default. Widen it for long names, such as a computer by code and name.groups, instead ofitems: the list in groups, each{ label?, items }. A group's values sit under its heading (ComboboxGroupLabel), with a separator between groups; a group without alabelshows no heading. The type takes one or the other, never both. When the search leaves a group with nothing, its heading and the separator before it go too, so no line is left on its own.tagLabelOf: a shorter text for a value inside its tag alone, such as a computer's code. Everything else keepslabelOf's full name: the tag's title, its ×'s name, the trigger's name and tooltip, and the search. The ruler measures the short text, since that is what the tag shows.openandonOpenChange: the list's open state, for a page that keeps one filter's list open at a time. Uncontrolled by default.tagsOrderandlabelOrder: its steps in a FitToolbar (below).
In a FitToolbar
An applied filter marks itself data-active, as FitToolbar asks of an applied item, so a scrolling group keeps it in view; the caller adds nothing.
In a FitToolbar the filter gives way with the rest of the toolbar (FitToolbar › Behavior). It doesn't measure its parent's room there: the toolbar does, and two measures of one room would disagree, as SegmentedControl's iconsOnlyBelow is off in a toolbar. It shows every tag the 320px cap holds, and folds into +N within that cap only.
tagsOrder(thetagsstep): its tags fold to the first one and+N, at least one tag kept.labelOrder(thelabelstep): its name hides and its icon stays. The trigger's accessible name and a tooltip keep the name and every value (valueLabel). A filter without aniconrefuses this step, since nothing would be left to show.
Its trigger and, once it is applied, its clear × are the toolbar's items: one or two per filter. The toolbar stays one Tab stop, and its arrow keys go through them in reading order, the trigger, then its clear ×, then the next item; an unset filter is its trigger alone. A tag's × is for a pointer and never a stop. After the clear × takes the filter's values out, focus goes to the trigger, which then holds the toolbar's Tab stop. An item the arrow keys reach under a scrolling group's fade comes into view. Before, the trigger and the clear × were Tab stops of their own inside the toolbar, and its arrow keys didn't reach them (slock's Tasks and search toolbars).
A filter never moves into More: as The toolbar over a list says, the filters wrap to a line of their own that scrolls sideways. Put them in a FitToolbarGroup with overflow="scroll" in a toolbar with wrap, the sort on the first line.
Give tags and label the numbers of The toolbar over a list: a filter's own tags fold first, then its name becomes its icon. At the same number tags comes before label, and the filters of one FitToolbarGroup with the same number fold and unfold together. Items in a FitToolbar don't shrink; truncation happens only within the 320px cap, the tag first, then the name (0.111.2's rule).
States
- Unset: the PickerTriggerButton look, the name and a chevron, as high as the other filter buttons.
- Applied: the group fills
info-softat the same height. The name inside it has no fill of its own; it hovers with the medium overlay (Hover and press). - A tag sits on the canvas colour with a seam ring. Its × is 18px, 3px from the tag's top, bottom and end, so its hover fill stays inside the tag; only the × hovers.
- The clear × is 24px with a 14px glyph, 4px from the group's end; it hovers with the medium fill.
Behavior
- Choosing a value in the list adds its tag at the end; tags keep the order the values were chosen in. The list stays open while people choose.
- A tag's × takes that one value out. The clear × takes them all out, and the filter is unset again.
- After a × removes itself, focus goes to the trigger, never to the page or to the next filter. The trigger's new name says what is left.
- With
maxTagCount="responsive", tags fold into+Nbefore the name is cut, and one tag always shows. When even that one doesn't fit beside the name, the tag gives way first: its label truncates down to a letter, an ellipsis and its ×, and only then the name truncates, so the filter keeps saying what it is ("Destinations [Private c… ×] +2" in a 280px column). The count is measured before the first paint and again when the row resizes, so no frame shows tags that are then taken back. - On a touch screen, each × and
+Nhas a hit area of at least 24px;+Ncounts as part of the trigger (Accessibility › Hit targets).
Content
- Name the filter by what it filters, as a noun: Status, Assignee, Channel. Don't add the word Filter.
- A tag says the value's name as the list does, or a short form of it through
tagLabelOf(a computer's code) when the full name would crowd the toolbar. Keep the icon in the list; the tag carries text only. - A shortcut for the person viewing ("Me") is a plain first row, in an unlabelled first group followed by the separator, then the labelled People group. Its tag says the shortcut's own word (
labelOfreturns "Me"), never expanded to the person's name. Leave the person out of the People group, so the same person can't be two values and two tags. - Name a tag's × "Remove {value}", and the clear × "Clear {filter}": the clear ×'s name always says which filter it clears.
- The caller writes every sentence, in its own language: the trigger's name once values are chosen (
valueLabel, from the labels in order), each tag's × (removeLabel) and the clear × (clearFilterLabel). TagFilter joins no words itself, so a list takes the language's own mark: "Assignee: Kirby, Tenny" in English, the ideographic comma in Chinese (Intl.ListFormat, or the catalog's list pattern).
Accessibility
- The group is a
role="group"named by the filter; the trigger, the tags' × and the clear × are siblings in it, not nested buttons. - Two Tab stops per filter: the trigger and the clear ×. A tag's × is for a pointer (
tabIndex=-1); the keyboard takes a value out by unticking it in the list. In a FitToolbar the trigger and the clear × are toolbar items instead, reached with the arrow keys, and the whole toolbar is one Tab stop (In a FitToolbar). - The clear × is named by
clearFilterLabel, which must name the filter ("Clear Assignee", not "Clear"): in a toolbar of several filters, the arrow keys reach one clear × after another, and a screen reader reads only that name. - The trigger's name and tooltip list every chosen value, the folded ones included ("Assignee: Kirby, Tenny, Lagoon, Scout"); unset, it is the filter's name.
+Nis hidden from screen readers, since the trigger already names those values. - No live region: when the filter clears, focus is on the trigger, and its new name is what a screen reader reads.
Rules
- Use TagFilter for every filter of several values in a toolbar, so all of them read the same way. Don't summarise chosen values as "2 statuses" in the button.
- Keep a filter of one value a PickerTriggerButton: a tag for a single value with no siblings adds nothing.
- Don't put a tag's icon, avatar or colour in the tag. The list shows them; the toolbar stays text.
- Don't nest one filter's group inside another's, or put other controls inside the group.
API
ComboboxTagFilter
TagFilter
Also takes the attributes of its element.
TagFilterClear
Also takes the attributes of its element.
TagFilterMore
Also takes the attributes of its element.
TagFilterTag
Also takes the attributes of its element.
TagFilterTrigger
Also takes the attributes of its element.