Skip to content

Docs: document controlled/uncontrolled prop naming conventions for @wordpress/ui#76281

Merged
ciampo merged 4 commits into
trunkfrom
docs/ui-controlled-uncontrolled-conventions
Mar 13, 2026
Merged

Docs: document controlled/uncontrolled prop naming conventions for @wordpress/ui#76281
ciampo merged 4 commits into
trunkfrom
docs/ui-controlled-uncontrolled-conventions

Conversation

@ciampo
Copy link
Copy Markdown
Contributor

@ciampo ciampo commented Mar 7, 2026

What?

Document the controlled/uncontrolled prop naming conventions (defaultX / x / onXChange) for the @wordpress/ui package.

Why?

As noted in #76252 (comment), these conventions should be documented so that both component authors and consumers have a single, authoritative reference for the pattern.

The @wordpress/ui package already follows a consistent pattern across its interactive components (inherited from Base UI), but it was not yet documented.

How?

  • Added a new "Controlled and Uncontrolled Modes" subsection under "Core Design Principles" in the @wordpress/ui README, covering:
    • The defaultX / x / onXChange prop naming pattern
    • Concrete examples for open/closed and value state domains
    • Uncontrolled and controlled usage examples
    • Difference from native onChange
    • Guidelines for component authors (including JSDoc conventions)

Testing Instructions

  • Review the documentation in packages/ui/README.md
  • Verify the conventions match existing component implementations (CollapsibleCard, Dialog, Tabs, Input, Textarea, Select)
  • Check that the Storybook introduction page renders the new section correctly (npm run storybook:dev → Design System > Components > Introduction)

Made with Cursor

ciampo added 3 commits March 7, 2026 16:01
…ss/ui README

Document the `defaultX` / `x` / `onXChange` prop naming pattern used
across interactive components in the package. Covers uncontrolled vs
controlled modes, difference from native `onChange`, and guidelines for
component authors.

Ref: #76252 (comment)
Made-with: Cursor
…est practices

Add a note at the top of the Tabs best practices page linking to the
package-wide controlled/uncontrolled prop naming conventions documented
in the README.

Made-with: Cursor
- Use `@wordpress/element` import instead of `react` for consistency
  with the rest of the README and package source
- Clarify that `onXChange` receives the new value as its "first"
  argument (some Base UI-derived components pass additional arguments)
- Document behavior when neither `x` nor `defaultX` is provided

Made-with: Cursor
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Documents the @wordpress/ui controlled/uncontrolled prop naming convention (defaultX / x / onXChange) to provide a single reference for both component authors and consumers, and links to it from the Tabs Storybook best-practices page.

Changes:

  • Adds a new “Controlled and Uncontrolled Modes” section to packages/ui/README.md describing the naming pattern, behavior rules, and authoring guidelines.
  • Includes concrete controlled/uncontrolled usage examples (Tabs + CollapsibleCard) and clarifies how onXChange differs from native onChange.
  • Adds a cross-reference in the Tabs best-practices MDX to the new README section.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/ui/src/tabs/stories/best-practices.mdx Adds a link to the newly documented package-wide controlled/uncontrolled conventions.
packages/ui/README.md Introduces the new documentation section detailing the defaultX / x / onXChange convention with examples and guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 7, 2026

Flaky tests detected in c838f3e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22801491699
📝 Reported issues:

@ciampo ciampo marked this pull request as ready for review March 8, 2026 11:04
@ciampo ciampo requested a review from a team as a code owner March 8, 2026 11:04
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 8, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ciampo ciampo self-assigned this Mar 8, 2026
@ciampo ciampo merged commit f92c6e8 into trunk Mar 13, 2026
41 checks passed
@ciampo ciampo deleted the docs/ui-controlled-uncontrolled-conventions branch March 13, 2026 16:47
@github-actions github-actions Bot added this to the Gutenberg 22.8 milestone Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] UI /packages/ui [Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants