Skip to content

UI: improve component code readability in Storybook - #80129

Closed
simison wants to merge 3 commits into
trunkfrom
update/ui-storybook-code-readability
Closed

UI: improve component code readability in Storybook#80129
simison wants to merge 3 commits into
trunkfrom
update/ui-storybook-code-readability

Conversation

@simison

@simison simison commented Jul 10, 2026

Copy link
Copy Markdown
Member

Follow-up to #77382 (comment)

Pairs with #80132 which adds displayNames.

What?

Avoids <React.Fragment> appearing in code examples

Why?

Cleaner code previews and copy-paste for docs consumers.

How?

Switch from args: { children: () } to replacing rendering fully with render prop.

Passes dummy {} just to work around a known Storybook quirk: otherwise Storybook will show: render: () => () as part of the code snippet.

Testing Instructions

Run npm run storybook:dev
Smoke test different stories and code snippets.

Testing Instructions for Keyboard

Screenshots or screencast

Before

image

After

image

When combined with #80132:

image

Use of AI Tools

yes

@simison simison added [Type] Developer Documentation Documentation for developers [Package] UI /packages/ui Storybook Storybook and its stories for components labels Jul 10, 2026
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 7.72 MB

compressed-size-action

</>
),
},
render: ( {} ) => (

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Without {} here we'd get render() => ( ) visible in the code example. Some kind of known Storybook quirk to pass either {} or _args to fix it. 🤷

@simison
simison force-pushed the update/ui-storybook-code-readability branch from e791b83 to 0cfd19d Compare July 10, 2026 20:33
@simison simison added [Status] In Progress Tracking issues with work in progress and removed [Status] In Progress Tracking issues with work in progress labels Jul 10, 2026
@simison
simison marked this pull request as ready for review July 10, 2026 21:02
@simison
simison requested a review from a team as a code owner July 10, 2026 21:02
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

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: simison <simison@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>

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

@github-actions

Copy link
Copy Markdown

Flaky tests detected in ad0d750.
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/29123316066
📝 Reported issues:

@ciampo

ciampo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Switch from args: { children: () } to replacing rendering fully with render prop.

This defeats the point of using Storybook controls and args, though? cc @mirka as the resident Storybook-typescript integration expert

@aduth

aduth commented Jul 13, 2026

Copy link
Copy Markdown
Member

Out of curiosity, would it work to pass args.children as an array instead of using the fragment?

simison added 3 commits July 16, 2026 10:34
Refactor stories to use explicit render functions with direct child
composition instead of args.children fragments, and use render: ( {} ) =>
so Show code displays clean JSX snippets.
@simison

simison commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Out of curiosity, would it work to pass args.children as an array instead of using the fragment?

Seems to do the trick as well! It'll require adding keys everywhere, but thankfully those don't show up in Storybook examples.

Moved that solution to another PR:

@simison

simison commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

This defeats the point of using Storybook controls and args, though?

We would still continue using args for the actual args and just pass them down to render.

E.g.

  • Select control: render: ( { items = defaultItems, ...args } ) => (
  • Stack: render: ( { gap, align, justify } ) => (
  • Button: render: ( { children: _children, ...args } ) => (

@ciampo

ciampo commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

With #80352 merged, can we close this PR?

@simison simison closed this Jul 16, 2026
@simison
simison deleted the update/ui-storybook-code-readability branch July 16, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] UI /packages/ui Storybook Storybook and its stories for components [Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants