Opened 10 years ago

Closed 10 years ago

#16147 closed defect (invalid)

Tree: focusNode() broken in dojo 1.8

Reported by: bjoerns Owned by: bjoerns
Priority: undecided Milestone: tbd
Component: Dijit Version: 1.8.0
Keywords: Cc:
Blocked By: Blocking:


Context: We are currently migration one of our application from dojo 1.4 to dojo 1.8. One central part of the application is a tree representing a polyhierarchical data structure - one item can be represented by several tree nodes in different paths. We have a custom function to open the path to one such tree node and focus it. The open part still works, but the focusNode call fails silently.

Steps to reproduce: build a tree, call focusNode with any visible node, i.e. on using FireFox? and FireBug?'s console:

dijit.byId("myTree") // Widget dijit.Tree
dijit.byId("dijit__TreeNode_59") // Widget dijit._TreeNode
dijit.byId("myTree").focusNode(dijit.byId("dijit__TreeNode_59")) // undefined

As far as I understand it from debugging, everything is fine until line 277 in dijit/_base/focus.js, where the native focus() method is called on the domNode representing the TreeNode? Label. After that, things got hard for me to follow, apparently an eventListener kicks in, somewhere in the event handling the target gets lost and defaults(?) to document.#

Change History (4)

comment:1 Changed 10 years ago by bjoerns

Update: focusNode only fails, if the focus / click event is not already on the tree.

Internal it works, for example the handling of navigation by key works, but a button on a for example a different BorderContainerChild?, that calls a function that should focus a different (already visible) node fails.

comment:2 Changed 10 years ago by bill

Owner: changed from bill to bjoerns
Status: newpending
Summary: dijit.Tree.focusNode() broken in dojo 1.8Tree: focusNode() broken in dojo 1.8

It's working for me. I modified test_Tree.html adding an <input/> above the tree, and then on chrome/mac did:


in the console, and quickly focused the <input/> before the timer fired.

Can you attach a test case and list the instructions to reproduce, including which browsers it fails on?

comment:3 Changed 10 years ago by bjoerns

Status: pendingnew

i modified test_Tree with this:

<button onclick="dijit.byId('mytree').focusNode(dijit.byId('dijit__TreeNode_7'));" >highlight Europe</button>
<button onclick="dijit.byId('mytree').focusNode(dijit.byId('mytree').rootNode);" >highlight rootNode</button>

as first elements on the page.

clicking either button has no effect on the 'mytree' tree (or any other).

this fails in FireFox? 15.0.1..woops...

ok, in FireFox? 16.0.1 the focus is set, but the node is not highlited

chrome: focus is set, but no highlite

Opera 12.02: fail

IE 9: focus is set on the second click, no highlite

(all on Win7)

ok, so this seems to be a) a problem with certain browser (FF 15 should be irrelevant by now) and I think I didn't understand focusNode() completly. In our legacy application with dojo 1.4 focusNode sets both focus and the highlite for selected node.

if I modify the button to:

<button onclick="dijit.byId('mytree').focusNode(dijit.byId('dijit__TreeNode_7'));dijit.byId('mytree').set('selectedNodes', [dijit.byId('dijit__TreeNode_7')])" >highlight Europe</button>

I get the desired effect. Is this the intended behaviour, focusNode and set('selectedNodes') both have to be executed to completly highlite a node?

comment:4 Changed 10 years ago by bill

Resolution: invalid
Status: newclosed

Right, focus and selection (aka highlighting) are orthogonal things. Remember that multiple nodes can be selected whereas only one node can be focused. And also that using the arrow keys changes the focus to a node that isn't selected.

So, sounds like there isn't an issue here. It's true the behavior changed in 1.5, as documented in the release notes.

Note: See TracTickets for help on using tickets.