# Filter bar

A **Filter bar** is a horizontal collection of non-editable pills used to represent the currently applied filters.

## Usage

The filter bar is placed above specific parts of the page, making it clear that only those parts will reflect the applied filters.

![Filter bar](<../images/filter-bar.png>)

### When to use

- Use it to represent the currently applied filters. The filters themselves must be set or changed using separate functionality.
- Use it if the filter doesn't have to be inline editable.
- Use it if more than 2-3 filter criteria need to be applied at the same time.

### Best practices

- Use one filter pill per filter category.
- If only one option is selected, show the value (e.g. `Munich`).
- If more than one option is selected, show the criteria name in plural with a counter (e.g. `7 cities`).
- Don't use a filter bar if you need to provide inline filter editing functionality. Use the [filtered search component](<https://element.siemens.io/components/sorting-filtering/filtered-search/>) instead.
- Use an alternative text like `Applied filters` to make it accessible for visually impaired people and screen readers.

## Design

### Elements

![Filter bar - Elements](<../images/filter-bar-elements.png>)

> 1. Filter pills, 2. Reset filters button

### Interaction states

As the filter bar does not have a representation on its own, all interaction states correspond to the *filter pills* and the *reset button*.

The *filter pills* container color should always be in contrast with its surrounding background. Use `background-0` or `background-1` according to that.

The filter bar can be hidden completely, if no filter is applied.

![Filter bar - Interaction states](<../images/filter-bar-states.png>)

### Responsive design

When reducing the viewport width, the filter pills should be grouped/combined dynamically. The filter bar must not have a scroll bar and should never hide the applied filters.

![Filter bar - Responsive design](<../images/filter-bar-responsive.png>)

## Code

The filter bar is created for the purpose of user filtering and should be used in combination with tables, lists, etc. This component serves as a visual component, and always maintains the state of current active filters returned by `filtersChange` output event, which triggers every time a user removes an item from a filter. A two-way data-binding is also possible, e.g. `[(filters)]="myFilters"`.

### Usage

```
import { SiFilterBarComponent } from '@siemens/element-ng/filter-bar';

@Component({
  imports: [SiFilterBarComponent, ...]
})
```

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject } from '@angular/core';
import { Filter, SiFilterBarComponent } from '@siemens/element-ng/filter-bar';
import { LOG_EVENT } from '@siemens/live-preview';

@Component({
  selector: 'app-sample',
  imports: [SiFilterBarComponent],
  templateUrl: './si-filter-bar.html',
  host: { class: 'p-5' }
})
export class SampleComponent {
  logEvent = inject(LOG_EVENT);

  filters: Filter[] = [
    {
      filterName: 'temperature',
      title: 'Temperature',
      description: '30°'
    },
    {
      filterName: 'time',
      title: 'Time',
      description: '10:10 AM'
    },
    {
      filterName: 'date',
      title: 'Date',
      description: '27-12-2022'
    },
    {
      filterName: 'company',
      title: 'Company',
      description: 'Siemens'
    },
    {
      filterName: 'location',
      title: 'Location',
      description: 'Zug'
    },
    {
      filterName: 'only-key',
      title: 'Only Key',
      description: ''
    },
    {
      filterName: 'only-value',
      title: '',
      description: 'Only Value'
    }
  ];
}
```

Template:

```html
<h4>Variant Light</h4>
<div class="px-4">
  <si-filter-bar [filters]="filters" (filtersChange)="logEvent($event)" />
</div>

<div class="clearfix mt-8"></div>
<h4>Variant Dark</h4>
<div class="background-1 px-4">
  <si-filter-bar colorVariant="base-0" [filters]="filters" (filtersChange)="logEvent($event)" />
</div>

<div class="clearfix mt-8"></div>
<h4>Variant Light Disabled</h4>
<div class="px-4">
  <si-filter-bar disabled [filters]="filters" (filtersChange)="logEvent($event)" />
</div>

