@@ -128,6 +128,8 @@ Reference List
128
128
- manage the browser url
129
129
* - :ref: `rpc <frontend/services/rpc >`
130
130
- send requests to the server
131
+ * - :ref: `scroller <frontend/services/scroller >`
132
+ - handle clicks on anchors elements
131
133
* - :ref: `title <frontend/services/title >`
132
134
- read or modify the window title
133
135
* - :ref: `user <frontend/services/user >`
@@ -692,6 +694,58 @@ When a rpc fails, then:
692
694
displayed and the server is regularly contacted until it responds. The
693
695
notification is closed as soon as the server responds.
694
696
697
+ .. _frontend/services/scroller :
698
+
699
+ Scroller service
700
+ ----------------
701
+
702
+ Overview
703
+ ~~~~~~~~
704
+
705
+ - Technical name: `scroller `
706
+ - Dependencies: none
707
+
708
+ Provides a way to handle scrolls to anchors in the webclient.
709
+ This service is used whenever a click occurs on the webclient.
710
+
711
+ The service adds an event listener to get `click `'s on the document. The service is then
712
+ checking if the selector contained in its href attribute is valid to distinguish anchors and Odoo
713
+ actions (e.g. ``<a href="#target_element"></a> ``). It returns nothing if it is not the case.
714
+
715
+ An event ``SCROLLER:ANCHOR_LINK_CLICKED `` is triggered on the main application bus. That event contains a
716
+ custom event containing the `element ` matching and its `id ` to notify other parts that may need to handle
717
+ an anchor behavior themselves. The original event is also given as it might need to be prevented. Otherwise,
718
+ the ``scrollTo `` function is used to handle the scroll to the correct element directly in the service.
719
+ That function is imported from ``@web/core/utils/scrolling.js ``.
720
+
721
+ API
722
+ ~~~
723
+
724
+ The following values are contained in the `anchor-link-clicked ` custom event explained above.
725
+
726
+ .. list-table ::
727
+ :widths: 25 25 50
728
+ :header-rows: 1
729
+
730
+ * - Name
731
+ - Type
732
+ - Description
733
+ * - ``element ``
734
+ - ``HTMLElement | null ``
735
+ - The anchor element targeted by the href
736
+ * - ``id ``
737
+ - ``string ``
738
+ - The id contained in the href
739
+ * - ``originalEv ``
740
+ - ``Event ``
741
+ - The original click event
742
+
743
+ .. note ::
744
+ The scroller service emits a `SCROLLER:ANCHOR_LINK_CLICKED ` event on the :ref: `main bus <frontend/framework/bus >`
745
+ You should use `preventDefault() ` on the event given to the listener element to avoid the service to handle the
746
+ scrolling behavior and doing it correctly from the listener. It is used for example in the ``FormRenderer ``
747
+ to set the notebook page visible before the scroll.
748
+
695
749
.. _frontend/services/title :
696
750
697
751
Title Service
0 commit comments