Skip to content

Commit fea1c7c

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

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/LiveComponent/src/EventListener/AddLiveAttributesSubscriber.php

Lines changed: 8 additions & 4 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,
@@ -75,14 +79,14 @@ public function onPreRender(PreRenderEvent $event): void
7579
}
7680

7781
$inputProps = $event->getMountedComponent()->getInputProps();
78-
$isDeferred = array_key_exists('defer', $inputProps);
82+
$isDeferred = \array_key_exists('defer', $inputProps);
7983

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)