Skip to main content
Neighborhood Design System v5.0.0-rc.2

Filters

Ready

Filters component provides a user-friendly interface for refining search or data results.

Preview

Open in Storybook (opens in new tab)

Code

Install
npm install @fbin-web/neighborhood-core
Import
import { NbhdFilters } from '@fbin-web/neighborhood-core';
Usage
<nbhd-filters total-results="10">
</nbhd-filters>


<script>
  const filters = document.querySelector('nbhd-filters');

  filters.filters = [
    {
      title: 'Category',
      key: 'category',
      expanded: false,
      description: 'Integer posuere erat a ante venenatis dapibus posuere velit aliquet.',
      options: [
        {
          label: 'Kitchen',
          count: 420,
          value: 'Kitchen',
          selected: false,
        },
        {
          label: 'Kitchen Faucets',
          count: 418,
          value: 'Kitchen Faucets',
          selected: false,
        },
        {
          label: 'Kitchen Sink Faucets',
          count: 416,
          value: 'Kitchen Sink Faucets',
          selected: false,
        },
        {
          label: 'Smart Home',
          count: 22,
          value: 'Smart Home',
          selected: false,
        },
        {
          label: 'Kitchen Accessories',
          count: 2,
          value: 'Kitchen Accessories',
          selected: false,
        },
        {
          label: 'Dispensers',
          count: 2,
          value: 'Dispensers',
          selected: false,
        },
        {
          label: 'Parts',
          count: 2,
          value: 'Parts',
          selected: true,
        },
      ],
    },
    {
      title: 'Collection',
      key: 'Collection',
      expanded: false,
      options: [
        {
          label: 'Align',
          count: 10,
          value: 'Align',
          selected: false,
        },
        {
          label: 'Sleek',
          count: 8,
          value: 'Sleek',
          selected: false,
        },
        {
          label: 'Chateau',
          count: 31,
          value: 'Chateau',
          selected: false,
        },
        {
          label: 'Adler',
          count: 19,
          value: 'Adler',
          selected: false,
        },
        {
          label: 'Camerist',
          count: 17,
          value: 'Camerist',
          selected: false,
        },
      ],
    },
    {
      title: 'Finish',
      key: 'Finish',
      tooltip: 'Select your favorite colors',
      expanded: false,
      options: [
        {
          label: 'Chrome',
          count: 288,
          value: 'chrome',
          selected: false,
          finishImage: 'https://moen.widen.net/content/3d7ihxrfrz/png/chrome_100.png',
        },
        {
          label: 'Spot Resist Stainless',
          count: 261,
          value: 'spot resist stainless',
          selected: true,
          finishImage: 'https://moen.widen.net/content/3d7ihxrfrz/png/chrome_100.png',
        },
        {
          label: 'Matte Black',
          count: 129,
          value: 'matte black',
          selected: true,
        },
        {
          label: 'Classic Stainless',
          count: 58,
          value: 'classic stainless',
          selected: false,
        },
        {
          label: 'Oil Rubbed Bronze',
          count: 55,
          value: 'oil rubbed bronze',
          selected: false,
        },
        {
          label: 'Brushed Gold',
          count: 36,
          value: 'brushed gold',
          selected: false,
        },
        {
          label: 'Stainless',
          count: 32,
          value: 'stainless',
          selected: false,
        },
        {
          label: 'Bronzed Gold',
          count: 31,
          value: 'bronzed gold',
          selected: false,
        },
        {
          label: 'Mediterranean Bronze',
          count: 30,
          value: 'mediterranean bronze',
          selected: false,
        },
        {
          label: 'Polished Nickel',
          count: 28,
          value: 'polished nickel',
          selected: false,
        },
      ],
    },
    {
      title: 'Type Of Handles',
      key: 'Type of Handles',
      expanded: false,
      options: [
        {
          label: 'Lever Handles',
          count: 404,
          value: 'Lever handles',
          selected: false,
          tooltip:
            'Nulla vitae elit libero, a pharetra augue. Etiam porta sem malesuada magna mollis euismod.',
        },
        {
          label: 'Knob Handles',
          count: 10,
          value: 'Knob handles',
          selected: false,
        },
        {
          label: 'Lever And Knob Handles',
          count: 2,
          value: 'Lever and knob handles',
          selected: false,
        },
        {
          label: 'Lever And Cross Handles',
          count: 1,
          value: 'Lever and cross handles',
          selected: false,
        },
      ],
    },
    {
      title: '',
      key: 'facets-1',
      options: [{ label: 'Option 1' }, { label: 'Option 2' }, { label: 'Option 3' }],
    },
  ];
