Skip to content

Fix dropdown form child clicks#42527

Open
mturac wants to merge 2 commits into
twbs:mainfrom
mturac:fix/issue-41803-dropdown-form-clicks
Open

Fix dropdown form child clicks#42527
mturac wants to merge 2 commits into
twbs:mainfrom
mturac:fix/issue-41803-dropdown-form-clicks

Conversation

@mturac

@mturac mturac commented Jun 19, 2026

Copy link
Copy Markdown

Description

Keeps dropdowns open when clicking elements inside a form within a dropdown menu, such as a label associated with an input.

Motivation & Context

Fixes #41803. Bootstrap already keeps dropdowns open for direct input, select, option, textarea, and form clicks inside the menu. This extends that behavior to descendants of forms, matching the expected behavior for form controls and labels embedded in dropdown menus.

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would change existing functionality)

Checklist

  • I have read the contributing guidelines
  • My code follows the code style of the project (using npm run lint)
  • My change introduces changes to the documentation
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed

Live previews

N/A

Related issues

Fixes #41803

Testing

  • npm run js-lint -- --quiet
  • npm run js-test-karma -- --browsers ChromeHeadless (811 specs passing)

@mturac mturac requested a review from a team as a code owner June 19, 2026 16:04

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 364de7b95f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread js/src/dropdown.js Outdated
Comment on lines +379 to +380
const isFormChild = event.target && typeof event.target.closest === 'function' &&
event.target.closest('form')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Limit form check to forms inside the menu

When the entire dropdown is rendered inside an outer <form>, event.target.closest('form') walks past the dropdown menu and marks every menu item as a form child. Because the next condition only checks context._menu.contains(event.target), normal clicks on links/buttons in that dropdown menu now skip _completeHide, so default autoClose: true no longer closes menus in forms; constrain this check to a form that is itself contained by the menu.

Useful? React with 👍 / 👎.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clicks within forms within dropdowns no longer ignored and close the dropdown

2 participants