Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form submission inside dropdown fails #3640

Open
bairdj opened this issue Feb 13, 2025 · 0 comments
Open

Form submission inside dropdown fails #3640

bairdj opened this issue Feb 13, 2025 · 0 comments

Comments

@bairdj
Copy link

bairdj commented Feb 13, 2025

Following the example here to submit a form inside a dropdown https://headlessui.com/react/menu#using-with-buttons

import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/react'

function Example() {
  function showSettingsDialog() {
    alert('Open settings dialog!')
  }

  return (
    <Menu>
      <MenuButton>My account</MenuButton>
      <MenuItems anchor="bottom">
        <MenuItem>
          <button onClick={showSettingsDialog} className="block w-full text-left data-[focus]:bg-blue-100">
            Settings
          </button>
        </MenuItem>
        <MenuItem>
          <a className="block data-[focus]:bg-blue-100" href="/support">
            Support
          </a>
        </MenuItem>
        <MenuItem>
          <a className="block data-[focus]:bg-blue-100" href="/license">
            License
          </a>
        </MenuItem>
        <form action="/logout" method="post">
          <MenuItem>
            <button type="submit" className="block w-full text-left data-[focus]:bg-blue-100">
              Sign out
            </button>
          </MenuItem>
        </form>
      </MenuItems>
    </Menu>
  )
}

Attempting to submit this form generates:

Form submission canceled because the form is not connected

Reproducible example using the code from docs: https://stackblitz.com/edit/vitejs-vite-htf44j?file=src%2FApp.tsx
Check the console to see the warning logged

Possible regression from
#1790
#532

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

No branches or pull requests

1 participant