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

When clicking in a scrolled tree for the first time, focus is not set properly #712

Closed
aleventhal opened this issue Mar 31, 2017 · 1 comment

Comments

@aleventhal
Copy link
Contributor

Note: I have a PR coming for this.

Expected and actual behavior

When clicking in a scrolled tree, if autoScroll option is true, then the tree scrolls back to the top.

Steps to reproduce the problem

  1. Either load http://jsfiddle.net/KcxRd/1032/, or in demo/sample-scroll.html, remove the following lines:
-                       init: function(event, data) {
-                               data.tree.getFirstChild().setFocus();
-                       },
  1. Load the page and scroll the tree with a mousewheel (without clicking yet)
  2. Click on a tree item -- the tree will scroll back to the top

The removed code should not be necessary in order to get a scrollable tree to work. The PR will show a better way to handle the click-to-focus situation.

Could you set up a jsFiddle (http://jsfiddle.net/mar10/KcxRd/)

Yes -> http://jsfiddle.net/KcxRd/1032/

Environment

  • Browser type and version: Chrome
  • jQuery and jQuery UI versions: latest
  • Fancytree version: latest
mar10 pushed a commit that referenced this issue Apr 1, 2017
…op (#713)

* Setting focus to first item should not be necessary in scroll demo

* Ensure tree item is focused *after* mouse click has had a chance to set focus.

Currently treeSetFocus will focus the first tree item if nothing else had focus.
However, a mouse click does not have a chance to set focus until after the
mouse is released. In order for the treeSetFocus to know that something
was focused with the mouse, we need to:
1) Set focus on a tree item immediately on a mousedown
2) Use a setTimeout(ensureFocus, 0) in treeSetFocus to ensure that
   it runs after the mousedown handler

This prevents the tree from scrolling back up when the user clicks in it.

* Fix tests
@mar10
Copy link
Owner

mar10 commented Apr 1, 2017

Thanks, I merged. In the past, I found the focus handling a bit tricky, so let's see what happens ;)

@mar10 mar10 closed this as completed Apr 1, 2017
mar10 added a commit that referenced this issue Aug 20, 2017
mar10 added a commit that referenced this issue Aug 26, 2017
mar10 added a commit that referenced this issue Aug 26, 2017
mar10 added a commit that referenced this issue Aug 26, 2017
eramitmittal added a commit to iongroup/fancytree that referenced this issue Jan 25, 2018
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

2 participants