Description
The expand-section, collapse-section, open-section, and toggle-section window event listeners in support/resources/views/components/section/index.blade.php have a JavaScript operator-precedence bug that prevents them from working when $collapseId is not set.
Affected lines
Lines 48, 50, 51, 52 in vendor/filament/support/resources/views/components/section/index.blade.php:
x-on:expand-section.window="if ($event.detail.id == @js($collapseId) ?? $el.id) isCollapsed = false"
Root cause
When $collapseId is null (the default — e.g. when using ->extraAttributes(['id' => 'section-foo']) instead of passing a collapseId), @js($collapseId) renders as JS null. The expression becomes:
if ($event.detail.id == null ?? $el.id) isCollapsed = false
JavaScript operator precedence: == (precedence 10) binds tighter than ?? (precedence 4), so this parses as:
if (($event.detail.id == null) ?? $el.id) isCollapsed = false
Since ?? only coalesces null/undefined (not false), and $event.detail.id == null evaluates to false for any real string id, the ?? never kicks in. The listener effectively only fires when detail.id is null/undefined — the opposite of the intended behavior.
Note: the x-data initializer on line 45 gets this right with template literals:
$persist(@js($collapsed)).as(`section-${@js($collapseId) ?? $el.id}-isCollapsed`)
Here there's no ==, so ?? works correctly as a fallback.
Fix
Wrap the fallback expression in parentheses so ?? resolves before ==:
x-on:expand-section.window="if ($event.detail.id == (@js($collapseId) ?? $el.id)) isCollapsed = false"
Same fix needed on all four affected lines (collapse-section, expand-section, open-section, toggle-section).
Steps to reproduce
- Create a Filament Section with
->collapsible()->collapsed() and ->extraAttributes(['id' => 'section-foo']) (no explicit collapseId)
- Dispatch from JS:
window.dispatchEvent(new CustomEvent('expand-section', { detail: { id: 'section-foo' } }))
- Expected: section expands
- Actual: nothing happens
Filament version
v5 (tested on latest)
Description
The
expand-section,collapse-section,open-section, andtoggle-sectionwindow event listeners insupport/resources/views/components/section/index.blade.phphave a JavaScript operator-precedence bug that prevents them from working when$collapseIdis not set.Affected lines
Lines 48, 50, 51, 52 in
vendor/filament/support/resources/views/components/section/index.blade.php:Root cause
When
$collapseIdisnull(the default — e.g. when using->extraAttributes(['id' => 'section-foo'])instead of passing acollapseId),@js($collapseId)renders as JSnull. The expression becomes:JavaScript operator precedence:
==(precedence 10) binds tighter than??(precedence 4), so this parses as:Since
??only coalescesnull/undefined(notfalse), and$event.detail.id == nullevaluates tofalsefor any real string id, the??never kicks in. The listener effectively only fires whendetail.idis null/undefined — the opposite of the intended behavior.Note: the
x-datainitializer on line 45 gets this right with template literals:Here there's no
==, so??works correctly as a fallback.Fix
Wrap the fallback expression in parentheses so
??resolves before==:Same fix needed on all four affected lines (collapse-section, expand-section, open-section, toggle-section).
Steps to reproduce
->collapsible()->collapsed()and->extraAttributes(['id' => 'section-foo'])(no explicitcollapseId)window.dispatchEvent(new CustomEvent('expand-section', { detail: { id: 'section-foo' } }))Filament version
v5 (tested on latest)