Skip to content

Dropdown does not close when clicking outside if opened via toggle button #279

@augustmarowski

Description

@augustmarowski

Description
When the dropdown is opened by clicking the toggle arrow button with data-action="toggle", clicking outside the dropdown does not close it. This happens because the input element does not receive focus when the dropdown is opened in this way, and the component relies on the blur event from the input to close the dropdown.

Steps to reproduce

  1. Click the toggle arrow button to open the dropdown.
  2. Click anywhere outside the dropdown.
  3. Observe that the dropdown does not close.

Expected behavior
Clicking outside the dropdown should close it, regardless of how the dropdown was opened.

Proposed Solution
To fix this issue, omit data-action="toggle" from the toggle arrow button. Without data-action="toggle", the click will trigger focusControl, which ensures the input is focused. This allows the blur event to fire when clicking outside, correctly closing the dropdown.

Additional Context
The issue occurs because data-action="toggle" bypasses the logic in focusControl that focuses the input. This prevents the dropdown from responding to outside clicks via the on_blur handler.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions