@molecule/app-tab-filter-svelte
Feature · tab-filter · App (browser) · v1.1.4 · Apache-2.0
Horizontal pill-tab filter with optional count badges and icons
npm install @molecule/app-tab-filter-svelteHow it works
@molecule/app-tab-filter-svelte is a ready-made tab-filter feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
<script lang="ts">
import { TabFilter } from '@molecule/app-tab-filter-svelte'
let activeTab = $state('all')
const tabs = [
{ id: 'all', label: 'All', count: 42 },
{ id: 'open', label: 'Open', count: 8 },
{ id: 'closed', label: 'Closed', count: 34 },
]
</script>
<TabFilter
defaultTab={{ id: 'all', label: 'All' }}
{tabs}
activeId={activeTab}
onChange={(id) => (activeTab = id)}
/>Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte
Reference
Svelte tab-style filter with inline count badges.
Exports <TabFilter> — horizontally-scrolling pill-tabs with counts —
and the TabFilterTab type. Different from a plain tabs row: this one
surfaces per-tab count badges and scrolls horizontally on overflow. Set
defaultTab to the collection's unfiltered view: it remains reachable when
tabs changes to a path/query-selected filter. A duplicate id appears once,
using the default tab's definition. Pass its id to the same onChange
navigation callback. Applications without a default view can omit it.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
<script lang="ts">
import { TabFilter } from '@molecule/app-tab-filter-svelte'
let activeTab = $state('all')
const tabs = [
{ id: 'all', label: 'All', count: 42 },
{ id: 'open', label: 'Open', count: 8 },
{ id: 'closed', label: 'Closed', count: 34 },
]
</script>
<TabFilter
defaultTab={{ id: 'all', label: 'All' }}
{tabs}
activeId={activeTab}
onChange={(id) => (activeTab = id)}
/>
Type
feature
Installation
npm install @molecule/app-tab-filter-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
API
Interfaces
TabFilterTab
Shape of a single tab entry passed to TabFilter.
interface TabFilterTab {
/** Unique id / state key. */
id: string
/** Display label: translated text, or a snippet rendering any node. */
label: string | Snippet
/** Optional leading icon: text, or a snippet rendering any node. */
icon?: string | Snippet
/** Optional count badge (e.g. number of items matching this filter). */
count?: number
/** When true, the tab renders disabled. */
disabled?: boolean
}
TabFilterProps
Props accepted by the TabFilter component.
interface TabFilterProps {
/** Tabs to render. */
tabs: TabFilterTab[]
/** Persistent collection/default view, retained even when tabs contains only the active filter. */
defaultTab?: TabFilterTab
/** Currently active tab id. */
activeId: string
/** Called when an enabled tab is clicked. */
onChange: (id: string) => void
/** Whether to allow the row to scroll horizontally. Defaults to true. */
scrollable?: boolean
/**
* When `true` (default), draws filled-pill backgrounds matching the
* polished flagship apps. Pass `false` for the older bare-text-only style.
*/
filled?: boolean
/** Extra classes. */
className?: string
}
Constants
TabFilter
const TabFilter: LegacyComponentType
Injection Notes
Requirements
Peer dependencies:
@molecule/app-svelte^3.5.0 || ^4.0.0@molecule/app-ui^1.1.0@molecule/app-ui-svelte^1.6.0svelte^5.0.0
Runtime Dependencies
-
@molecule/app-svelte -
@molecule/app-ui -
@molecule/app-ui-svelte -
svelte -
Requires a wired ClassMap bond (
getClassMap()throws before bonding). Labels are text or a snippet — pass translated strings. -
The default
filledpill backgrounds use Material-3 token utilities that only produce CSS when the app theme defines those tokens. In token-less apps passfilled={false}(font-weight-only active state) or add the tokens. -
Counts render via
toLocaleString();disabledtabs are non-interactive. Keyboard interaction is click/tab-focus only — no roving arrow-key navigation.