Skip to content

Show builder sections as collapsible cards - #3762

Open
Crabcyborg wants to merge 1 commit into
masterfrom
feat/builder-section-cards
Open

Crabcyborg wants to merge 1 commit into
masterfrom
feat/builder-section-cards

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Splits the section part out of #3668 so it can ship in 7.2 on its own. That PR now merges this branch and builds on it, so this one merges first. It also fixes the problems found while comparing that PR against master in forms that use Tabs and Accordions (formidable-tabs-accordions).

What changes

  • Sections in the builder render as cards: a bordered body, a tinted header, a chevron button and a field count badge. Only the builder preview changes. Published forms and saved settings are untouched.
  • The collapse control is a real <button> with aria-expanded and aria-controls. It replaces the old link, which did nothing for a section inside a Tabs field (it only worked on standalone sections). Collapsed sections are remembered per form in localStorage. Blocked storage is ignored.
  • A collapsed card shows only its header, including containers like Tabs that render extra rows such as the tab buttons. A collapsed card no longer stretches to the height of its grid row.
  • Selecting a section, or any field inside it, outlines the whole card and every card around it.

Fixes compared with #3668

  • Field count. It counts only real fields. Sections, Tabs/Accordion containers (they share edit_field_type_divider) and end markers such as end_tabs are skipped. In the demo form, "Registration details" said 15 fields but holds 11, and an accordion said 5 but holds 2. Both now report correctly.
  • Hover state. The ID and move/menu icons stay hover-only, as on master, instead of always showing. The header tints and the card border darkens on hover.
  • Narrow layout columns. The icons overlay the end of the header instead of taking a row of their own. The title, "(Collapsed)" and the count wrap between words instead of being clipped. Below 320px the overlay drops the ID (it is still in the Field Options header). The core rule that reserves 100% - 100px on hover no longer squeezes the title.
  • The old end-of-section circle marker is hidden inside cards.

Not included (stays in #3668)

The field badges, breadcrumb, Collapse all/Expand all menu, drag destination banner and the page-break submit row change.

Testing

  • node --test tests/js/builderSections.test.mjs: 5 passing. It covers counting regular fields, skipping containers, end markers, submit and page breaks, and an 11-field tabs container. Two cases fail when the container/end marker check is removed.
  • ESLint, stylelint and oxlint clean on the new files. admin.js keeps its 49 existing ESLint warnings. A production build changed only js/formidable_admin.js and css/frm_admin.css for this diff.
  • Browser check (Playwright, Lite with Pro and formidable-tabs-accordions active) on a form with standalone sections, a Tabs field with three sections, and an Accordion field:
    1. Open the builder. Each section and the Tabs/Accordion field shows as a card with the correct count.
    2. Hover a section header. The header tints, the border darkens, and the icons appear without covering the count in wide columns.
    3. Click the chevron on a section inside a tab. It collapses. Reload. It is still collapsed. Expand it again and the stored state clears.
    4. Collapse the Tabs field. Only its header remains, with no tab-button row.
    5. Select a field inside a section inside a tab. The Tabs card, the section card and the field are outlined.
    6. Check a section in a 3 or 4 column layout. The title wraps between words and the hover icons fit.

No JavaScript errors in the console during these steps.

🤖 Generated with Claude Code

Sections in the builder become bordered cards with a tinted header,
a field count and a real collapse button that remembers its state
per form in browser storage. The collapse control now works for
sections nested inside tabs and accordions, where the old link did
nothing.

The count skips sections, tab and accordion containers and their end
markers, so a tabs field reports the fields inside its panels. The
ID and move/menu icons stay hover-only and overlay the header, so
narrow layout columns keep a readable title. Selecting a field
outlines the cards it sits in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2a91b45 and bd18897.

Files selected for processing: 8

  • css/frm_admin.css
  • js/formidable_admin.js
  • js/src/admin/admin.js
  • js/src/admin/builderSections.js
  • resources/scss/admin/components/builder/_dividers.scss
  • resources/scss/admin/components/builder/_sections.scss
  • resources/scss/admin/frm_admin.scss
  • tests/js/builderSections.test.mjs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with 2 non-blocking notes at bd1889702. First review of this PR. The collapse button, the field count and the remembered state all work live; nothing I ran failed.

Live (preview env, Lite on this PR, a seeded form with two sections):

  • Both sections get a real <button> with aria-expanded, aria-controls and an "Expand/Collapse in builder" label, and the old link is gone. A real mouse click collapses once (the legacy .frm-collapse-section jQuery handler does not also toggle it), selects no field, and localStorage holds ["7","15"]. After a reload both sections come back collapsed, with aria-expanded="false" and the list hidden.

  • Counts match a hand count of the DOM: "4 fields" (text, email, text, number; end marker not counted) and "1 field".

    expanded card with count badge
    collapsed cards, "(Collapsed)" note and count

Non-blocking:

  1. No test for initBuilderSections. The 5 tests only cover the pure isCountedField/countSectionFields, with hand-made objects that mimic the DOM. The part that carries the risk (click handling with the capture-phase stopPropagation, aria-* state, the localStorage read/write and its blocked-storage fallback, syncing when other code toggles frm-section-collapsed) has none. jsdom is enough to cover it. Separately, the Tabs/Accordion claim in the PR body ("11 fields, not 15") rests on the mock only; I could not check it live because the Tabs add-on is not active in my env.
  2. The button's aria-label goes stale after a rename. The label is built from the section name only in setCollapsed, and the observer (inline comment) watches child list and class changes, not text. Editing the name node of an expanded section left the label on the old name for 500ms+ in my check (I edited .frm_builder_field_name by script, the way the builder updates it; I did not type into the name field). A screen reader would announce the old name until the next toggle or class change.

Tests run: node --test tests/js/builderSections.test.mjs at bd1889702 -> 5 pass, 0 fail (CI skips this job on the PR). eslint on builderSections.js and the test, stylelint on _sections.scss and _dividers.scss, oxlint on builderSections.js: all clean. The built js/formidable_admin.js and css/frm_admin.css contain the new code.

Not exercised: nested sections (my seed did not create one), live Tabs/Accordion containers, adding a new section by drag, drag into a collapsed section, narrow layout columns and the 320px container query, RTL, a large form (the observer re-runs prepareSection for every section on any class change in the canvas, which I did not time), rebuilding the bundles to diff them, PHPUnit/Cypress (no PHP change; CI skips Cypress), and the code-review/security-review/simplify skills (I read the whole diff by hand).

frame = null;
observer.disconnect();
canvas.querySelectorAll( SECTION_SELECTOR ).forEach( prepareSection );
observer.observe( canvas, { childList: true, subtree: true, attributes: true, attributeFilter: [ 'class' ] } );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: renaming a section does not refresh its button label. prepareSection only rewrites aria-label through setCollapsed, and this observer ignores text changes, so after a rename the label keeps the old name until a class change or a toggle. Observe text too and recompute the label in prepareSection (compare before setting, like the count). The observer is disconnected while refresh() runs, so its own count/label writes will not loop. [Likely] fix, not run.

Suggested change
observer.observe( canvas, { childList: true, subtree: true, attributes: true, attributeFilter: [ 'class' ] } );
observer.observe( canvas, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: [ 'class' ] } );

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant