diff --git a/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_renderer.js b/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_renderer.js index ef6253089ea..4cc974b823d 100644 --- a/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_renderer.js +++ b/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_renderer.js @@ -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() { diff --git a/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_view.scss b/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_view.scss index b3085cb535f..6181b541c25 100644 --- a/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_view.scss +++ b/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_view.scss @@ -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; + } +}