From 27e3f1a3070ed08c449a87fead09765fb87a1f76 Mon Sep 17 00:00:00 2001
From: Michael Telgkamp <michael.telgkamp@mindscreen.de>
Date: Thu, 5 Dec 2019 15:47:46 +0100
Subject: [PATCH] [BUGFIX] Fix keyboard behaviour on pagetree root node

- Do not toggle node with canToggle!==true
- Check if node has parent before trying to go to parent node

Resolves: #89847
Resolves: #89864
Releases: master
Change-Id: I49f112c15e64103e707481cecb7f61bd58fa8182
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62544
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Susanne Moog <look@susi.dev>
---
 .../Resources/Public/JavaScript/SvgTree.js    | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/SvgTree.js b/typo3/sysext/backend/Resources/Public/JavaScript/SvgTree.js
index f6f86df33b34..36fc68635a5f 100644
--- a/typo3/sysext/backend/Resources/Public/JavaScript/SvgTree.js
+++ b/typo3/sysext/backend/Resources/Public/JavaScript/SvgTree.js
@@ -258,31 +258,32 @@ define(
           return;
         }
         e.preventDefault();
+        var parentDomNode = e.target.parentNode;
         switch (e.keyCode) {
           case keyTypesEnum.END:
             // scroll to end, select last node
-            var parent = e.target.parentNode;
             this.scrollTop = this.wrapper[0].lastElementChild.scrollHeight + this.settings.nodeHeight - this.viewportHeight;
             this.wrapper.scrollTop(this.scrollTop);
             this.updateScrollPosition();
             this.update();
-            this.switchFocus(parent.lastElementChild);
+            this.switchFocus(parentDomNode.lastElementChild);
             break;
           case keyTypesEnum.HOME:
             // scroll to top, select first node
-            var parent = e.target.parentNode;
             this.scrollTop = this.nodes[0].y;
             this.wrapper.scrollTop(this.scrollTop);
             this.update();
-            this.switchFocus(parent.firstElementChild);
+            this.switchFocus(parentDomNode.firstElementChild);
             break;
           case keyTypesEnum.LEFT:
             if (currentNode.expanded) {
-              // collapse node
-              this.hideChildren(currentNode);
-              this.prepareDataForVisibleNodes();
-              this.update();
-            } else {
+              // collapse node if collapsible
+              if (currentNode.canToggle) {
+                this.hideChildren(currentNode);
+                this.prepareDataForVisibleNodes();
+                this.update();
+              }
+            } else if (currentNode.parents.length > 0) {
               // go to parent node
               var parentNode = this.nodes[currentNode.parents[0]];
               this.scrollNodeIntoVisibleArea(parentNode, 'up');
-- 
GitLab