zTree / zTree_v3

jQuery Tree Plugin
MIT License
4.1k stars 1.28k forks source link

Fix selectNode() method scroll issue behavior for Mozilla Firefox #473

Closed alexeyhimself closed 3 years ago

alexeyhimself commented 3 years ago

selectNode method calls for scrollIntoViewIfNeeded() if it exists (true for Chrome and Safari) and calls for scrollIntoView(false) otherwise (true for Firefox). But instead of calling scrollIntoView() with defaults you call it with false argument. And such call causes automatic scroll of a tree list (a big one, that overflows screen height) to put selected element to the bottom of the screen on every call of selectNode method. This UX sucks: you selected an element, put it somewhere on a screen, then you hit "up" or "down" keyboard key that calls for selectNode method - and your tree is scrolled to put selected item at the bottom of visible area! This annoys especially when you see that Chrome browser has not one issue.

I suggest to make the following fix (which works for me): to change

scrollIntoView: function(dom) {
    if (!dom) {
        return;
    }
    if (dom.scrollIntoViewIfNeeded) {
        dom.scrollIntoViewIfNeeded();
    } else if (dom.scrollIntoView) {
        dom.scrollIntoView(false);
    } else {
        try{dom.focus().blur();}catch(e){}
    }
},

to (explicit definition of defaults in a call):

scrollIntoView: function(dom) {
    if (!dom) {
        return;
    }
    if (dom.scrollIntoViewIfNeeded) {
        dom.scrollIntoViewIfNeeded();
    } else if (dom.scrollIntoView) {
        dom.scrollIntoView({ behavior: 'auto', block: 'nearest', inline: 'nearest' });
    } else {
        try{dom.focus().blur();}catch(e){}
    }
},
zTree commented 3 years ago

Hello, your code is very old. please check the log:

2018.08.21 v3.5.37