/symfony-ux-skills:stimulusfrom symfony-ux-skills
Provides Stimulus JavaScript behavior for Symfony UX: dropdowns, tabs, modals, clipboard buttons, and third-party widgets. Covers StimulusBundle, data-controller, data-action, targets, values, outlets, lazy controllers, and Twig stimulus_* helpers.
Ships in symfony-ux-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Modest JavaScript framework that connects JS objects to HTML via data attributes. Stimulus does not render HTML: it augments server-rendered HTML with behavior.
The mental model: HTML is the source of truth, JavaScript controllers attach to elements, and data attributes are the wiring. No build step required with AssetMapper.
data-controller="name" attach controller to element
data-name-target="item" mark element as a target
data-action="event->name#method" bind event to controller method
data-name-key-value="..." pass typed data to controller
data-name-key-class="..." configure CSS class names
data-name-other-outlet=".selector" reference another controller instance
// assets/controllers/example_controller.js
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
static targets = ['input', 'output'];
static values = { url: String, delay: { type: Number, default: 300 } };
static classes = ['loading'];
static outlets = ['other'];
connect() {
// Called when controller connects to DOM
}
disconnect() {
// Called when controller disconnects -- clean up here
}
submit(event) {
// Action method
}
}
File naming convention: hello_controller.js maps to data-controller="hello". Subdirectories use -- as separator: components/modal_controller.js maps to data-controller="components--modal".
If a controller reconnects during a Turbo visit or an event listener runs twice, check the Turbo compatibility examples.
<div data-controller="hello">
<input data-hello-target="name" type="text">
<button data-action="click->hello#greet">Greet</button>
<span data-hello-target="output"></span>
</div>
Pass server data to controllers via value attributes. Values are typed and automatically parsed.
<div data-controller="map"
data-map-latitude-value="{{ place.lat }}"
data-map-longitude-value="{{ place.lng }}"
data-map-zoom-value="12">
</div>
Available types: String, Number, Boolean, Array, Object. Values trigger {name}ValueChanged() callbacks when mutated.
The format is event->controller#method. Default events exist per element type (click for buttons, input for inputs, submit for forms) so the event can be omitted.
{# Explicit event #}
<button data-action="click->hello#greet">Greet</button>
{# Default event (click for button) #}
<button data-action="hello#greet">Greet</button>
{# Multiple actions on same element #}
<input type="text"
data-action="focus->field#highlight blur->field#normalize input->field#validate">
{# Prevent default #}
<form data-action="submit->form#validate:prevent">
{# Keyboard shortcuts #}
<div data-action="keydown.esc@window->modal#close">
<input data-action="keydown.enter->modal#submit keydown.ctrl+s->modal#save">
{# Global events (window/document) #}
<div data-action="resize@window->sidebar#adjust click@document->sidebar#closeOutside">
Externalize CSS class names so controllers stay generic:
<button data-controller="button"
data-button-loading-class="opacity-50 cursor-wait"
data-button-active-class="bg-blue-600"
data-action="click->button#submit">
Submit
</button>
// In controller
this.element.classList.add(...this.loadingClasses);
An element can have multiple controllers:
<div data-controller="dropdown tooltip"
data-action="mouseenter->tooltip#show mouseleave->tooltip#hide">
<button data-action="click->dropdown#toggle">Menu</button>
<ul data-dropdown-target="menu" hidden>...</ul>
</div>
Reference other controller instances by CSS selector:
<div data-controller="player"
data-player-playlist-outlet="#playlist">
<button data-action="click->player#playNext">Next</button>
</div>
<ul id="playlist" data-controller="playlist">
<li data-playlist-target="track">Song 1</li>
<li data-playlist-target="track">Song 2</li>
</ul>
// In player controller
static outlets = ['playlist'];
playNext() {
const tracks = this.playlistOutlet.trackTargets;
// ...
}
Instead of on initial page load, load controller JS when a matching data-controller element appears on the page. Use for controllers with heavy dependencies (chart libs, editors, maps) used on a few pages.
/* stimulusFetch: 'lazy' */
import { Controller } from '@hotwired/stimulus';
import Chart from 'chart.js';
export default class extends Controller {
connect() {
// Chart.js is only loaded once a matching element is on the page
}
}
Place the comment at the top level of the file (before or after the imports). If a minifier strips comments, use the preserved form /*! stimulusFetch: 'lazy' */, detected since Symfony UX 3.3+. For third-party controllers, set "fetch": "lazy" in assets/controllers.json.
Raw data attributes are the recommended approach: they need no helper, work everywhere and read easily.
{# Raw attributes (preferred) #}
<div data-controller="search"
data-search-url-value="{{ path('api_search') }}">
Twig helpers exist for complex cases or when generating attributes programmatically:
{# Twig helper #}
<div {{ stimulus_controller('search', { url: path('api_search') }) }}>
{# Chaining multiple controllers #}
<div {{ stimulus_controller('a')|stimulus_controller('b') }}>
{# Target and action helpers #}
<input {{ stimulus_target('search', 'query') }}>
<button {{ stimulus_action('search', 'submit') }}>
From PHP (form types, for instance), autowire StimulusHelper (since Symfony UX 3.5+):
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;
public function __construct(private StimulusHelper $stimulusHelper) {}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$attributes = $this->stimulusHelper->createStimulusAttributes();
$attributes->addController('country-picker', ['locale' => 'fr']);
$attributes->addAction('country-picker', 'refresh', 'change');
$builder->add('country', CountryType::class, ['attr' => $attributes->toArray()]);
}
StimulusBundle works with three asset systems. Controllers live in assets/controllers/, UX package controllers are listed in assets/controllers.json:
| Pipeline | Setup |
|---|---|
| AssetMapper (default) | Nothing to add: Flex wires assets/stimulus_bootstrap.js |
| Webpack Encore | Install @symfony/stimulus-bridge yourself (npm install --save-dev @symfony/stimulus-bridge) |
| Reprise (Vite / Rsbuild, experimental, since Symfony UX 3.3+) | Point the plugin at controllers.json, then start the app with @symfony/reprise/stimulus |
// vite.config.js (Reprise)
import { defineConfig } from 'vite';
import Symfony from '@symfony/reprise/vite';
export default defineConfig({
plugins: [Symfony({ stimulus: './assets/controllers.json' })],
});
// assets/stimulus_bootstrap.js (Reprise)
import { startStimulusApp } from '@symfony/reprise/stimulus';
const app = startStimulusApp();
HTML drives, JS responds. Controllers don't create markup: they attach behavior to existing HTML. If you find yourself generating DOM in a controller, consider whether a TwigComponent or LiveComponent would be better.
One controller, one concern. A dropdown controller handles dropdowns. A tooltip controller handles tooltips. Compose multiple controllers on the same element rather than building mega-controllers.
Clean up in disconnect(). If connect() adds event listeners, timers, or third-party library instances, disconnect() must remove them. Turbo navigation will disconnect and reconnect controllers as pages change.
Values over data attributes. Use Stimulus values (typed, with change callbacks) rather than raw data-* attributes for data that the controller needs to read or watch.
symfony/stimulus-bundle on Packagist.ux:map:*, chartjs:* and notify:* events to extend in your own controllerspath() and trans() inside controllersux:installWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub smnandre/symfony-ux-skills --plugin symfony-ux-skills20 skills in this plugin
/live-componentSymfony UX LiveComponent: live search, live filters, dependent selects and form validation as users type. Use for reactive PHP and Twig components, #[AsLiveComponent], LiveProp, LiveAction, data-model, loading states, emit/listen, lazy rendering and LiveResponse downloads./symfony-uxSymfony UX: choose and combine packages for a Symfony frontend. Use when deciding between Stimulus, Turbo, TwigComponent and LiveComponent, or fitting several Symfony UX packages into the same feature. Prefer the dedicated skill for a task that fits one package./turboSymfony UX Turbo: Turbo Frames for partial navigation and form submissions, Turbo Streams for multiple updates and Mercure broadcasts, and Turbo Drive for links and forms. Use for turbo-frame, turbo-stream, twig:Turbo, TurboFrame, TurboStreamResponse, turbo_stream_from and #[Broadcast].Other plugins' skills for the same job