Home > widget-integration > FilterRender

FilterRender class

Rendering service for filter widget UI components.

Manages all DOM rendering operations for the filter widget, including filter options, refine-by tags, view more buttons, collection headers, and mobile/desktop layouts. Coordinates with FilterStore for state management and FilterHelper for utilities.

Signature:

export declare class FilterRender 

Remarks

This service handles complex rendering logic including: - Filter option rendering (list, box, swatch, rating, multi-level) - Dynamic "View More" state management - Mobile vs desktop layout differences - Collapse/expand state persistence - Filter tree lazy loading - Collection header rendering

Technical Support teams can extend this service to customize rendering behavior, add shop-specific UI elements, or modify filter display logic.

Example 1

Extend to customize filter option rendering:

window.boostWidgetIntegration.extend('FilterRender', (FilterRender) => {
  return class CustomFilterRender extends FilterRender {
    async renderOptionList(params) {
      // Add custom badge to filter options
      await super.renderOptionList(params);
      const container = params.dom.querySelector('.boost-sd__filter-option-list');
      if (container) {
        container.insertAdjacentHTML('afterbegin', '<div class="custom-badge">New</div>');
      }
    }
  };
});

Example 2

Override collection header rendering:

window.boostWidgetIntegration.extend('FilterRender', (FilterRender) => {
  return class extends FilterRender {
    async renderCollectionHeader() {
      await super.renderCollectionHeader();
      // Add custom collection description
      const header = document.querySelector('#boost-sd__collection-header');
      if (header) {
        header.insertAdjacentHTML('beforeend', this.getCustomDescription());
      }
    }
  };
});

Constructors

Properties

Property

Modifiers

Type

Description

NOUI_HANDLE_OFFSET

protected

string

Horizontal offset applied to noUi handles in RTL mode.

sliderCleanupMap

protected

readonly

Map<string, () => void>

Tracks drag-listener cleanup functions per filter option. Keyed by filterOptionId (stable across DOM swaps) so that document-level mouseup/touchend listeners are always removed before re-registering, even when the slider Element itself is replaced by lazyLoadFilterTree.

Methods

Method

Modifiers

Description

addFilterBoxSelectedClass(key, value)

Adds selected class to filter box option

addFilterListSelectedClass(key, value)

Adds selected class to filter list option

addFilterSelectedClass(key, value, displayType)

Adds selected class to filter option based on display type

addFilterSwatchSelectedClass(key, value)

Adds selected class to swatch filter option

addOptionList(action)

protected

Adds a filter option to the selected filters (multiple selection) Appends to existing filters and updates URL with new value

addRangeValueToFilterTree(filterTree, option, action, horizontalHasApplyButton)

protected

Adds range value to filter tree

applyFilterOption(action)

Applies filter option changes Handles scrolling, closing horizontal options, and resetting filter state

applyHandleTranslate(handle, translatePercent, isRtl)

protected

Applies a CSS translate transform to a handle's parent origin element.

applyParallaxEffect()

protected

Applies parallax effect to collection header image Migrated from collection-header/parallax.js

applySliderValue(key, value, ctx)

protected

Applies a validated slider value: updates state, syncs DOM, persists to store, and commits the filter tree change. Called by keyboard and blur interactions. Protected to allow override in shop-specific integrations.

attachInputBlurHandler(input, type, ctx)

protected

Attaches a blur handler that validates the typed value and calls applySliderValue when the committed value differs from the current slider state. Uses blur (not change) so it only fires on actual user interaction.

attachKeyboardInteraction(handle, type, ctx)

protected

Attaches keyboard arrow-key navigation to a slider handle. Moves the handle by sliderStep on ArrowLeft/ArrowRight, debounced to 500 ms.

backFilterTreeMobile()

Navigates back in mobile filter tree Resets mobile filter state to show all filter options

bindEventSearchOption(option, optionDom, filterTreeParent)

protected

Binds search event for filter option

bindingToolbarFilterMobileStyle(option)

protected

Binds toolbar for mobile filter style Updates title and clear button

buildAttributeDataFilterOptionListItem(rawAction, option)

Sets the data-filterOptionId attribute on filter option DOM elements.

Updates both desktop and mobile DOM containers for a filter option with the filterOptionId from the option configuration, used for event routing.

buildBackgroundColor(label)

protected

Builds background color from label (extracts last segment after hyphen)

buildEventFilterOptionCollapsed(rawAction, metadata)

Sets data-metadata attributes on collapse toggle elements.

Attaches collapse/expand metadata to the toggle button and its SVG child elements for both desktop and mobile layouts, enabling event delegation.

buildSliderContext(dom, option)

protected

Collects all DOM references and computed settings into a single context object. Returns null if the slider DOM node is not present in the container.

buildSwatchSettings(value)

protected

Builds swatch settings from filter settings

buildUrlWithLocalization(path)

protected

Builds a URL with a localization prefix when necessary.

Detects a 2-letter ISO locale code (e.g., fr, de) from the current pathname and prepends it to the given path. English (en) is excluded because Shopify typically omits it from URLs.

clearAllFilters(options)

Clears all active filters and resets the filter state.

Removes all selected filters from state, clears all URL query parameters, emits FILTER_RESET to trigger a new API call, and scrolls to the top.

clearAllFiltersDomState(selectedFilters, target)

protected

Clears selected filter UI immediately, including the active mobile panel.

clearFilter(action, options)

Clears one or more filters from the active filter state Removes filters from the filter tree, updates URL, and triggers API call if needed

clearRefineByDomState()

protected

Clears refine-by containers that otherwise retain old labels until AJAX render completes.

clearResetFilterOptionDomState(keys, removedFilters, remainingFilters, target)

protected

Clears selected UI for one mobile filter option before AJAX results return.

closeFilterOptionHorizontalOpening()

Closes all horizontally opened filter options Updates collapse state to close any open options

closeMobileFilterTree()

Closes mobile filter tree

commitFilterTreeChange(newFilterTree, ctx)

protected

Commits a resolved filter tree to the store, emits FILTER_RESET for vertical layouts, and dispatches the range-slider-change analytics event.

computeHandleTranslate(value, min, valueRange)

protected

Returns the CSS translate-X percent that positions a handle at the given value.

createButtonClearOrClearAll(type, optionId)

Creates a clear or clear-all button element for the mobile filter toolbar.

Generates a <button> pre-configured with the correct action metadata for either clearing a single filter option or all active filters.

createDragHandlers(ctx)

protected

Creates the three drag event handlers (pointerdown, pointermove, pointerup equivalents). Drag state is shared between the handlers through closure variables.

determineScrollTarget()

protected

Determines the appropriate scroll target based on layout and sticky settings Returns scroll options for the current filter configuration

dispatchEventChangeRangeSlider(data)

protected

Dispatches a boost-sd-range-slider-change custom event for analytics.

dispatchEventReViewCollection()

protected

Dispatches analytics event for collection view

expandCollapseMultiLevel(action)

Expands or collapses multi-level filter options Manages state persistence for multi-level filter option expansion

fillFilterTree()

Fills filter tree with complete data from available options Enriches selected filters with missing display values and metadata

formatFromToKey(from, to)

protected

Formats from-to key for price/percent filters

formatRangeSliderCurrency(container)

Formats currency symbols for range slider unit elements. This method is public to allow FilterController to delegate currency formatting.

formatWithDelimiter(value, delimiter)

protected

Formats number with thousand separator (delimiter from sliderDelimiter)

generateFilterDataForRange(key, value, option)

Generates filter data object for range filters

getActiveDesktopFilterTreeParent()

protected

getActiveFilterDocument()

protected

getClearAllDomRoots(target)

protected

Returns DOM roots that can contain selected filter state during mobile fullscreen mode.

getCollectionData(params)

protected

Gets collection data for header Migrated from collection-header/index.js

getFilterOptionToggleStateForClose(currentAction)

protected

Gets toggled state for closing a filter option Helper method for closeFilterOptionHorizontalOpening

getLimitOptionValues(option, size)

Returns a slice of option values up to the given size limit.

getNumberViewMore(option, isFilterTreeVertical)

Gets the number of items to show before the "View More" button.

Returns the configured threshold for the view more button, which may be customized globally via window.boostWidgetIntegrationConfig.startViewMore.

getSelectedKeysFilter()

Returns a lookup map of currently selected filter value keys.

Builds a Record<string, boolean> where keys follow the pattern "filterOptionId-value" (lowercased), used for O(1) selected-state checks during template rendering.

handleCollapse(action)

Applies a single collapse action to the filter tree DOM.

Adds or removes CSS classes on the target elements specified in the action object, scoped to the current filter tree parent element.

handleCollapsedChange()

Applies the current collapse state to all filter option DOM elements.

Iterates over stored collapseState entries and adds or removes CSS classes on target elements to keep the DOM in sync with the current state.

handleCollectionOption(action)

Main handler for collection option clicks.

Routes collection filter selections to the appropriate handler based on current page context. On collection pages, redirects to the selected collection. On search pages, updates filters to show products from the selected collection.

handleFillFilterTree()

protected

Handles the actual filling of filter tree with option data

handleFilterTreeResponsive()

Handles responsive behavior for filter tree Manages display switching between mobile and desktop layouts

handleShowResult(target)

Handles showing results for off-canvas filter Closes the off-canvas filter when clicking result button, close button, or overlay

