I’m working on a reviews section with multiple collapsible text elements inside a Wix Repeater. When I click on one collapsible text item to expand it, I want the previously expanded item to collapse automatically. Additionally, when a user swipes left or right on mobile or when an item goes out of the viewport on both mobile and desktop, the expanded item should collapse.
Here’s what I want to achieve:
- I have a repeater with multiple collapsible text elements, each containing a review.
- When a user clicks to expand a new collapsible text, the previously expanded one should collapse.
- I don’t want more than one collapsible text expanded at the same time.
- When a user swipes left/right on mobile (or on desktop when the item leaves the viewport), the expanded text should collapse.
Here’s the code I tried, but it doesn’t work:
let openedItem = null;
$w.onReady(() => {
$w(“#repeater10”).onItemReady(($item, itemData, index) => {
const collapse = $item(“#collapsibleText11”);
collapse.onClick(() => {
if (openedItem && openedItem !== collapse) {
openedItem.collapse();
}
if (collapse.collapsed) {
collapse.expand();
openedItem = collapse;
} else {
collapse.collapse();
openedItem = null;
}
});
});
});
This is how it currently looks (I’ll attach a screenshot showing how the layout is broken). Could someone please help me figure out what I’m doing wrong or point me in the right direction to achieve this functionality?
Thanks!