Home > widget-integration > PredictiveBundleController

PredictiveBundleController class

Manages predictive bundle rendering, modal behavior, and interaction handling.

Override public methods in this controller to customize modal opening behavior, rendering hooks, or interaction responses without replacing the full module.

Signature:

export declare class PredictiveBundleController extends Controller<PredictiveBundleControllerProps> 

Extends: Controller<PredictiveBundleControllerProps>

Example

window.boostWidgetIntegration.extend('PredictiveBundleController', (PredictiveBundleController) => {
  return class extends PredictiveBundleController {
    notifyAfterRender(payload) {
      window.dispatchEvent(new CustomEvent('shop:predictive-bundle:after-render', {
        detail: payload,
      }));
      super.notifyAfterRender(payload);
    }
  };
});

Constructors

Properties

Property

Modifiers

Type

Description

appService

AppService

boundRoots

protected

Set<HTMLElement>

cartService

CartService

constants

PredictiveBundleConstants

currentBlockType

string

focusTrapService

FocusTrapService

inlineContainerMap

protected

Map<string, HTMLElement>

Maps widgetId → the DOM element that was passed to renderPreparedBundle as targetElement.

modalFocusTrapCleanup

Map<string, () => void>

modalSurfaceService

ModalSurfaceService

navigationHelper

NavigationHelper

ownedWidgetIds

protected

Set<string>

predictiveBundleService

PredictiveBundleService

productLinkSelector

string

productService

ProductService

rootBindings

static

WeakMap<HTMLElement, RootBindingRecord>

runtime

DOMActionRuntime

state

Signal<PredictiveBundleControllerState>

stateService

PredictiveBundleStateService

wcagHelper

WCAGHelper

Methods

Method

Modifiers

Description

activateFocusTrap(surface)

Activates a focus trap for the provided modal surface.

addBundleToCart(target, blockType)

Adds the selected bundle products to cart.

bindRoot(root, blockType)

Binds delegated click and keyboard handlers to a bundle root.

Override getClickActions() or getKeydownActions() to customize the delegated behavior without rewriting the binding lifecycle.

cleanupBoundRoots()

protected

Removes delegated listeners registered by this controller instance.

cleanupFocusTraps()

protected

Clears all focus trap cleanups registered by this controller instance.

cleanupOwnedState()

protected

Clears controller-owned widget state from the shared state service.

closeAllDropdown()

Closes all currently open predictive bundle dropdowns.

closeModal(blockType)

Closes the predictive bundle modal surface.

closePredictiveBundleModal(blockType, options)

Closes the predictive bundle modal and restores focus when appropriate.

connect(props, parent)

Connects the controller to a predictive bundle root element.

destroy()

Releases bound roots, focus traps, and controller-owned bundle state.

ensureModalBindings(blockType)

Ensures delegated handlers are attached to the shared modal surface.

findElementById(root, id)

Finds an element by id within a root node.

getBlockType(blockType)

Resolves the active block type, preferring an explicit value when provided.

getBundleData(widgetId)

Reads cached bundle data for a widget.

getClickActions(root, blockType)

protected

Returns click actions delegated from a predictive bundle root.

Override to add or replace click behavior for shop-specific integrations.

getInteractionContext(target, wrapper)

Resolves the widget and wrapper associated with a user interaction.

getKeydownActions(root, blockType)

protected

Returns keyboard actions delegated from a predictive bundle root.

Override to adjust keyboard interactions without rewriting bindRoot().

getModalId(blockType)

Builds the DOM id used for the modal surface.

getModalSurface(blockType)

Resolves or creates the modal surface for the active block type.

getTargetElementUpdate(blockType)

Resolves the inline target that should receive bundle updates.

handleClickEmbeddedBundle(target, blockType, options)

Opens the modal from an embedded bundle click target.

handleComboboxNavigation(event, target, blockType)

Handles keyboard navigation for variant combobox interactions.

handleDropdownActivation(target)

Opens a dropdown in response to keyboard activation.

handlePopupTrigger(target, blockType)

Handles inline trigger clicks that should open the predictive bundle modal.

notifyAfterRender(payload)

Dispatches the legacy after-render event bridge for bundle integrations.

openModal(blockType, widgetId)

Opens the predictive bundle modal and focuses the first interactive element.

openPredictiveBundleModal(widgetId, blockType, options)

Opens the predictive bundle modal for a widget.

prepareRenderedBundle(bundle)

protected

Calculates bundle state and renders markup once so it can be reused across multiple targets.

prepareSurfaceForBlock(surface, blockType)

Positions the shared modal surface for the active block context.

renderBundleMarkup(widgetId, bundleData, templateName)

Produces HTML for a predictive bundle template.

renderOneBundleByTargetElement(targetElement, bundle, blockType)

Renders a single predictive bundle into a target element.

renderPredictiveBlocksForProductPage(productId, blockType)

Renders predictive bundle blocks on a product page.

renderPredictiveBundleWithData(widgetId, bundleData, wrapper, templateName, blockType, callback)

Renders bundle markup into either the modal wrapper or an inline target.

renderPreparedBundle(targetElement, prepared, blockType)

protected

Applies pre-rendered bundle markup to a target element.

renderRecommendationForSearchPage(predictiveBundles, blockType)

Renders predictive bundles on search and embedded bundle surfaces.

restoreFocus(wrapper, key)

Restores keyboard focus after a bundle rerender.

selectBundleByPriority(bundles)

protected

Selects the highest-priority bundle for the bottom layout position from a raw bundle list.

Priority rules (applied in order): 1. Bundles with bundle_display_type === 'product' are excluded from bottom-layout candidates. 2. Non-AI bundles (classic, tiered, volume) outrank AI bundles (bundle_type starts with 'ai_'). 3. Among equal-priority bundles the one with the highest updated_at timestamp wins.

Override to apply shop-specific priority or filtering.

selectVariantProduct(target, blockType)

Updates bundle state after a variant selection.

setBundleData(widgetId, data)

Stores bundle data and tracks ownership for later cleanup.

toggleCheckbox(target, blockType)

Toggles product selection inside a predictive bundle.

toggleDropdown(target)

Toggles the variant dropdown associated with an interaction target.