-
New Feature
-
Resolution: Done
-
Normal
-
8.0.3
-
None
-
Security Level: Jimmy
-
None
-
None
steps to reproduce
- load the attached zul
- type ch in the textbox
current result
ZK moves the focus to Tree, so that users can't continue his typing
debug info
- when opening a treeitem, treeitem's setopen() enforce moving focus on its parent tree.
zul.sel.Treeitem = zk.$extends(zul.sel.ItemWidget, { _open: true, $define: { open: function (open, fromServer) { .... tree.focus(); }
we can consider not moving the focus.
- Maybe there is another use case that requires getting focus while opening, e.g. a user opens a treeitem by mouse clicking instead of API. Then we can differentiate 2 cases with fromServer flag.
workaround
zk.afterLoad('zul.sel', function() { var oldMethods = {}; zk.override(zul.sel.Treeitem.prototype, oldMethods, { setOpen: function (open, fromServer) { var previouslyFocused = zk.Widget.$(jq(':focus')); oldMethods.setOpen.apply(this, arguments); if (previouslyFocused){ previouslyFocused.focus(); } } }); });
debug info
- moving focus is a general issue that we will face when implementing every widget. We should collect use cases and conclude a design rule
- it's better to focus a tree in doClick (click event handler) instead of setOpen()