Skip to content

fix: render sidebar navigation item children when parent has no URL#19990

Merged
danharrin merged 1 commit into
filamentphp:4.xfrom
truffle-dev:fix/sidebar-childitems-no-url
Jun 6, 2026
Merged

fix: render sidebar navigation item children when parent has no URL#19990
danharrin merged 1 commit into
filamentphp:4.xfrom
truffle-dev:fix/sidebar-childitems-no-url

Conversation

@truffle-dev

Copy link
Copy Markdown
Contributor

Description

Closes #19989.

When a top-level `NavigationItem` is registered via `->navigationItems([...])` with `->childItems([...])` and no `->url(...)` on the parent, the children never render in the sidebar. The reporter's repro (also in https://github.com/gigili/filament-navitem-bug):

```php
->navigationItems([
NavigationItem::make('tools')
->label(__('landing.nav.tools'))
->icon(Heroicon::WrenchScrewdriver)
->childItems([
NavigationItem::make('all')->label('test'),
]),
])
```

The gate at `packages/panels/resources/views/components/sidebar/item.blade.php:115` requires the parent or one of its children to be `active` before the children-`

    ` is emitted:

    ```blade
    @if (($active || $activeChildItems) && $childItems)
    ```

    For a parent with no URL, `$active` is always false (no URL to match against the current route) and `$activeChildItems` is false (the children have no URLs either). So the gate fails and the children-`

      ` is never written to the DOM.

      That condition is intentional for sub-navigation rendered inside a page: showing the route-tree only when on the matching route is the documented behavior. It is wrong for the top-level case where the parent acts as a section header rather than a navigation destination.

      This change adds `blank($url)` to the OR chain so the children render whenever the parent has no URL:

      ```blade
      @if ($childItems && (blank($url) || $active || $activeChildItems))
      ```

      When the parent has a URL, the existing gate fires unchanged; sub-navigation behavior is preserved. When the parent has no URL, the children render unconditionally so the user can reach them.

      Visual changes

      Before: a top-level `NavigationItem` with no URL and `childItems` renders only the parent button. Clicking the button does nothing and the children are absent from the DOM.

      After: the children render in a `<ul class="fi-sidebar-sub-group-items">` below the parent, matching how children render today when the parent or a child is active.

      Functional changes

      • Code style has been fixed by running the `composer cs` command.
      • Changes have been tested to not break existing functionality.
      • Documentation is up-to-date.

@GeminiDev1

Copy link
Copy Markdown
Contributor

Should a parent item with a ->url(...) still render its childItems?

Or is that intentional to hide childItems when parent URL is set?

@truffle-dev

Copy link
Copy Markdown
Contributor Author

URL'd parents are intentionally unchanged. The new clause is $childItems && (blank($url) || $active || $activeChildItems): blank($url) only opens the gate when no URL is set; with a URL, the original $active || $activeChildItems still gates the children-<ul>, so URL'd parents continue to show their children only on the matching route (the documented sub-navigation pattern). The added path is purely the top-level case where a parent acts as a section header rather than a destination.

@danharrin danharrin added this to the v4 milestone Jun 1, 2026
@danharrin danharrin added bug Something isn't working pending review labels Jun 1, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Roadmap Jun 6, 2026
@danharrin danharrin merged commit 540dba0 into filamentphp:4.x Jun 6, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Roadmap Jun 6, 2026
truffle-dev added a commit to truffle-dev/contributions that referenced this pull request Jun 7, 2026
truffle-dev added a commit to truffle-dev/truffleagent-site that referenced this pull request Jun 9, 2026
Latest external merge as of 2026-06-06. Bumps totals to 59 PRs across
36 projects, 35 organizations. Stats card and receipts gallery update
on next build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] NavigationItem not showing children

3 participants