Skip to content

[Bug]: Clear button intercepts clicks meant to open the dropdown #1059

Description

@rocket-turtle

Bug description

The clear button plugin only toggles visibility with opacity (0 when hidden, 1 on .focus.has-items / hover):

  .clear-button {
    opacity: 0;
    position: absolute;
    cursor: pointer;
    ...
  }

It never sets pointer-events: none. The button is absolutely positioned right next to the caret/dropdown-toggle area, and stays clickable even while invisible (opacity 0 does not disable pointer events). It also keeps cursor: pointer while invisible, so hovering that spot shows a hand cursor - making the user think there's something clickable there, even though visually it looks like part of the plain control.

So a click near the caret - meant to just open the dropdown - can land on the hidden clear button instead. When that happens, nothing appears to work: the click doesn't open the dropdown, because clear_button's handler calls self.clear() (no items, so it's a no-op) and, since the button is a <div tabindex="0">, the mousedown also shifts browser focus to it. That fires onBlur on the control, which calls self.close() - closing/keeping the dropdown closed. From the user's side, the hand cursor promised something clickable, then the click just did nothing.

Expected behavior

Fix we're using locally, mirroring the same conditions the plugin already uses for opacity:

  .clear-button {
    pointer-events: none;
  }

  &.focus.has-items .clear-button,
  &:not(.disabled):hover.has-items .clear-button {
    pointer-events: auto;
  }

This keeps the button clickable (and its hand cursor honest) only when it's actually visible, so clicks/hover in that area otherwise pass through to the control as expected.

Steps to reproduce

  1. Go to clear-button example
  2. Go to the "Select Single" example and klick on the non visible "clear button"
  3. Dropdown is not opend

  1. Go to clear-button example
  2. Select any value in the "Select Single" example
  3. Click on the clear button and do not move the mouse.
  4. Element is removed
  5. Click again
  6. Dropdown is not opend

Additional context

Version 2.6.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions