Skip to content

Commit

Permalink
minor #1367 [live-component docs] Rearrange information about using c…
Browse files Browse the repository at this point in the history
…ustom Stimul… (srich387)

This PR was merged into the 2.x branch.

Discussion
----------

[live-component docs] Rearrange information about using custom Stimul…

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| Issues        | n/a
| License       | MIT

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, however, 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.

I have therefore swapped these two subsections around to improve their logical flow.

It is especially important that this information is presented clearly because it has caused confusion in the past; see e.g. #687.

Commits
-------

c8113e0 [live-component docs] Rearrange information about using custom Stimulus controllers
  • Loading branch information
kbond committed Jan 3, 2024
2 parents 41a53d5 + c8113e0 commit 86a7d39
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/LiveComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,21 @@ of the change:
input.dispatchEvent(new Event('change', { bubbles: true }));
Adding a Stimulus Controller to your Component Root Element
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 2.9

The ability to use the ``defaults()`` method with ``stimulus_controller()``
was added in TwigComponents 2.9 and requires ``symfony/stimulus-bundle``.
Previously, ``stimulus_controller()`` was passed to ``attributes.add()``.

To add a custom Stimulus controller to your root component element:

.. code-block:: html+twig

<div {{ attributes.defaults(stimulus_controller('my-controller', { someValue: 'foo' })) }}>

JavaScript Component Hooks
~~~~~~~~~~~~~~~~~~~~~~~~~~

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

Adding a Stimulus Controller to your Component Root Element
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 2.9

The ability to use the ``defaults()`` method with ``stimulus_controller()``
was added in TwigComponents 2.9 and requires ``symfony/stimulus-bundle``.
Previously, ``stimulus_controller()`` was passed to ``attributes.add()``.

To add a custom Stimulus controller to your root component element:

.. code-block:: html+twig

<div {{ attributes.defaults(stimulus_controller('my-controller', { someValue: 'foo' })) }}>

Loading States
--------------

Expand Down

0 comments on commit 86a7d39

Please sign in to comment.