datacontrollerz-filter

Filter

Filters and sorts a list of items from declarative controls, with animated show/hide, grouped filters, and empty-state handling.

Attributes

AttributeTypeDefaultDescription
targetstring''Selector of the container(s) whose children are filtered. Defaults to owned [data-filter-target] descendants; a selector with no internal match falls back to the document, so external lists work too.
sel-activestring''Selector seeding the initial state from matching controls (e.g. .z-active); false disables seeding. Without it, controls carrying the active class seed the state.
animationFilterAnimation'slide'Transition style when items show/hide: slide (FLIP move/resize), fade, delayed-fade (staggered fade), or none/false/empty for instant updates.
no-animationbooleanfalseDisables all transition animation regardless of animation.
durationnumber250Transition duration in milliseconds (default 250).
Inherited from Base
AttributeTypeDefaultDescription
clsstring''Adds classes to named parts as key: classes pairs; a plain string targets the default part.
stlstring''Adds inline styles to named parts as key: styles pairs; a plain string targets the default part.

Custom Styling (cls / stl)

Default cls target:active · defaultstl target:host-inner

KeyDefault classclsstlDescription
activez-activeyesnoClass toggled on controls whose filter/sort configuration matches the current state (default z-active).

Events

EventDetailFlagsDescription
z-filter:after-filter{ state: FilterState; matchingCount: number; totalCount: number }bubblesFires after the state is applied with state, matchingCount, and totalCount.
z-filter:before-filter{ state: { filter: { [x: string]: string; }; sort: string[]; }; previousState: FilterState }cancelable, bubblesCancelable; fires before a state change with state and previousState in detail. preventDefault() keeps the current state.
z-filter:change{ state: FilterState; matchingCount: number; totalCount: number }bubblesFires after every applied state change, with the same detail as after-filter.
z-filter:mount · from ControllerRecord<string, unknown>bubblesFires when deferred template content is mounted into the container.

Methods

SignatureDescription
apply(controlEl: HTMLElement, animate?: boolean = true): Promise<void>Applies a control element's configuration (as if it were clicked), optionally without animation.
getState(): FilterStateReturns a copy of the current state: filter (group → selector map) and sort ([key, order] or []).
refresh(): voidRe-indexes items, re-syncs control classes/ARIA, and re-applies the current state without events.
reset(animate?: boolean = true): Promise<void>Clears all filters and sorting (back to the original order).
setState(state: Partial<FilterState>, animate?: boolean = true): Promise<void>Sets the state directly, firing before-filter/after-filter/change; resolves when transitions finish.

Data Hooks

AttributeValuesApplies toRoleDescription
data-filter—descendantconfigOn a control: the CSS selector an item must match to stay visible. Empty value shows all items.
data-filter-control—descendantconfigMarks a clickable control. The value is a filter selector, or filter: …; group: …; sort: …; order: … options; separate data-filter/data-group/data-sort/data-order attributes override the parsed keys.
data-filter-empty—descendantconfigMarks an empty-state element; shown only when no items match.
data-filter-target—descendantconfigMarks a container whose children are filtered when target is unset.
data-fn · from ControllertemplatedescendantconfigMarks a deferred <template> child whose content is mounted into the container on demand.
data-group—descendantconfigOn a control: names an independent filter group, so several groups can be active at once (AND-combined).
data-orderasc, descdescendanttriggerSort direction on a sort control: asc (default) or desc.
data-sort—descendantconfigOn a control: the attribute to sort by (data-<key> is also checked), or :text for text content. Empty value clears sorting. Numeric values sort numerically.

Keyboard

KeysActionWhen
Enter SpaceActivates the focused filter control (native buttons/links keep their default behavior).—

Accessibility

  • Controls get aria-pressed (or aria-selected for role="tab") reflecting whether their configuration is active, and are kept button-accessible.
  • Hidden items receive both hidden and display: none so they leave the layout and accessibility tree.