[IMP] hooks: useAutofocus new API
Recently, the API of useAutofocus has been simplified (see 4308de6aab
).
Here we adapt its documentation.
closes odoo/documentation#1572
Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
This commit is contained in:
parent
dce73864eb
commit
9f179bd49d
@ -23,7 +23,7 @@ documents the list of hooks provided by the Odoo web framework.
|
|||||||
* - :ref:`useAssets <frontend/hooks/useassets>`
|
* - :ref:`useAssets <frontend/hooks/useassets>`
|
||||||
- load assets
|
- load assets
|
||||||
* - :ref:`useAutofocus <frontend/hooks/useAutofocus>`
|
* - :ref:`useAutofocus <frontend/hooks/useAutofocus>`
|
||||||
- focus automatically a referenced element
|
- focus automatically an element referenced by autofocus
|
||||||
* - :ref:`useBus <frontend/hooks/usebus>`
|
* - :ref:`useBus <frontend/hooks/usebus>`
|
||||||
- subscribe and unsubscribe to a bus
|
- subscribe and unsubscribe to a bus
|
||||||
* - :ref:`usePager <frontend/hooks/usepager>`
|
* - :ref:`usePager <frontend/hooks/usepager>`
|
||||||
@ -61,10 +61,8 @@ Location
|
|||||||
Description
|
Description
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Focus automatically an element referenced by a component after its rendering if
|
Focus an element referenced by a t-ref="autofocus" in the current component as
|
||||||
that element was not already present in the dom. The focus of that element can
|
soon as it appears in the DOM and if it was not displayed before.
|
||||||
be forced at a future patch if the returning value (a function) of useAutofocus
|
|
||||||
is called.
|
|
||||||
|
|
||||||
.. code-block:: javascript
|
.. code-block:: javascript
|
||||||
|
|
||||||
@ -72,10 +70,7 @@ is called.
|
|||||||
|
|
||||||
class Comp {
|
class Comp {
|
||||||
setup() {
|
setup() {
|
||||||
const focusOnUpdate = useAutofocus("to_focus");
|
this.inputRef = useAutofocus();
|
||||||
}
|
|
||||||
onStateReset() {
|
|
||||||
focusOnUpdate();
|
|
||||||
}
|
}
|
||||||
static template = "Comp";
|
static template = "Comp";
|
||||||
}
|
}
|
||||||
@ -83,16 +78,15 @@ is called.
|
|||||||
.. code-block:: xml
|
.. code-block:: xml
|
||||||
|
|
||||||
<t t-name="Comp" owl="1">
|
<t t-name="Comp" owl="1">
|
||||||
<input t-ref="to_focus" type="text"/>
|
<input t-ref="autofocus" type="text"/>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
API
|
API
|
||||||
---
|
---
|
||||||
|
|
||||||
.. js:function:: useAutofocus([ref])
|
.. js:function:: useAutofocus()
|
||||||
|
|
||||||
:param string ref: optional. If given, must be a t-ref value. Default is "autofocus"
|
:returns: the element reference.
|
||||||
:returns: a function to be called if focus must be forced on next patch.
|
|
||||||
|
|
||||||
.. _frontend/hooks/usebus:
|
.. _frontend/hooks/usebus:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user