{if(element)elements.current.set(node.id,element);else elements.current.delete(node.id);}} role="treeitem" aria-level={depth+1} aria-selected={selectedIds?selectedIds.includes(node.id):selected===node.id} aria-expanded={node.children?.length?open:undefined} tabIndex={(focus??selected??rows[0]?.node.id)===node.id?0:-1} className="nodedc-tree__row" style={{'--tree-depth':depth} as CSSProperties} title={node.label} onFocus={()=>setFocus(node.id)} onClick={event=>select(node.id,event)} onDoubleClick={()=>node.children?.length&&toggle(node.id)} onKeyDown={event=>{
+ {rows.map(({node,depth,open},position)=>
{if(element)elements.current.set(node.id,element);else elements.current.delete(node.id);}} role="treeitem" aria-level={depth+1} aria-selected={selectedIds?selectedIds.includes(node.id):selected===node.id} aria-expanded={node.children?.length?open:undefined} tabIndex={(focus??selected??rows[0]?.node.id)===node.id?0:-1} className="nodedc-tree__row" style={{'--tree-depth':depth} as CSSProperties} title={node.label} onFocus={()=>setFocus(node.id)} onClick={event=>select(node.id,event)} onKeyDown={event=>{
if(event.target!==event.currentTarget)return;
let next:string|undefined;
if(event.key==='ArrowDown')next=rows[Math.min(rows.length-1,position+1)]?.node.id;
diff --git a/registry/components.json b/registry/components.json
index 4c3fc39..e748cab 100644
--- a/registry/components.json
+++ b/registry/components.json
@@ -1297,7 +1297,8 @@
],
"summary": "Compact hierarchical outliner with single-line rows, selection, visibility and keyboard navigation.",
"behavior": [
- "selection expands ancestors and scrolls only the tree container",
+ "new external selection expands ancestors and scrolls only the tree container",
+ "visibility/data refresh keeps disclosure state; arrow disclosure keeps scroll position; row double-click does not expand",
"Arrow/Home/End navigation, disclosure and optional visibility actions",
"long names ellipsize without growing row height",
"filter retains matching ancestors",
diff --git a/scripts/tree-behavior.dom.cjs b/scripts/tree-behavior.dom.cjs
new file mode 100644
index 0000000..6603641
--- /dev/null
+++ b/scripts/tree-behavior.dom.cjs
@@ -0,0 +1,29 @@
+const fs=require('node:fs'),path=require('node:path'),os=require('node:os'),assert=require('node:assert/strict');
+// Supply jsdom through the QA NODE_PATH when it is not installed locally.
+const root=process.env.DG_ROOT||path.resolve(__dirname,'..');
+const {JSDOM}=require('jsdom'),React=require(root+'/node_modules/react'),{act}=React,{createRoot}=require(root+'/node_modules/react-dom/client');
+const dom=new JSDOM('
',{pretendToBeVisual:true});
+for(const name of ['window','document','HTMLElement','Element','Node','Event','MouseEvent','KeyboardEvent'])global[name]=dom.window[name];global.IS_REACT_ACT_ENVIRONMENT=true;
+const scratch=fs.mkdtempSync(path.join(os.tmpdir(),'nodedc-tree-check-'));
+require(root+'/node_modules/esbuild').buildSync({entryPoints:[root+'/packages/ui-react/src/Tree.tsx'],outfile:scratch+'/tree.cjs',bundle:true,platform:'node',format:'cjs',external:['react','react/*'],jsx:'automatic'});
+const {Tree}=require(scratch+'/tree.cjs');
+HTMLElement.prototype.getBoundingClientRect=function(){
+ const host=this.closest('[role=tree]');if(this===host)return{top:0,bottom:140,left:0,right:400,width:400,height:140};
+ const i=host?[...host.querySelectorAll('[role=treeitem]')].indexOf(this):0,top=i*28-(host?.scrollTop||0);return{top,bottom:top+28,left:0,right:400,width:400,height:28};
+};
+let visible=true,selected='leaf99',revision=0,selectedCalls=0,available=true;
+const nodes=()=>[{id:'root',label:'Root',visible,children:available?Array.from({length:100},(_,i)=>({id:'leaf'+i,label:'Leaf '+i})):[]}];
+const ui=createRoot(document.getElementById('app'));
+const render=()=>act(async()=>ui.render(React.createElement(Tree,{nodes:nodes(),selected,revealKey:revision,label:'Tree test',defaultExpandedDepth:1,onSelect:()=>selectedCalls++,onVisibilityChange:(_,v)=>{visible=v;}})));
+const button=label=>[...document.querySelectorAll('button')].find(b=>b.getAttribute('aria-label')===label);
+const send=(target,type='click',props={})=>act(async()=>target.dispatchEvent(new MouseEvent(type,{bubbles:true,...props})));
+(async()=>{
+ await render();const host=document.querySelector('[role=tree]');assert(host.scrollTop>0,'external leaf selection reveals the leaf');
+ await send(button('Свернуть Root'));host.scrollTop=0;assert.equal(document.querySelectorAll('[role=treeitem]').length,1);
+ await send(button('Скрыть Root'));await render();assert.equal(document.querySelectorAll('[role=treeitem]').length,1,'visibility refresh cannot re-open selected ancestors');assert.equal(host.scrollTop,0);assert.equal(selectedCalls,0);
+ await send(button('Развернуть Root'));assert.equal(document.querySelectorAll('[role=treeitem]').length,101);assert.equal(host.scrollTop,0,'disclosure must not reveal old selected leaf');
+ await send(button('Свернуть Root'));await send(document.querySelector('[role=treeitem]'),'dblclick');assert.equal(document.querySelectorAll('[role=treeitem]').length,1,'only disclosure, not row double-click, expands');
+ revision++;await render();assert.equal(document.querySelectorAll('[role=treeitem]').length,101);assert(host.scrollTop>0,'explicit external reveal still works');
+ selected='later';available=false;await render();selected='leaf99';await render();assert.equal(document.querySelectorAll('[role=treeitem]').length,1);available=true;await render();assert.equal(document.querySelectorAll('[role=treeitem]').length,101);assert(host.scrollTop>0,'pending selection is revealed when async children arrive');
+ await act(async()=>ui.unmount());console.log('PASS: 6 Tree DOM scenarios — visibility/disclosure independence, no disclosure scroll jump, eye does not select, row double-click does not expand, explicit reveal, async reveal.');
+})().catch(e=>{console.error(e);process.exitCode=1;}).finally(()=>{fs.rmSync(scratch,{recursive:true,force:true});dom.window.close();});