Table of Contents
In-page heading navigation that highlights the section currently in view.
Preview
Getting started
Install the package and register the service provider. Scroll the page to watch the active section update in the navigation beside this content.
Requirements
You will need a recent PHP runtime and a compatible Laravel application before continuing with the setup steps.
Configuration
Publish the configuration file and adjust the defaults to match your environment. Each option is documented inline for clarity.
Environment variables
Sensitive values belong in your environment file rather than committed configuration so they never leak into source control.
Usage
Drop the component into any Blade view and it will smooth-scroll to each section while highlighting the heading currently in view.
Controls
Device view renders in an isolated frame so real responsive breakpoints apply. Switch to Full for overflowing popovers.
Installation
php artisan ui:add table-of-contents
Behavior layer (Alpine)
This component installs a self-registering Alpine module to
resources/js/ui/table-of-contents.js. Import the behavior layer once
from your bundle so it loads (it hooks alpine:init):
import './table-of-contents.js';
Registry contract
Install confidence
php artisan ui:add table-of-contents
writes only the generated targets below. The CLI validates each file hash before writing and
prompts before replacing local changes unless --force is used.
- Version
- 1.0.1
- License
- open
- Stability
- stable
- Contract
- v2
- Foundation
- ≥ 1.0.0
| Type | Generated target |
|---|---|
| blade | resources/views/components/ui/table-of-contents.blade.php |
| js | resources/js/ui/table-of-contents.js |
Registry dependencies
None.
Package dependencies
composer: jml/brok:^1.0
npm: alpinejs
Guidance
Navigation and orientationOrient users and move between destinations.
Use when
- Use to orient users and help them move across pages, sections, or commands. Do not hide primary wayfinding in novelty interactions or deep nested structures if straightforward navigation would be clearer.
Avoid when
- Avoid using table-of-contents as a default simply because it is available in the library. Choose it only when its interaction cost, visibility, and behavior match the job to be done.
- Task length
- micro
- Interaction cost
- low
- Interruptiveness
- none
- Input precision
- none
- Mobile / touch risk
- low
- Accessibility risk
- medium
- Needs background context
- No
- Comparison needed
- No
Preferred alternatives
- Visible links and local navigation
Anti-patterns
- Hiding primary wayfinding in novelty interactions
API
manifest knowledge + registry-derived coverageProps
| Prop | Type / values | Default | Description |
|---|---|---|---|
| target | mixed|null | null | Declared by @props in the registry Blade source. |
| selector | string | h2, h3 | Declared by @props in the registry Blade source. |
| items | array | [] | Declared by @props in the registry Blade source. |
| title | mixed|null | null | Declared by @props in the registry Blade source. |
Slots
Components use the default Blade slot unless a documented subcomponent is installed by the registry item.
Data slots
table-of-contents
table-of-contents-item
table-of-contents-list
table-of-contents-title
Capabilities
Behavior
- Uses server-rendered Blade and semantic HTML.
- Installs a JavaScript behavior module when the registry item includes resources/js/ui files.
- Declares registry capability flags: a11y, interactive, responsive, rtl, darkMode, localized.
Usage
<div class="grid gap-8 md:grid-cols-[1fr_220px]">
<article id="toc-demo" class="space-y-4">
<section>
<h2 id="getting-started" class="text-xl font-semibold text-foreground">{{ __('Getting started') }}</h2>
<p class="text-muted-foreground">{{ __('Install the package and register the service provider. Scroll the page to watch the active section update in the navigation beside this content.') }}</p>
</section>
<section>
<h3 id="requirements" class="text-lg font-medium text-foreground">{{ __('Requirements') }}</h3>
<p class="text-muted-foreground">{{ __('You will need a recent PHP runtime and a compatible Laravel application before continuing with the setup steps.') }}</p>
</section>
<section>
<h2 id="configuration" class="text-xl font-semibold text-foreground">{{ __('Configuration') }}</h2>
<p class="text-muted-foreground">{{ __('Publish the configuration file and adjust the defaults to match your environment. Each option is documented inline for clarity.') }}</p>
</section>
<section>
<h3 id="environment" class="text-lg font-medium text-foreground">{{ __('Environment variables') }}</h3>
<p class="text-muted-foreground">{{ __('Sensitive values belong in your environment file rather than committed configuration so they never leak into source control.') }}</p>
</section>
<section>
<h2 id="usage" class="text-xl font-semibold text-foreground">{{ __('Usage') }}</h2>
<p class="text-muted-foreground">{{ __('Drop the component into any Blade view and it will smooth-scroll to each section while highlighting the heading currently in view.') }}</p>
</section>
</article>
<x-ui.table-of-contents target="#toc-demo" class="md:sticky md:top-4 md:self-start" />
</div>
Accessibility & localization
data-slot
Keyboard focus-visible
Localized labels
- Accessibility target: wcag-2.2-aa-target.
- Uses semantic HTML and a stable
data-slotattribute for styling/scripting hooks. - Focus-visible rings use the
ringtoken so keyboard focus is always visible. - Disabled and invalid states are conveyed to assistive tech, not by color alone.
- Targets WCAG 2.2 AA; verify contrast in light, dark, admin and customer surfaces above.
- Labels go through
__()and the component uses logical properties (ms-*,text-start,start-*) so it mirrors correctly — flip the preview to RTL to confirm.
Source
The exact, editable file ui:add writes
into your app — copy it or own the whole thing. Previews
render this same code; there are no preview-only components.
Changelog
Current version: v1.0.1. See the site changelog for the full release history.