Skip to content

Comments

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

Open
jtomaszewski wants to merge 1 commit intotailwindlabs: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 intotailwindlabs:mainfrom
jtomaszewski:vk/36e3-allow-to-close-c

Conversation

@jtomaszewski
Copy link

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
Copy link

vercel bot commented Jan 20, 2026

@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
Copy link

ignatremizov commented Feb 21, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

close ComboBox programmatically HOW?

2 participants