From 636d913e0b35ef81e8ef149995e2c40adb06cd80 Mon Sep 17 00:00:00 2001 From: Adam Dierkens Date: Mon, 23 Nov 2026 12:38:09 -0500 Subject: [PATCH 1/5] Add parts-based composition ADR Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../adrs/adr-026-parts-based-composition.md | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 contributor-docs/adrs/adr-026-parts-based-composition.md diff --git a/contributor-docs/adrs/adr-026-parts-based-composition.md b/contributor-docs/adrs/adr-026-parts-based-composition.md new file mode 100644 index 00000000000..dd6ccfc758c --- /dev/null +++ b/contributor-docs/adrs/adr-026-parts-based-composition.md @@ -0,0 +1,212 @@ +# [ADR] Adopt a parts-based composition API inspired by Base UI + +Date: 2026-11-17 · Updated: 2026-11-23 + +## Status + +| Stage | State | +| -------------- | -------------- | +| Status | Proposed ❓ | +| Implementation | Not planned ⛔ | + +## Context + +GitHub teams tell us they're reaching for libraries like Base UI when a design is hard to build with Primer React. Often they want to keep most of what a Primer component already does and try a different layout or interaction. How much they can reuse depends on which component they started with. + +One reason Base UI appeals to teams is that they can arrange a component's parts themselves and keep the keyboard and focus behavior the library provides. Once someone learns how to put a Tooltip on their own button, they can use the same approach for a menu. We'd like teams to have that room to experiment in Primer. + +### What breaks today + +- **Small changes can break composition.** A Tooltip works on an `ActionMenu.Button`, but [extracting the pair into a reusable component can break the menu](https://github.com/primer/react/blob/d1e8047f777ce7005622877d206f9675a91f8790/packages/react/src/ActionMenu/ActionMenu.tsx#L119-L173). In one product menu, the team also has to remove the Tooltip when the button is disabled. +- **Consumers have to wire components together themselves.** On a project board card, the same button shows a Tooltip on hover and opens an overlay on click. The team has to connect both refs by hand. +- **Changing the layout takes more work than it should.** Moving a Dialog title or its actions means fitting the new layout back into the structure Dialog expects. +- **The same customization behaves differently across components.** One component might keep both class names or call both click handlers. Another might drop Primer's when the caller supplies one. Teams have to read the source to tell. +- **Callbacks don't give consumers enough information.** `ActionMenu` tells consumers that it closed. They can't tell from the callback whether someone pressed Escape or clicked outside, or cancel that change without taking over its state. + +## Decision + +We'll take inspiration from Base UI and update Primer to have a more parts-based API. Interactive components will expose the pieces consumers need to arrange their own layouts and combine interactions, with consistent composition conventions across Primer. + +Parts and configured components will share Primer's existing implementation. Teams can use the standard patterns or compose the parts directly, while Primer keeps ownership of the public API and can evolve the underlying implementation over time. + +### What changes + +- **Components are built from parts.** Every interactive component will expose named parts so consumers can move a trigger into their own component, wrap a title, or leave out an optional close button. +- **Every rendered part supports `as` and `render`.** Use `as` to change the element type. Use `render` to put the part's behavior on an element you supply, or pass a function that receives its props (including `ref`) and state. A Tooltip and a menu can share one button without consumers connecting refs by hand. A provider-only root has no element to replace. +- **Parts follow Primer's prop-merging conventions.** Parts follow [ADR-025](https://github.com/primer/react/blob/main/contributor-docs/adrs/adr-025-prop-merging.md) when they combine Primer's props with the consumer's, including props on a `render` target, so consumers don't have to learn a different merge order for each component. +- **Callbacks say what happened.** New state-change callbacks take one object, for example `onOpenChange({open, reason, event, cancel})`. Consumers can see what prompted the change and call `cancel()` before it takes effect, without taking over the component's state. +- **The same prop means the same thing everywhere.** Shared props use the same names, values, and defaults across components. If two components offer the same sizes, callers shouldn't have to learn two spellings of `medium`. +- **Component scorecards track consistency over time.** We'll use a [component scorecard](#how-do-we-maintain-composition-quality-over-time) to review new APIs and recheck shipped components as conventions change, so new components and API additions follow the same decisions. + +### What stays the same + +- **Existing component APIs keep working.** Teams can keep using `` with `ActionMenu.Button`, or `Dialog` with `title` and `onClose`. Existing subcomponents keep their prop handling, and existing callbacks keep their signatures, so adopting parts doesn't require rewriting existing usage. +- **Configured components keep their data APIs.** Teams can keep supplying data for common patterns and use parts when they need to arrange the content themselves. A configured prop and a part don't both supply the same content. +- **Existing `as` props and slots stay supported.** Root `as` props and slots keep working where they're supported, so consumers can adopt parts without replacing customizations they already use. +- **Primer keeps its current implementation.** Parts and configured components share Primer's current behavior code, types, CSS Modules, and accessibility defaults, so introducing parts doesn't require a separate behavior or styling stack. + +### Example: a Tooltip on a menu trigger + +Today, simplified from the product menu above: + +```tsx +// Works because ActionMenu finds Tooltip and ActionMenu.Button by identity + + + Medium + + {/* items */} + +``` + +Proposed, with illustrative part names: + +```tsx + + + Medium} />} /> + Reasoning effort + + {/* items */} + +``` + +One `