Skip to content

[KZN-4067]: expose ref on Collapsible - #6821

Open
AliceMenzie wants to merge 3 commits into
mainfrom
am/KZN-4067-collapsible-ref
Open

[KZN-4067]: expose ref on Collapsible#6821
AliceMenzie wants to merge 3 commits into
mainfrom
am/KZN-4067-collapsible-ref

Conversation

@AliceMenzie

@AliceMenzie AliceMenzie commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Wraps Collapsible in forwardRef, forwarding the ref to the toggle IconButton via useImperativeHandle
  • Exposes a ButtonRef interface ({ focus: () => void }) so consumers can programmatically focus the toggle button
  • Re-exports ButtonRef type from the Collapsible index for convenience

Context

Requested in KZN-4067. The consumer (probations-reviews-ui) needed to restore focus to the Collapsible toggle button after async operations (save/delete in a sortable list) and was working around this with a fragile querySelector('[data-testid="collapsible-button-..."]').

Usage

import { useRef } from 'react'
import { Collapsible, type ButtonRef } from '@kaizen/components'

const collapsibleRef = useRef<ButtonRef>(null)

// After an async operation:
collapsibleRef.current?.focus()

<Collapsible ref={collapsibleRef} title="Settings">
  {/* content */}
</Collapsible>

Test plan

  • All existing Collapsible tests pass
  • New ref tests cover: ref defined, focus callable, controlled mode, uncontrolled mode, fallback id, useRef hook pattern
  • Storybook story WithProgrammaticFocus demonstrates the async focus flow

🤖 Generated with Claude Code

@pip-the-concierge

Copy link
Copy Markdown
Contributor

🤖 Agent Workflows

  • PR Review — AI-powered code review

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2982805

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kaizen/components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@AliceMenzie AliceMenzie changed the title feat(Collapsible): expose ref for programmatic button focus (KZN-4067) [KZN-4067]: expose ref on Collapsible Jun 23, 2026
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

✨ Here is your branch preview! ✨

Last updated for commit 2982805: refactor(Collapsible): replace ButtonRef with CollapsibleRef

Wraps Collapsible in forwardRef, forwarding to the toggle IconButton via
useImperativeHandle. Exposes ButtonRef ({ focus }) so consumers can
programmatically focus the toggle after async operations — replacing
fragile querySelector workarounds.

Also exports ButtonRef from the ButtonV1 barrel so consumers can type
their refs without reaching into internals.

Closes KZN-4067

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@AliceMenzie
AliceMenzie force-pushed the am/KZN-4067-collapsible-ref branch from c13cfff to 484cf48 Compare June 23, 2026 05:05
AliceMenzie and others added 2 commits June 23, 2026 15:14
Define CollapsibleRef = { focus: () => void } in Collapsible itself so
the public API has no dependency on ButtonV1 internals. The
useImperativeHandle factory now constructs the object directly rather
than forwarding the internal ButtonRef.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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