Repository navigation
Show builder sections as collapsible cards - #3762
Crabcyborg wants to merge 1 commit into
Conversation
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>
|
Warning Review limit reachedYou'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. View limit details
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. |
There was a problem hiding this comment.
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>witharia-expanded,aria-controlsand an "Expand/Collapse in builder" label, and the old link is gone. A real mouse click collapses once (the legacy.frm-collapse-sectionjQuery handler does not also toggle it), selects no field, andlocalStorageholds["7","15"]. After a reload both sections come back collapsed, witharia-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".
Non-blocking:
- No test for
initBuilderSections. The 5 tests only cover the pureisCountedField/countSectionFields, with hand-made objects that mimic the DOM. The part that carries the risk (click handling with the capture-phasestopPropagation,aria-*state, thelocalStorageread/write and its blocked-storage fallback, syncing when other code togglesfrm-section-collapsed) has none.jsdomis 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. - The button's
aria-labelgoes stale after a rename. The label is built from the section name only insetCollapsed, and the observer (inline comment) watches child list andclasschanges, 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_nameby 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' ] } ); |
There was a problem hiding this comment.
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.
| observer.observe( canvas, { childList: true, subtree: true, attributes: true, attributeFilter: [ 'class' ] } ); | |
| observer.observe( canvas, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: [ 'class' ] } ); |


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
<button>witharia-expandedandaria-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 inlocalStorage. Blocked storage is ignored.Fixes compared with #3668
edit_field_type_divider) and end markers such asend_tabsare 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.100% - 100pxon hover no longer squeezes the title.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.admin.jskeeps its 49 existing ESLint warnings. A production build changed onlyjs/formidable_admin.jsandcss/frm_admin.cssfor this diff.No JavaScript errors in the console during these steps.
🤖 Generated with Claude Code