Home > widget-integration > FilterController > handleClickOutside

FilterController.handleClickOutside property

Sets up a click outside handler for an element. Executes a callback when a click occurs outside the specified root element.

Automatically removes the event listener after the first outside click is detected, preventing memory leaks and ensuring one-time use behavior.

Signature:

handleClickOutside: (rootElm: any, callback: any) => () => void;

Remarks

This utility is commonly used for closing dropdowns, modals, or popups when the user clicks outside. The listener is automatically cleaned up after first trigger.

Example

Override to add custom outside click logic:

window.boostWidgetIntegration.extend('FilterController', (FilterController) => {
  return class CustomFilterController extends FilterController {
    handleClickOutside(rootElm, callback) {
      const enhancedCallback = (target) => {
        // Log analytics before closing
        this.trackOutsideClick(rootElm.id, target);
        callback(target);
      };
      return super.handleClickOutside(rootElm, enhancedCallback);
    }
  };
});