Skip to content

Commit c8113e0

Browse files
authored
[live-component docs] Rearrange information about using custom Stimulus controllers
In the section 'Working with the Component in JavaScript', the preamble mentions that you can create a custom Stimulus controller and attach it to or put it around the root component element in order to control its behaviour. How to attach a custom controller is only explained further down in the subsection 'Adding a Stimulus Controller to your Component Root Element'. This subsection is currently buried beneath an intervening subsection on a different topic, 'JavaScript Component Hooks', making it easy for a reader to overlook. As such, to improve the logical flow of the documentation, I have swapped these two subsections around. It is especially important that this information is presented clearly because it has caused confusion in the past; see e.g. symfony#687.
1 parent d109f66 commit c8113e0

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,21 @@ of the change:
842842
843843
input.dispatchEvent(new Event('change', { bubbles: true }));
844844
845+
Adding a Stimulus Controller to your Component Root Element
846+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
847+
848+
.. versionadded:: 2.9
849+
850+
The ability to use the ``defaults()`` method with ``stimulus_controller()``
851+
was added in TwigComponents 2.9 and requires ``symfony/stimulus-bundle``.
852+
Previously, ``stimulus_controller()`` was passed to ``attributes.add()``.
853+
854+
To add a custom Stimulus controller to your root component element:
855+
856+
.. code-block:: html+twig
857+
858+
<div {{ attributes.defaults(stimulus_controller('my-controller', { someValue: 'foo' })) }}>
859+
845860
JavaScript Component Hooks
846861
~~~~~~~~~~~~~~~~~~~~~~~~~~
847862

@@ -876,21 +891,6 @@ The following hooks are available (along with the arguments that are passed):
876891
* ``loading.state:finished`` args ``(element: HTMLElement)``
877892
* ``model:set`` args ``(model: string, value: any, component: Component)``
878893

879-
Adding a Stimulus Controller to your Component Root Element
880-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
881-
882-
.. versionadded:: 2.9
883-
884-
The ability to use the ``defaults()`` method with ``stimulus_controller()``
885-
was added in TwigComponents 2.9 and requires ``symfony/stimulus-bundle``.
886-
Previously, ``stimulus_controller()`` was passed to ``attributes.add()``.
887-
888-
To add a custom Stimulus controller to your root component element:
889-
890-
.. code-block:: html+twig
891-
892-
<div {{ attributes.defaults(stimulus_controller('my-controller', { someValue: 'foo' })) }}>
893-
894894
Loading States
895895
--------------
896896

0 commit comments

Comments
 (0)