Skip to content

Commit 7f62a42

Browse files
committed
Adjust attributes names and allow choosing a custom HTML tag
1 parent fd97359 commit 7f62a42

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/LiveComponent/src/EventListener/AddLiveAttributesSubscriber.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
*/
3636
final class AddLiveAttributesSubscriber implements EventSubscriberInterface, ServiceSubscriberInterface
3737
{
38+
private const DEFAULT_LOADING_TAG = 'div';
39+
40+
private const DEFAULT_LOADING_TEMPLATE = null;
41+
3842
public function __construct(
3943
private ComponentStack $componentStack,
4044
private TemplateMap $templateMap,
@@ -80,9 +84,9 @@ public function onPreRender(PreRenderEvent $event): void
8084
if ($isDeferred) {
8185
$event->setTemplate('@LiveComponent/deferred.html.twig');
8286

83-
if ($loadingTemplate) {
84-
$variables['loadingTemplate'] = $loadingTemplate;
85-
}
87+
$variables['loadingTag'] = $originalAttributes['loading-tag'] ?? self::DEFAULT_LOADING_TAG;
88+
$variables['loadingTemplate'] = $originalAttributes['loading-template'] ?? self::DEFAULT_LOADING_TEMPLATE;
89+
$attributes = $attributes->without('defer', 'loading-element', 'loading-template');
8690
}
8791
}
8892

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
<div {{ attributes }} data-action="live:connect->live#$render">
2-
{% if loadingTemplate is defined and loadingTemplate != null %}
3-
{{ include(loadingTemplate) }}
4-
{% endif %}
5-
</div>
1+
<{{ loadingTag }} {{ attributes }} data-action="live:connect->live#$render">
2+
{% block loadingContent %}
3+
{% if loadingTemplate != null %}
4+
{{ include(loadingTemplate) }}
5+
{% endif %}
6+
{% endblock %}
7+
</{{ loadingTag }}>

0 commit comments

Comments
 (0)