Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Previous changes not listed in this document can be traced using Git history.

### Added

- Added persistence of active tab in `TabList`
- Added `externalNavigate` and `refresh` actions

## [1.0.26] - 2026-06-16
Expand Down
18 changes: 17 additions & 1 deletion src/widgets/TabList/TabList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TabsProps } from 'antd'
import { Empty, Result, Tabs } from 'antd'
import { useMemo } from 'react'
import { useSearchParams } from 'react-router'

import WidgetRenderer from '../../components/WidgetRenderer'
import type { WidgetProps } from '../../types/Widget'
Expand All @@ -13,6 +14,7 @@ export type TabListWidgetData = WidgetType['spec']['widgetData']

const TabList = ({ resourcesRefs, uid, widgetData }: WidgetProps<TabListWidgetData>) => {
const { items } = widgetData
const [searchParams, setSearchParams] = useSearchParams()

const tabItems = useMemo(() => {
return items.reduce<NonNullable<TabsProps['items']>>((acc, { label, resourceRefId, title }, index) => {
Expand Down Expand Up @@ -40,11 +42,25 @@ const TabList = ({ resourcesRefs, uid, widgetData }: WidgetProps<TabListWidgetDa
}, [])
}, [items, resourcesRefs, uid])

const paramKey = `tab-${uid}`
const storedKey = searchParams.get(paramKey)
const activeKey = tabItems.some(({ key }) => key === storedKey) ? storedKey! : (tabItems[0]?.key ?? '')

const handleTabChange = (key: string) => {
setSearchParams(prev => {
const next = new URLSearchParams(prev)
next.set(paramKey, key)
return next
},
{ replace: true }
)
}

if (!items.length) {
return <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
}

return <Tabs items={tabItems} key={uid} />
return <Tabs activeKey={activeKey} items={tabItems} key={uid} onChange={handleTabChange} />
}

export default TabList
Loading