23vbq / top-layer-bundle
Native <dialog> modals, drawers and toasts for Symfony with Turbo and Stimulus
Package info
github.com/23vbq/top-layer-bundle
Type:symfony-bundle
pkg:composer/23vbq/top-layer-bundle
Requires
- php: >=8.2
- symfony/framework-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/stimulus-bundle: ^2.0 || ^3.0
- symfony/twig-bundle: ^6.4 || ^7.0 || ^8.0
- symfony/ux-turbo: ^2.15 || ^3.0
- symfony/ux-twig-component: ^2.20 || ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.1
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.5 || ^12.0 || ^13.0
- symfony/asset-mapper: ^6.4 || ^7.0 || ^8.0
- symfony/browser-kit: ^6.4 || ^7.0 || ^8.0
Suggests
- symfony/asset-mapper: To load the bundle's Stimulus controllers without a JS build step
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-26 21:55:37 UTC
README
Native <dialog> modals, drawers and toasts for Symfony with Turbo and Stimulus.
Status
Work in progress, not yet released. The API is not stable and may change at any time.
Why native <dialog>
- Top layer - modals opened with
showModal()and popovers are rendered in the browser's top layer, above the rest of the page. - No z-index - the top layer sits above all other content, so there is no z-index stacking to manage.
- Built-in backdrop - the
::backdroppseudo-element provides an overlay without extra markup. - Focus trap and Escape - modal dialogs make the rest of the page inert, keep focus inside the dialog and close on Escape out of the box.
Installation
composer require 23vbq/top-layer-bundle
The bundle requires Turbo 8 (@hotwired/turbo ^8.0). With AssetMapper, check the version in importmap.php.
Quick start
Place a modal and the button that opens it inside an element with the bundle's Stimulus controller:
<div data-controller="23vbq--top-layer-bundle--dialog"> <button type="button" data-action="23vbq--top-layer-bundle--dialog#open" data-23vbq--top-layer-bundle--dialog-src-param="{{ path('employee_delete', {id: employee.id}) }}"> Delete </button> <twig:TopLayer:Modal id="modal-employee-action" frame="employee-action" title="Delete employee" /> </div>
Clicking the button loads the URL into the modal. The page behind it renders its content inside a matching <turbo-frame>:
<turbo-frame id="employee-action"> {# form, confirmation, ... #} </turbo-frame>
Documentation
- Modal and drawer - components, props, opening and closing
- Turbo Stream actions - closing dialogs and reloading frames from a server response
- Toasts - flash-based notifications, configuration, toasts above modals
- Styling - CSS variables, dark mode, overriding classes and templates