Multi-Component Coordination
This pattern demonstrates how to coordinate multiple independent components (Search, Tabs, Grid, Pagination) using a shared state object.
Showing 5 results
Page 1
Analog Drive 91
Office
$406.99
Qty: 66
Analog Drive 92
Electronics
$424.99
Qty: 18
Analog Folder 96
Furniture
$56.99
Qty: 97
Analog Headset 69
Electronics
$489.99
Qty: 35
Analog Stapler 18
Furniture
$270.99
Qty: 80
How it works
-
Shared State: All components (Tabs, Search, Pagination) read from and write to a shared
ProductSearchState. -
hx-include: Requests include the current state using
hx-include="#product-search-state". -
Partial Updates: Each interaction updates the
#multi-component-democontainer, ensuring all components reflect the new state (e.g., changing tabs resets the page).
Code Example
<!-- Search includes current Tab -->
<input type="search" placeholder="Search..."
name="search"
hx-post="/demo/lab/update-grid"
hx-trigger="keyup changed delay:500ms"
hx-target="#multi-component-demo"
hx-include="#product-search-state" />
<!-- Tabs include current Search -->
<button name="tab" value="electronics"
hx-post="/demo/lab/update-grid"
hx-target="#multi-component-demo"
hx-include="#product-search-state">
Electronics
</button>