<div class="clearfix mt-8"></div>
<h4>Variant Dark Disabled</h4>
<div class="background-1 px-4">
  <si-filter-bar
    disabled
    colorVariant="base-0"
    [filters]="filters"
    (filtersChange)="logEvent($event)"
  />
</div>
```

### [SiFilterBarComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L43-L127>)

**Kind:** component

**Selector:** `si-filter-bar`

```
import { SiFilterBarComponent } from '@siemens/element-ng/filter-bar';
```

```
component SiFilterBarComponent
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [allowReset](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L75-L75>) | `boolean` | `true` | Set false to hide reset filters button |
| [collapsedFiltersDescription](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L97-L99>) | `TranslatableString` | `` $localize`:@@SI_FILTER_BAR.COLLAPSED_FILTERS_DESCRIPTION:+ {{count}} criteria` `` | Custom text for the collapsed filters. |
| [colorVariant](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L81-L81>) | `BackgroundColorVariant` | `'base-1'` | Color to use for component background |
| [disabled](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L88-L88>) | `boolean` | `false` | Set to true to disable component |
| [filterDefaultText](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L52-L54>) | `TranslatableString` | `` $localize`:@@SI_FILTER_BAR.NO_FILTERS:No filters applied` `` | Custom text if no filters are selected. |
| [filters](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L60-L60>) | `Filter[]` | `[]` | Array of filter items to show |
| [resetText](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L69-L69>) | `TranslatableString` | `` $localize`:@@SI_FILTER_BAR.RESET_FILTERS:Reset filters` `` | Text for reset button |

#### Output Properties

| Name | Type | Description |
| --- | --- | --- |
| [filtersChange](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L60-L60>) | `Filter[]` | Array of filter items to show |
| [resetFilters](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/si-filter-bar.component.ts#L104-L104>) | `void` | Output callback to be executed when the reset filter is clicked |

### Types Documentation

### [BackgroundColorVariant](<https://github.com/siemens/element/blob/main/projects/element-ng/common/models/color-variant.model.ts#L8-L8>)

**Kind:** type alias

```
import type { BackgroundColorVariant } from '@siemens/element-ng/common';
```

Use this type with filter components `colorVariant` to render component variants based on background of container

```
type BackgroundColorVariant = 'base-1' | 'base-0'
```

### [Filter](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/filter.ts#L14-L36>)

**Kind:** interface

```
import type { Filter } from '@siemens/element-ng/filter-bar';
```

```
interface Filter
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [description](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/filter.ts#L29-L29>) (optional) | `TranslatableString` | Short description of filter pill. Can be left empty if [title](<index.html#t:Filter.title>) is used to align the title to middle of pill. |
| [filterName](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/filter.ts#L19-L19>) | `string` | Identification name of filter pill. Is not shown to the user, please specify either a [title](<index.html#t:Filter.title>) or a [description](<index.html#t:Filter.description>). |
| [status](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/filter.ts#L35-L35>) (optional, deprecated) | `FilterStatusType` | Deprecated: The status property has been deprecated as it no longer has any visual effect on filter pills. This property will be removed in the next major version. Please remove this property from your Filter objects as it is now ignored by the filter component. |
| [title](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/filter.ts#L24-L24>) (optional) | `TranslatableString` | Shown title of filter pill. Can be left empty if [description](<index.html#t:Filter.description>) is used. |

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```

### [FilterStatusType](<https://github.com/siemens/element/blob/main/projects/element-ng/filter-bar/filter.ts#L12-L12>)

**Kind:** type alias

```
import type { FilterStatusType } from '@siemens/element-ng/filter-bar';
```

Deprecated: FilterStatusType has been deprecated as it no longer has any visual effect on filter pills. This type will be removed in the next major version. Please remove any usage of the `status` property from your Filter objects as it is now ignored by the component.

```
type FilterStatusType = 'default' | 'success' | 'info' | 'warning' | 'danger' | 'inactive'
```
