Skip to content

Commit 4d23086

Browse files
committed
[ADD] developer: scroller service added
This commit adds the documentation related to the scroller service. This service is used for the webclient to handle clicks on links and there were no documentation related until now.
1 parent d761910 commit 4d23086

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

content/developer/reference/frontend/services.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ Reference List
128128
- manage the browser url
129129
* - :ref:`rpc <frontend/services/rpc>`
130130
- send requests to the server
131+
* - :ref:`scroller <frontend/services/scroller>`
132+
- handle clicks on anchors elements
131133
* - :ref:`title <frontend/services/title>`
132134
- read or modify the window title
133135
* - :ref:`user <frontend/services/user>`
@@ -692,6 +694,58 @@ When a rpc fails, then:
692694
displayed and the server is regularly contacted until it responds. The
693695
notification is closed as soon as the server responds.
694696

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+
695749
.. _frontend/services/title:
696750

697751
Title Service

0 commit comments

Comments
 (0)