cursive icon indicating copy to clipboard operation
cursive copied to clipboard

[BUG] Form elements (e.g. `Checkbox`) take focus on scroll

Open arxanas opened this issue 2 years ago • 1 comments

Describe the bug

When trying to scroll, if the mouse is over an element like a Checkbox, instead of scrolling in the parent view, focus is moved to that element.

To Reproduce

Reproduces in cargo run --example list_view. Move your mouse over the checkbox, and then scroll. The checkbox takes focus. Actually, the issue reproduces for all of the form controls — I don't want any of them to be taking focus in this situation

Expected behavior

The containing ScrollView should scroll.

Environment

  • Operating system used: macOS
  • Backend used: crossterm
  • Current locale:
* LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=
  • Cursive version (from crates.io, from git, ...) 0c6669d6732c3cffeda983958bd9a0fe05ac3b44

Additional context

I tried adjusting take_focus as follows:

    fn take_focus(&mut self, direction: Direction) -> Result<EventResult, CannotFocus> {
        match direction {
            Direction::Abs(Absolute::None) => Ok(EventResult::Ignored),
            _ => self.enabled.then(EventResult::consumed).ok_or(CannotFocus),
        }
    }

Of course, this means that the element no longer responds to mouse click events, which is also not desirable. Is there any workaround to make these elements respond to clicks but not scrolls?

arxanas avatar May 07 '22 06:05 arxanas

Hi, and thanks for the report!

Indeed we probably don't want to change the selection with this. We should be able to forward mouse wheel events down the view tree without changing selection to let users scroll a view that's not selected, as well as not select regular views like checkboxes or edit views in the process.

gyscos avatar Jun 19 '22 20:06 gyscos