handleToggle(action, containerId)

protected

Toggles classes on target elements Used for expand/collapse functionality

hideDesktopVerticalFilterColumn(targetElement)

protected

initFilterOptionCollapse()

Initializes collapse/expand state for all active filter options.

Computes and sets the initial collapseState for every active filter option based on isCollapsePC/isCollapseMobile settings, layout, and any persisted toggle state when keepToggleState is enabled. Also registers Escape key support to close the currently focused filter option.

initHandlePositions(ctx)

protected

Sets initial handle transforms and z-indexes from persisted slider state.

initSliderOption(option, filterTree, inputLower, inputUpper)

protected

Initializes slider option from filter tree state

isCollectionPage()

protected

Checks if the current page is a collection page.

isFilterOptionSupported(displayType)

protected

Checks if display type is supported

isViewMoreFilterOption(option)

Checks if the option uses "view more" pagination.

keepStateMultipleLevelOptionItems()

protected

Keeps state for multiple level option items

lazyLoadFilterTree()

Lazy loads the filter tree to improve initial page load performance.

Implements progressive rendering by initially loading a limited number of filter options (LIMIT_FIRST_LOAD), then rendering remaining options asynchronously. This prevents blocking the main thread during filter initialization.

manageViewMoreState(params)

Manages view more state and rendering for filter options.

Controls the "View More" / "View Less" functionality that shows/hides additional filter values when there are many options. Updates state and re-renders the affected filter option with the appropriate number of values displayed.

normalizeRangeValue(val, removeDecimal, option)

protected

Normalizes a numeric slider value with proper snapping to sliderStep. Protected to allow override in shop-specific integrations.

optionCollection(action)

optionList(action)

Handles filter option list selection/deselection.

Main handler for list-style filter option clicks. Manages both single-select and multi-select filter types, updating state, URL parameters, and triggering API calls to refresh product results.

persistRangeState(ctx)

protected

Persists the current sliderOption into the rangeFilter store entry.

reCalcWidthFilterOptionHorizontal(filterTreeHorizontalStyle, filterLayout)

protected

Recalculates width for horizontal filter options Adapts position left or right based on viewport

redirectCollection(action)

protected

Redirects to collection page (for collection page context)

removeDomFilterOptionIfEmpty(rawAction, option)

Removes the filter option DOM element when it has no values.

Removes both desktop and mobile DOM nodes for a filter option when its values array is empty, preventing empty filter sections from displaying.

removeFilterBoxSelectedClass(key, value)

Removes selected class from filter box option

removeFilterListSelectedClass(key, value)

Removes selected class from filter list option

removeFilterSelectedClass(key, value, displayType)

Removes selected class from filter option based on display type

removeFilterSwatchSelectedClass(key, value)

Removes selected class from swatch filter option

removeRangeValueFromFilterTree(filterTree, option)

protected

Removes range value from filter tree

renderCollectionHeader()

Renders the collection header with title, description, and metadata.

Dynamically generates the collection header HTML including the collection name, description, image, and product count. Handles both collection pages and collection-filtered search results.

renderFilterOption(dom, option, limit)

protected

Renders filter option based on display type

renderFullFilterOption(dom, option)

Renders a complete filter option with all its values and controls.

Main rendering method that orchestrates the display of a single filter option, including its title, values, search box (if enabled), and view more controls. Routes to specialized rendering methods based on display type.

renderLazyFilterOption(dom, option)

protected

Sets up lazy loading for filter option

renderListContent(dom, option, limit)

protected

Main rendering logic for list options

renderMultiLevelCollectionContent(dom, option, limit)

protected

Main rendering logic for multi-level collection

renderMultiLevelTagContent(dom, option, limit, firstRender)

protected

Main rendering logic for multi-level tag

renderOptionBox(params)

Unified renderOptionBox with lazy loading and full render support

renderOptionBoxTemplate(params)

Renders filter option values using the box/grid template.

Generates HTML for box-style filter options displayed in a grid layout. Commonly used for visual filters like size or style options.

renderOptionList(params)

Unified renderOptionList with lazy loading and full render support

renderOptionListTemplate(params)

Renders filter option values using the list template.

Generates HTML for list-style filter options with checkboxes and labels. Supports document count display and selected state management.

renderOptionMultiLevelCollection(params)

Renders multi-level collection filter with hierarchical structure.

Generates HTML for nested collection filters that support parent-child relationships. Includes expand/collapse controls for subcollections.

renderOptionMultiLevelTag(params)

Renders multi-level tag filter with hierarchical structure.

Generates HTML for nested tag filters supporting parent-child relationships. Similar to multi-level collections but for product tags.

renderOptionRangeSlider({ dom, option })

