Skip to content

feat(combobox): add imperative ref handle for programmatic close#3837

Open
jtomaszewski wants to merge 1 commit into
tailwindlabs:mainfrom
jtomaszewski:vk/36e3-allow-to-close-c
Open

feat(combobox): add imperative ref handle for programmatic close#3837
jtomaszewski wants to merge 1 commit into
tailwindlabs:mainfrom
jtomaszewski:vk/36e3-allow-to-close-c

Conversation

@jtomaszewski

Copy link
Copy Markdown

Summary

Add ComboboxHandle type with close() method, allowing programmatic control of the Combobox via useImperativeHandle.

Fixes #3649

Usage

import { Combobox, ComboboxHandle } from '@headlessui/react'
import { useRef } from 'react'

function Example() {
  const comboboxRef = useRef<ComboboxHandle>(null)

  return (
    <>
      <button onClick={() => comboboxRef.current?.close()}>
        Close Combobox
      </button>
      <Combobox ref={comboboxRef}>
        <ComboboxInput />
        <ComboboxOptions>
          <ComboboxOption value="a">Option A</ComboboxOption>
        </ComboboxOptions>
      </Combobox>
    </>
  )
}

Test plan

  • Added tests for closing via ref.current.close()
  • Verified onClose callback is triggered
  • All existing combobox tests pass

🤖 Generated with Claude Code

Add ComboboxHandle type with close() method, allowing programmatic
control via useImperativeHandle. Usage:

const ref = useRef<ComboboxHandle>(null)
<Combobox ref={ref}>...</Combobox>
ref.current?.close()

Fixes tailwindlabs#3649

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jan 20, 2026

Copy link
Copy Markdown

@jtomaszewski is attempting to deploy a commit to the Tailwind Labs Team on Vercel.

A member of the Team first needs to authorize it.

@ignatremizov

ignatremizov commented Feb 21, 2026

Copy link
Copy Markdown

This is not backwards compatible (ref was HTMLElement type which you replace with ComboboxHandle) - if you need this just expose it as another prop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants