Skip to content

feat!: add the Menu component and rebuild Dropdown as its compatibility layer - #649

Merged
mrholek merged 6 commits into
v6-devfrom
feat/menu
Jul 31, 2026
Merged

feat!: add the Menu component and rebuild Dropdown as its compatibility layer#649
mrholek merged 6 commits into
v6-devfrom
feat/menu

Conversation

@mrholek

@mrholek mrholek commented Jul 31, 2026

Copy link
Copy Markdown
Member

Adds the Menu component (ported from Bootstrap v6) and rebuilds Dropdown on top of it — one engine, two markups. Plan and findings: workspace/plans/menu-and-dropdown-compat.md.

The architecture

Menu is the implementation; Dropdown is a ~210-line subclass carrying the v5 surface. The acceptance contract was the untouched v5 spec suite: dropdown.spec.js passes 87/87 without a single changed line.

Three seams made the subclass possible (the one deliberate deviation from upstream):

  • selectors and class hooks live in static getters, not module constants, so the subclass swaps .menu/.menu-item for .dropdown-menu/.dropdown-item
  • events go through constructor.eventName, so the subclass speaks *.coreui.dropdown
  • dataApiKeydownHandler reads event.delegateTarget instead of a bound this, and _openInstances is a registry shared down the prototype chain — one document-level clearMenus dismisses both families

Dropdown keeps: class-driven placement (dropup/dropend/--cui-position), the navbar/static data-coreui-popper CSS hook, descendant item lookup for the <li>-wrapped v5 markup, and the jQuery surface. It quietly gains Menu's container teleport and floatingConfig where options overlap.

What Menu brings

Submenus (hover intent with triangle tracking, keyboard entry/exit), container teleport, responsive placement ("bottom-start md:top-end" on our breakpoints), logical start/end placements, @starting-style entry transition, scrollable and translucent variants.

Also in here

  • _menu.scss translated onto our token conventions ($menu-* knobs, --cui-theme-* indirection, data-coreui-placement transform-origin hooks)
  • SelectorEngine.closest (additive, from upstream)
  • docs: the Menu page (upstream's, on our shortcodes; their interactive placement playground became a static example) and a callout on the Dropdown page
  • our lint caught upstream's Array.at(-1) — unsupported under the browser floors .browserslistrc declares — replaced with index access

Numbers and honest costs

  • Suite: 3453/3453 (140 upstream Menu specs + 8 of ours; dropdown suite untouched)
  • Menu costs ~1.4 kB gzip across the bundles — budgets raised explicitly for the new component
  • Coverage branch floor 89 → 88.5: several of Menu's uncovered branches are unreachable from the documented markup (upstream's own suite leaves them uncovered too); the reasoning sits next to the thresholds rather than in synthetic specs
  • Deferred, recorded in the plan: the shared createAnchoredPosition helper (touches six existing components — own PR), the coreui-internal-links entry (needs live URLs, lands with the v6 docs deploy), and Home/End keys in the compat layer (a Menu feature v5 never had)

mrholek added 6 commits July 31, 2026 17:07
The upstream component with our namespaces, one deliberate deviation and the
jQuery surface added:

- The selectors and class hooks live in static getters, not module constants,
  so Dropdown can subclass Menu and keep the v5 markup working (the plan:
  workspace/plans/menu-and-dropdown-compat.md). dataApiKeydownHandler reads
  event.delegateTarget instead of a bound `this`, which lets the subclass
  register the same static with its own selectors, and _openInstances is a
  registry shared down the prototype chain, so one clearMenus handles every
  family.
- SelectorEngine gains upstream's `closest` (additive).
- Our lint caught upstream's `Array.at(-1)` — unsupported under the browser
  floors .browserslistrc declares — replaced with index access.
- Spec ported (140 upstream tests) plus our additions: the jQueryInterface
  quartet and update()-with-reference coverage. One upstream branch
  (Escape inside a submenu reached through keyboard discovery) turns out
  unreachable from the documented markup — upstream's own suite leaves it
  uncovered too — so the branch floor moves to the measured 88.5 rather than
  gaining a synthetic spec; the reasoning lives next to the thresholds.
Upstream's _menu.scss translated token for token: prefixed --cui-menu-*
custom properties backed by $menu-* Sass knobs (the customization API every
component keeps), our theme indirection (--cui-theme-fg/-bg-subtle/-contrast/
-base) in place of their bare aliases, our palette hooks (tertiary-bg/-color,
component-active-*, border-color-translucent, box-shadow-lg) and
data-coreui-placement as the transform-origin hook. The @starting-style entry
transition, display allow-discrete and the translucent variant come along
unchanged.
…Menu

One engine, two markups. Menu gained the three seams the subclass needs —
events emitted through constructor.eventName (so the subclass speaks
*.coreui.dropdown), a _removeMenuAttributes hook, and the selectors it
already exposed as static getters. Dropdown shrinks from 552 lines of engine
to ~210 lines of overrides: the v5 selectors, class-driven placement
(dropup/dropend/--cui-position), the navbar/static data-coreui-popper hook,
descendant item lookup for the <li>-wrapped v5 markup, and the jQuery
surface. clearMenus is not re-registered — Menu's document-level handler
iterates the open-instance registry the subclass shares.

The acceptance contract: dropdown.spec.js untouched, 87/87 green on the
subclass. Full suite 3453/3453. In exchange Dropdown quietly gains Menu's
container teleport and floatingConfig passthroughs where the options overlap.

bundlewatch budgets raised explicitly for the new component: Menu costs
~1.4 kB gzip across the bundles (submenus, hover intent, responsive
placement), the named growth this branch delivers.
Upstream's menu.mdx with our namespaces, button classes, engine shortcodes
(ScssDocs capture markers, plain markdown tables) and links; their interactive
placement playground becomes a static two-button example, and the sections
backed by site machinery we don't have (JsDependencies, JsDataAttributes,
CSSVariables) are dropped. The Dropdown page opens with a callout that it is
now a compatibility layer over Menu.
Three things the review caught:

- Upstream's docs teach their composable class idiom (theme-* on menu items,
  btn-ghost theme-secondary) — the Tailwind-style API our bet explicitly
  rejects. The examples now speak CoreUI: text-* utilities tint items and
  btn btn-ghost-secondary is the button. The --cui-theme-* indirection stays
  in the SCSS as internal plumbing (alerts and tables use the same), it is
  just not the advertised API.
- The selected-state examples nested <div class="menu-item-content"> inside
  <button>, which is invalid HTML (buttons take phrasing content) and failed
  the vnu gate on CI — now <span>, styled identically by the flex rules.
- The Dropdown page callout and the migration guide now carry the decision:
  Dropdown is a compatibility layer and may be removed in v7 — prefer Menu
  for new work.
@mrholek
mrholek merged commit d2ef5dd into v6-dev Jul 31, 2026
7 checks passed
@mrholek
mrholek deleted the feat/menu branch July 31, 2026 15:33
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