Skip to content

FilterBar

A common filter and sort toolbar for e-commerce list pages, supporting sticky positioning, sort switching, pull-down filter panels, and inline filter modes.

Basic Usage

Set sorts and filters to enable basic sorting and filtering functionalities.

Current Sort: { "key": "default", "order": "desc" }

Current Filter: {}

Basic Usage

Inline Filter Mode

Set filter-in-panel to false if you want filters to be displayed directly in the toolbar.

Service
Inline Mode

Advanced E-Commerce Layout (Custom Slot & View Switcher)

In standard major e-commerce websites, it is commonly expected to feature a List/Grid View Toggle Button and Custom Price Range Inputs.

Current Sort: { "key": "default", "order": "desc" } | Current Filter: { "minPrice": null, "maxPrice": null }

Advanced Customization

Use in Nuxt

YhFilterBar can be used directly in Nuxt 3/4 after registering @yh-ui/nuxt. Its sorting, filtering, and slot rendering logic work in SSR and client hydration flows.

Current Sort: { "key": "default", "order": "desc" } | Current Filter: { "minPrice": null, "maxPrice": null }

Nuxt Usage
ts
// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@yh-ui/nuxt'],
  yhUI: {
    // Auto-imported by default
  }
})

API

Props

ParameterDescriptionTypeDefault
sortsSort option listYhFilterSortItem[][]
filtersFilter definition listYhFilterItem[][]
sortCurrent sort state (v-model:sort)YhFilterSort{ key: null, order: null }
filter-valueCurrent filter state (v-model:filterValue)YhFilterValue{}
show-allWhether to render the built-in "All" tabbooleantrue
stickyWhether to enable sticky positioningbooleanfalse
sticky-offsetSticky top offset in pixelsnumber0
filter-in-panelWhether to render filters in the built-in popup panelbooleantrue
theme-overridesComponent-level theme variable overridesRecord<string, string>{}
show-global-filterWhether to show the global filter buttonbooleantrue
show-view-toggleWhether to show the list/grid view toggle buttonbooleanfalse
view-typeCurrent layout mode (v-model:viewType)'list' | 'grid''list'

Events

Event NameDescriptionCallback Parameters
sort-changeTriggered after the current sort state changes(sort: YhFilterSort)
filter-changeTriggered after the current filter value changes(value: YhFilterValue)
view-changeTriggered after the list/grid view mode changes(viewType: 'list' | 'grid')
resetTriggered when the built-in global reset action is used-
confirmTriggered when the built-in panel confirm action is used(value: YhFilterValue)
reset-panelTriggered when resetting a single built-in filter panel(filter: YhFilterItem, value: YhFilterValue)
open-filterTriggered when the built-in global filter button is clicked-

Slots

Slot NameDescriptionParameters
filter-iconCustom content for the built-in global filter icon-
view-iconCustom content for the view toggle icon{ viewType: 'list' | 'grid' }
extraCustom content rendered in the trailing area-
panel-contentCustom content for the active popup filter panel{ filter: YhFilterItem, value: YhFilterValue, toggle: (filter: YhFilterItem, option: YhFilterOption) => void }

Expose

This component does not expose public instance methods or properties.

Theme Variables

Variable NameDefault ValueDescription
--yh-filter-bar-bgvar(--yh-bg-color)Root background
--yh-filter-bar-bordervar(--yh-border-color-lighter)Root border color
--yh-filter-bar-height44pxToolbar height
--yh-filter-bar-tab-colorvar(--yh-text-color-regular)Inactive tab text color
--yh-filter-bar-tab-active-colorvar(--yh-color-primary)Active tab text color
--yh-filter-bar-tab-active-bgvar(--yh-color-primary-light-9)Active tab background token
--yh-filter-bar-tab-radiusvar(--yh-radius-base)Tab radius token
--yh-filter-bar-badge-bgvar(--yh-color-danger)Badge background
--yh-filter-bar-panel-bgvar(--yh-bg-color)Panel background
--yh-filter-bar-panel-shadow0 4px 20px var(--yh-shadow-color)Panel shadow
--yh-filter-bar-panel-opt-bgvar(--yh-fill-color-light)Panel option background
--yh-filter-bar-panel-opt-active-bgvar(--yh-color-primary-light-9)Active panel option background
--yh-filter-bar-panel-opt-active-colorvar(--yh-color-primary)Active panel option text color
--yh-filter-bar-panel-opt-active-bordervar(--yh-color-primary)Active panel option border token
--yh-filter-bar-z-index100Root stacking context

Type Exports

NameDescription
YhFilterBarPropsComponent props type
YhFilterBarEmitsComponent emits type
YhFilterBarSlotsComponent slots type
YhFilterSortOrderSort order union type
YhFilterSortItemSort item type
YhFilterTypeFilter type union
YhFilterOptionFilter option type
YhFilterItemFilter item type
YhFilterValueFilter value shape
YhFilterSortSort state type
YhFilterBarInstanceComponent instance type

Released under the MIT License.