Skip to content

fix(core): Card's collapse toggle now respects defaultCollapsed, and works without a title - #490

Open
dvcolomban wants to merge 2 commits into
vitejs:mainfrom
dvcolomban:fix/json-render-card-collapse
Open

fix(core): Card's collapse toggle now respects defaultCollapsed, and works without a title#490
dvcolomban wants to merge 2 commits into
vitejs:mainfrom
dvcolomban:fix/json-render-card-collapse

Conversation

@dvcolomban

@dvcolomban dvcolomban commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Card's collapse state was fully local and disconnected from its own props:

  • defaultCollapsed was declared in the base catalog but never read — collapse state was hardcoded to ref(false), so authoring { defaultCollapsed: true } had no effect.
  • collapsible: true without a title rendered no header at all, so a titleless collapsible card had no chevron and could never be toggled.
  • Collapse now seeds from defaultCollapsed, and the header (with chevron) renders whenever title || collapsible.
  • A toggle event is emitted on collapse/expand so specs can wire on: { toggle: ... }.
  • Considered a two-way $bindState-controlled variant (mirroring Switch/TextInput) but dropped it — plain local state is enough for what collapse actually needs, and double-binding a UI affordance like this was overkill.

Screenshots

01-default-expanded 02-defaultCollapsed-true 03-no-title-header-still-shows 04-toggled-open-after-click

Test plan

  • pnpm run lint
  • pnpm run typecheck
  • Storybook Card story Controls: toggled collapsible/defaultCollapsed, confirmed initial state and click-to-toggle both work, including with no title

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@490

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@490

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@490

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@490

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@490

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@490

commit: 5d8c221

@dvcolomban
dvcolomban force-pushed the fix/json-render-card-collapse branch from 7a6dbc0 to a7846d1 Compare July 28, 2026 17:02
…works without a title

`defaultCollapsed` was declared in the schema but never read — collapse
state was a hardcoded `ref(false)`, so a Card always rendered expanded on
first paint regardless of the prop. It's now seeded from `defaultCollapsed`.

Also: a collapsible Card without a `title` had no header to click at all
(the header only rendered when `title` was truthy) — it now renders
whenever either is set.

Toggling now emits a `toggle` event, so a spec can react via `on: { toggle: ... }`.

Also types Card's own props (`CardProps`) co-located in `Card.ts` itself,
and adds `registryProps<Type, Props>()` — a typed alternative to the
untyped `props: ['element', 'emit', ...]` array form every registry
component currently uses, so `defineComponent` infers `setup`'s
`ctx.element.props` as the component's own type instead of `Record<string,
any>`. `CardProps` is re-exported from the client webcomponents entry
(`@vitejs/devtools/client/webcomponents`, already public) as an opt-in
strict type.
@dvcolomban
dvcolomban force-pushed the fix/json-render-card-collapse branch from a7846d1 to 7632c22 Compare July 28, 2026 17:14
@dvcolomban
dvcolomban marked this pull request as ready for review July 28, 2026 17:21
…d-collapse

# Conflicts:
#	packages/core/src/client/webcomponents/index.ts
#	packages/core/src/client/webcomponents/json-render/registry.ts
#	test/__snapshots__/tsnapi/@vitejs/devtools/client/webcomponents.snapshot.d.ts
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