Home > widget-integration > FilterController > addSwatchTooltipScrollHandler

FilterController.addSwatchTooltipScrollHandler() method

Adds scroll event handler to hide tooltip when page scrolls. Attaches a scroll listener that hides the tooltip and auto-removes itself.

This method: - Creates a stable handler reference for proper cleanup - Hides tooltip on scroll event - Auto-removes the listener after first trigger - Prevents duplicate listeners on the same tooltip

Signature:

protected addSwatchTooltipScrollHandler(tooltipContent: any): void;

Parameters

Parameter

Type

Description

tooltipContent

any

The tooltip element to attach handler to

Returns:

void

Remarks

Uses a private property on the tooltip element (_hideOnScrollHandler) to maintain a stable reference for the event handler. This allows proper listener removal and prevents memory leaks.

Example

Override to customize scroll hide behavior:

window.boostWidgetIntegration.extend('FilterController', (FilterController) => {
  return class CustomFilterController extends FilterController {
    protected addSwatchTooltipScrollHandler(tooltipContent) {
      // Add fade-out animation before hiding
      const originalHandler = super.addSwatchTooltipScrollHandler.bind(this);
      if (!tooltipContent._customHideHandler) {
        tooltipContent._customHideHandler = () => {
          tooltipContent.classList.add('fade-out');
          setTimeout(() => {
            originalHandler(tooltipContent);
          }, 200);
        };
      }
      window.addEventListener('scroll', tooltipContent._customHideHandler, { passive: true });
    }
  };
});