Skip to content

refactor(playground): clean up hooks and label the toolbar buttons - #4903

Open
thetaPC wants to merge 1 commit into
playground-testsfrom
playground-hooks
Open

thetaPC wants to merge 1 commit into
playground-testsfrom
playground-hooks

Conversation

@thetaPC

@thetaPC thetaPC commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #4902.

Playgrounds look and behave the same: this only changes how Playground uses React hooks, plus labels for screen readers. The code still renders in the browser only, as before. Rendering it on the server would change what shows on first load and make pages with many examples noticeably heavier, so that is left for its own PR.

  • The prop checks now sit in a small wrapper, so the early returns no longer come before the hooks.
  • The IntersectionObserver is created once and disconnected on unmount, instead of a new one on every render.
  • device-preview is imported once, and only by playgrounds that use the device frame.
  • The dark mode is computed from the color mode instead of copied into state. It is sent to the demo on load, on change, and after a reset, instead of on every render.
  • Snippets render directly instead of being copied into state in an effect.
  • File tabs use refs instead of ids, which repeated across playgrounds on the same page.
  • The StackBlitz, copy and reset buttons have accessible names, and the iOS and MD buttons expose aria-pressed.
  • The props and their defaults are documented on PlaygroundProps in playground.types.ts, and size only accepts the named sizes or a pixel value.
  • The set-focus playgrounds passed size="sm", which isn't a size and fell back to the browser's default height. They now pass that height, so they look the same.

How to test

Compared with the live site, playgrounds should look and behave the same:

  1. Open the preview's Alert page. The playgrounds and their code look the same, and iOS and MD switch the demo.
  2. With a screen reader, or the accessibility panel in the browser's dev tools, check the toolbar. The three icon buttons are named "Open in StackBlitz", "Copy source code" and "Reset demo", and the iOS and MD buttons report whether they're pressed.
  3. Open Modal, keep Angular selected, and click "Open in StackBlitz". All four files from the tabs arrive in StackBlitz.
  4. Pick iOS in any playground, then open Input and scroll to the fill playground. It stays in MD, and its iOS button is disabled.
  5. Open Reorder and drag an item in a playground with a console. The console lists the event, and is cleared by "Reset demo".
  6. Open App. The set-focus demo is the same height as on the live site.

The demos stay light when the site is dark. That is already the case on main, and is tracked separately.

@thetaPC
thetaPC added this pull request to stack #4900 November 25, 2026 19:46
@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-docs Ready Ready Preview Nov 25, 2026 7:46pm UTC

Request Review

@thetaPC
thetaPC marked this pull request as ready for review November 25, 2026 23:12
@thetaPC
thetaPC requested a review from a team as a code owner November 25, 2026 23:12

This branch was successfully deployed

1 active deployment
Preview — f10acd51 Deployed Nov 25, 2026 by vercel[bot]
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