datacontroller
z-filterFilter
Filters and sorts a list of items from declarative controls, with animated show/hide, grouped filters, and empty-state handling.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
target | string | '' | 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-active | string | '' | 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. |
animation | FilterAnimation | 'slide' | Transition style when items show/hide: slide (FLIP move/resize), fade, delayed-fade (staggered fade), or none/false/empty for instant updates. |
no-animation | boolean | false | Disables all transition animation regardless of animation. |
duration | number | 250 | Transition duration in milliseconds (default 250). |
Inherited from Base
| Attribute | Type | Default | Description |
|---|---|---|---|
cls | string | '' | Adds classes to named parts as key: classes pairs; a plain string targets the default part. |
stl | string | '' | 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
| Key | Default class | cls | stl | Description |
|---|---|---|---|---|
active | z-active | yes | no | Class toggled on controls whose filter/sort configuration matches the current state (default z-active). |
Events
| Event | Detail | Flags | Description |
|---|---|---|---|
z-filter:after-filter | { state: FilterState; matchingCount: number; totalCount: number } | bubbles | Fires after the state is applied with state, matchingCount, and totalCount. |
z-filter:before-filter | { state: { filter: { [x: string]: string; }; sort: string[]; }; previousState: FilterState } | cancelable, bubbles | Cancelable; 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 } | bubbles | Fires after every applied state change, with the same detail as after-filter. |
z-filter:mount · from Controller | Record<string, unknown> | bubbles | Fires when deferred template content is mounted into the container. |
Methods
| Signature | Description |
|---|---|
apply(controlEl: HTMLElement, animate?: boolean = true): Promise<void> | Applies a control element's configuration (as if it were clicked), optionally without animation. |
getState(): FilterState | Returns a copy of the current state: filter (group → selector map) and sort ([key, order] or []). |
refresh(): void | Re-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
| Attribute | Values | Applies to | Role | Description |
|---|---|---|---|---|
data-filter | — | descendant | config | On a control: the CSS selector an item must match to stay visible. Empty value shows all items. |
data-filter-control | — | descendant | config | Marks 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 | — | descendant | config | Marks an empty-state element; shown only when no items match. |
data-filter-target | — | descendant | config | Marks a container whose children are filtered when target is unset. |
data-fn · from Controller | template | descendant | config | Marks a deferred <template> child whose content is mounted into the container on demand. |
data-group | — | descendant | config | On a control: names an independent filter group, so several groups can be active at once (AND-combined). |
data-order | asc, desc | descendant | trigger | Sort direction on a sort control: asc (default) or desc. |
data-sort | — | descendant | config | On 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
| Keys | Action | When |
|---|---|---|
| Enter Space | Activates the focused filter control (native buttons/links keep their default behavior). | — |
Accessibility
- Controls get
aria-pressed(oraria-selectedforrole="tab") reflecting whether their configuration is active, and are kept button-accessible. - Hidden items receive both
hiddenanddisplay: noneso they leave the layout and accessibility tree.