Renders range slider for price/rating filters.

Orchestrates DOM initialization, keyboard/blur/drag interaction wiring, and listener cleanup for the custom range slider widget.

renderOptionRating(params)

Renders rating filter options with star displays.

Generates HTML for review rating filters, showing star icons and product counts for each rating level. Commonly used with review integration services.

renderOptionSwatch(params)

Unified renderOptionSwatch with lazy loading and full render support

renderOptionSwatchTemplate(params)

Renders filter option values using the swatch template.

Generates HTML for color/image swatch filter options. Supports different swatch shapes (circle/square) and layout types (grid/list).

renderOptionTemplate(params)

protected

Unified option rendering logic Handles list, box, and swatch display types

renderRatingContent(dom, option, limit)

protected

Main rendering logic for rating options

renderRefineBy()

Renders the "Refine By" section showing active filter selections.

Displays all currently selected filters as removable tags, allowing users to see and clear their active selections. Includes a "Clear All" button when multiple filters are selected.

renderRefineByHorizontal(data)

protected

Renders "Refine By" section for horizontal layout

renderRefineByMobile(data)

protected

Renders "Refine By" section for mobile layout

renderRefineByVertical(data)

protected

Renders "Refine By" section for vertical layout

renderSelectedOption()

Renders selected options in the filter tree UI Adds selected class to their DOM elements

renderSingleSwatch(value)

protected

Renders single swatch value with background color/image

renderSwatchContent(dom, option, limit)

protected

Main rendering logic for swatch options

renderViewMore(filterOptionId, filterOptionDisplayType)

Renders the updated filter option values when view more is toggled.

Retrieves the current view more state, determines which values to display (limited or all), and re-renders the filter option using the appropriate template (list, box, or swatch).

replacePrefixValue(option, value)

protected

Replaces prefix value based on option settings

resetFilterOption(action, target)

Resets a specific filter option Removes the filter from state, updates URL params, and triggers API refresh

sanitizeSliderStep(sliderStep, sliderRange, min, max)

protected

Sanitizes sliderStep/sliderRange inputs, applying NaN fallbacks and the max-step cap.

scheduleMobileFullscreenCleanup(mobile, options)

protected

searchPageCollection(action)

protected

Handles collection filter in search page context

setActiveHandleZIndex(activeKey, minHandle, maxHandle)

protected

Elevates the active handle to z-index 5 and lowers the inactive one to 4.

setMobileFilterTreeIconActive(isActive)

protected

setOptionList(action)

protected

Replaces filter option selection (single selection) Removes existing values for the key and sets new value

setupLazyLoadMultiLevelCollection(dom, id, option)

protected

Sets up lazy loading for multi-level collection

setupLazyLoadMultiLevelTag(dom, id, option)

protected

Sets up lazy loading for multi-level tag

setupLazyLoadOptionBox(dom, id, option)

protected

Sets up lazy loading for option box

setupLazyLoadOptionList(dom, id, option)

protected

Sets up lazy loading for list options

setupLazyLoadOptionRating(dom, id, option)

protected

Sets up lazy loading for rating options

setupLazyLoadOptionSwatch(dom, id, option)

protected

Sets up lazy loading for swatch options

shouldRenderLazyFilterOption(value, optionDomList)

protected

showDesktopVerticalFilterColumn(targetElement)

protected

showHideSearchBoxOption(rawAction, option)

Shows or hides the search box for a filter option based on platform settings.

Removes the search input DOM node for desktop when showSearchBoxFilterPC is false, or for mobile when showSearchBoxFilterMobile is false.

showMobileFilterTree()

Shows/toggles mobile filter tree Handles display toggle, scroll lock, and lazy loading

syncInputValue(input, value, option)

protected

Writes a value to a text input with delimiter formatting; no-ops safely when the input is null.

toggleAriaExpanded(element)

Toggles aria-expanded attribute on an element

toggleFilterTreeButtonDesktop()

Toggles desktop filter tree button visibility and state Handles horizontal, vertical expand, and vertical off-canvas layouts

toggleFilterTreeIcon()

protected

Toggles filter tree icon active state Updates tabindex for accessibility when filter button is clicked

toggleHiddenClass(action, targetSelector)

protected

Toggles hidden class on filter option item wrappers

updateCollectionHeaderProductCount()

Updates only the product count inside the collection header. Used after sort/filter changes to avoid full re-render flicker.

updateValueDisplayFromSwatch(data, swatchSettings)

protected

Updates value display from swatch settings Replaces raw values with configured swatch text

xssFilterOption(option, size)

Filters XSS-unsafe values from option values up to the given size.

Iterates option values and excludes any whose label, displayName, or key contains potentially malicious content as detected by FilterValidationHelper.