</script>

Properties

PropertyAttributeTypeDefaultDescription
filters—FilterGroup[][]Array of filter groups and their options. This property is not settable via attribute.
surfacesurfacenoneprimarysecondaryinverseinverse-secondaryprimarySurface color for the component.
headingheadingstringFiltersHeading displayed for the filters component.
headingLevelheading-level1234564Level of the "Filters" heading. Match it to the page outline.
clearFiltersLabelclear-filters-labelstringRemove allLabel for the button that clears all selected filters.
maxVisibleOptionsmax-visible-optionsnumber3Maximum number of filter options displayed before the expand button is shown.
expandLabelexpand-labelstringShow moreLabel for the button that displays additional filter options.
collapseLabelcollapse-labelstringShow lessLabel for the button that hides additional filter options.
totalResultstotal-resultsnumber0Total number of results used to determine whether a filter group should be visually hidden.
countStylecount-styleroundsquarecurlysquareBracket style used to display filter option counts.
removeFilterLabelremove-filter-labelstringRemove filterPrefix for each selected-filter chip’s accessible name, e.g. "Remove filter: Chrome".
resultsAnnouncementresults-announcementstring{count} resultsAnnounced to screen readers after a filter change once `total-results` updates. `{count}` is replaced with the result count.

Filter Group Structure

Structure for FilterGroup objects used in the filters property.

PropertyTypeRequiredDescription
keystringYesUnique identifier for the filter group.
titlestringNoDisplay title for the filter group.
descriptionstringNoAdditional description for the filter group.
expandedbooleanNoWhether the filter group is expanded by default.
tooltipstringNoTooltip text to display for the filter group.
optionsFilterOption[]NoArray of filter options within this group.

Filter Option Structure

Structure for FilterOption objects used within the FilterGroup options property.

PropertyTypeRequiredDescription
labelstringYesDisplay label for the filter option.
countnumberNoNumber of results for this filter option.
tooltipstringNoTooltip text for the filter option.
selectedbooleanNoWhether the filter option is currently selected.
hrefstringNoURL associated with the filter option.
valuestringNoValue associated with the filter option.
finishImagestringNoImage URL for finish-related filter options.

Events

NameDescriptionEvent Detail
nbhd-filter-changeEmitted when filter selections change.{ selectedFilters: FilterOptionEmitted[] }

CSS Parts

NameDescription
baseThe root filters component container.
sidebarThe desktop sidebar container.
sidebar-filter-groupsThe filter groups container in the desktop sidebar.
drawerThe mobile filter drawer container.
headerThe filters header containing the heading and clear action.
headingThe filters heading text element.
selected-filtersThe container for selected filter buttons.
selected-filterAn individual selected filter button.
filter-group-toggleThe button that expands or collapses a filter group.
filter-group-panelThe expandable panel containing a filter group's options.
checkboxAn individual filter option checkbox.
imageThe finish image wrapper for filter options with finish images.
tooltipThe filter tooltip container.
tooltip-descriptionThe filter tooltip description text.
sidebar-clearThe clear filters action in the desktop sidebar.
drawer-backdropThe backdrop behind the mobile filter drawer.
drawer-panelThe mobile filter drawer panel.
drawer-actionsThe action area in the mobile filter drawer.
drawer-clearThe clear filters action in the mobile drawer.
drawer-doneThe done action in the mobile drawer.
drawer-closeThe button that closes the mobile filter drawer.
drawer-bodyThe content area of the mobile filter drawer.
drawer-filter-groupsThe filter groups container in the mobile drawer.
nbhd-filters::part(base) {
  /* your styles */
}

Dependencies

Child components <nbhd-filters> renders internally. Import them too when you tree-shake.

Esc
↑ ↓ to move↵ to open