12. Interactive components
BuilderOS ships a library of interactive components (accordion, tabs, carousel, counter and before/after), in the style of Elementor’s widgets but with the package’s design: the AI supplies the HTML and CSS, and BuilderOS supplies the accessible behavior and the options the client can change from the editor: a carousel’s speed or autoplay, which tab opens by default, or the number a counter counts up to. The AI can also create custom components with BuilderOS.component(), with their options declared in the markup, and the client configures them the same way.
That way each AI stops coding these pieces its own way: the markup is always the same, the JavaScript is BuilderOS’s (no dependencies) and the options are edited in the panel.
In this chapter
- How it works (technical overview)Markup: data-bos-component=”<tipo>” on the component’s root element, inside a section. Its default values go in data-bos-option-<nombre>=”valor” and…
- In WordPress (what the client does)When you click a component or any element inside it (an accordion question, a slide, a tab title…), the panel’s Content tab shows the “Component…
- Markup for the AI (syntax)The look comes from the package, with its classes (with the section prefix). BuilderOS’s CSS is minimal and neutral: structure and state.
- For the developerFiles: includes/modules/class-builder-os-components.php (library, schemas, render, loading and editor) and includes/modules/components/ (validation…
Library options
| Component | Option | Type | Default | What it does |
|---|---|---|---|---|
accordion | first-open | toggle | true | The first item starts open. |
multiple | toggle | false | Allow several open at once (otherwise, opening one closes the others). | |
tabs | initial | number (1–20) | 1 | Tab that starts open (clamped to the number of tabs). |
activation | select: auto, manual | auto | With the arrows: switch tabs as you move, or move and switch with Enter. | |
carousel | autoplay | toggle | false | Automatic playback (with a pause button; it doesn’t activate with “reduce motion”). |
interval | number (2–20 s, step 0.5) | 5 | Seconds per slide. | |
arrows | toggle | true | Previous / Next buttons. | |
dots | toggle | true | Navigation dots. | |
loop | toggle | true | At the end, go back to the start (without a loop, the arrows are disabled at the ends; autoplay goes back to the start). | |
per-view | number (1–6) | 1 | Visible items on desktop. | |
per-view-tablet | number (1–6) | the desktop value, at most 2 | Visible items on tablet (≤ 1024 px). | |
per-view-mobile | number (1–4) | 1 | Visible items on mobile (≤ 767 px). | |
counter | duration | number (0.5–10 s) | 2 | Duration of the count. |
start | number | 0 | Number it counts up from. | |
prefix, suffix | text | "" | Text before and after the number (€, +, %…). | |
separator | select: auto, ., ,, space, none | auto | Thousands separator (auto = as written). | |
before-after | start | number (0–100 %) | 50 | Starting position of the cut. |
orientation | select: horizontal, vertical | horizontal | Left/right or top/bottom. |
❌ What NOT to do
- Don’t code your own accordion, tabs, carousel, counter or before/after, and don’t load Swiper, Slick or similar for that: use
data-bos-component. That way the client can configure them and they’re accessible. - Don’t use
data-bos-*in CSS or JS (they’re removed on publish): style with your classes and theis-*classes; in a custom component’s JS usedata-part. - Don’t hide closed panels or inactive tabs with
display: nonein your CSS, and don’t puthiddenin the HTML: BuilderOS does it, and that way everything is readable without JavaScript. - Don’t set the carousel slides’ width or its
overflow: the visible-items options control them. - Don’t write the counter as 0 in the HTML: write the final number.
- Don’t make the buttons, tabs or controls
<div>or<a>: use<button type="button">. - Don’t put tabs in a repeater; for lists the client extends, use the accordion.
- Don’t add your own autoplay without a pause button, or animations that ignore
prefers-reduced-motion.
Image viewer (lightbox)
To enlarge a package section’s photos, put data-bos-lightbox on the link to the large image:
<div class="obras">
<a href="img/obra-1-grande.jpg" data-bos-lightbox="obras" data-bos-caption="Reforma integral en Chamberí">
<img src="img/obra-1.jpg" alt="Salón reformado con suelo de roble">
</a>
<a href="img/obra-2-grande.jpg" data-bos-lightbox="obras">
<img src="img/obra-2.jpg" alt="Cocina abierta en blanco">
</a>
</div>- The value is the group: images in the same group form a gallery (arrows, counter, swipe).
- Caption:
data-bos-caption; otherwise the<figcaption>of its<figure>; otherwise the image’salt. - It also works on an
<img data-bos-lightbox>with no link (it enlarges the image itself or itsdata-full). - With photos the client can change (
data-bos-edit="image"), putdata-bos-lightboxon the<img>itself (no link): the viewer enlarges whichever image is there at the time. A link with a fixedhrefwould keep pointing at the old photo. - BuilderOS converts it to
data-lightboxwhen rendering (thedata-bos-*attributes are cleaned) and loads the viewer only on that page. - Accessibility, keyboard, mobile and “reduce motion”: see chapter 13 › Viewer.
Announcement bar slot in the header
The builder’s announcement bar with “Inside the site header” is rendered in the package’s header:
- in the element with the class
bos-slot-announcement, if the header has one (e.g.<div class="bos-slot-announcement"></div>at the very top); - otherwise, as the first child of the first
<header>in theheaderpart.
It takes the full width of that element and receives clicks even if the header has pointer-events: none.