Filter bar and chips

Filter bar

Status: Paid Last 30 days Country: Thailand
Remove a chip or clear all.

Chips on their own

Draft Selected Add filter

Behavior

  • A chip with a remove button is a span.chip with a button inside. The button needs an aria-label such as "Remove Status: Paid".
  • Removing a chip moves focus to the next chip, or the last one left, so the keyboard keeps its place.
  • The Clear all button (data-clear) is hidden when there are no chips.
  • Chips you add later work too. The script reads the page, so there is nothing to start.
  • Chips outside a .filter-bar are only styled. Handle their buttons yourself.

API

Methods

MethodDescription
tsunami.filterBar.values(bar)The data-value of each chip (its text when there is none).
tsunami.filterBar.clear(bar)Removes every chip and sends tsunami:filterchange.
tsunami.filterBar.mount(root?)Refreshes the Clear all button of each bar inside root.

Events

EventOnDescription
tsunami:chipremovethe chip, bubbles, cancelableSent before a chip is removed. event.detail is { value, label }. Call preventDefault() to keep the chip.
tsunami:filterchangethe .filter-bar, bubblesSent after a chip is removed or all are cleared. event.detail.values lists the chips left.

Keyboard

KeyDescription
TabMoves between the remove buttons and Clear all.
Enter SpaceRemoves the chip, or clears all.

Attributes

Attribute / elementValuesDescription
.chipon a spanThe pill. Put the label first and an optional remove button last.
data-variantaccent, mutedOn a chip: an accent outline, or a dashed quiet one.
data-valuetextOn a chip: what tsunami:chipremove and values() report.
.filter-baron a divA wrapping row of chips. Give it role="group" and an aria-label.
data-clearpresentOn a button in the bar: removes every chip.