[IMP] hr_org_chart: auto scroll in hierarchy view

Before this commit, when the user unfold a node in hierarchy view,
he has to scroll to be able to see the child nodes added.

This commit adds an auto-scroll when a new row is added to directly
show the child nodes added on the view when the user unfolds a node
in the hirarchy view.

task-3376776
This commit is contained in:
Xavier Bol (xbo)
2023-10-16 08:17:31 +02:00
parent 3e5e6fd3e3
commit 3489a0d28f
2 changed files with 21 additions and 1 deletions
@@ -1,9 +1,10 @@
/** @odoo-module */
import { Component, useRef } from "@odoo/owl";
import { Component, useRef, onPatched } from "@odoo/owl";
import { _t } from "@web/core/l10n/translation";
import { useService } from "@web/core/utils/hooks";
import { scrollTo } from "@web/core/utils/scrolling";
import { HierarchyCard } from "./hierarchy_card";
import { useHierarchyNodeDraggable } from "../../hooks/hierarchy_node_draggable";
@@ -61,6 +62,17 @@ export class HierarchyRenderer extends Component {
},
});
}
onPatched(this.onPatched);
}
onPatched() {
const row = this.rendererRef.el.querySelector(":scope .o_hierarchy_row:last-child");
if (row) {
const scrollable = this.env.isSmall ? document.querySelector(".o_hierarchy_view") : this.rendererRef.el.parentNode;
scrollable.classList.add(".o_hierarchy_auto-scroll");
scrollTo(row, { scrollable, isAnchor: true });
scrollable.classList.remove(".o_hierarchy_auto-scroll");
}
}
get canDragAndDropRecord() {
@@ -1,3 +1,11 @@
.o_control_panel_navigation .o_switch_view .o_hierarchy_icon { // button in view switcher
rotate: 90deg;
}
.o_hierarchy_view { // uses for auto-scroll when drag&drop or unfold node
scroll-behavior: smooth;
.o_content {
scroll-behavior: smooth;
}
}