Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3538

Do not change focus when opening a Treeitem

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Normal Normal
    • 8.5.2
    • 8.0.3
    • None
    • Security Level: Jimmy
    • None

      steps to reproduce

      1. load the attached zul
      2. 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()

            CharlesQiu CharlesQiu
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 1 day
                1d
                Remaining:
                Time Spent - 2 hours Remaining Estimate - 6 hours
                6h
                Logged:
                Time Spent - 2 hours Remaining Estimate - 6 hours
                2h