# elementor/trunk/modules/atomic-widgets/elements/atomic-tabs/handlers/editor-tabs-state.js

Elementor Website Builder – more than just a page builder, version trunk. 46 lines.

- Page: https://pluginprobe.com/plugins/elementor/trunk/code/modules/atomic-widgets/elements/atomic-tabs/handlers/editor-tabs-state.js
- Raw: https://pluginprobe.com/plugins/elementor/trunk/raw/modules/atomic-widgets/elements/atomic-tabs/handlers/editor-tabs-state.js
- Modified: 2026-05-20T12:19:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/elementor/trunk/code/modules/atomic-widgets/elements/atomic-tabs/handlers/editor-tabs-state.js#L10-L20`.

```javascript
import { Alpine } from '@elementor/alpinejs';
import { getTabId } from './utils';

/**
 * @typedef {Record<string, number>} TabsState - Maps tabsId to the selected tab index.
 */
const STORE_NAME = 'editor-atomic-tabs-state';

function ensureStore() {
	if ( ! Alpine.store( STORE_NAME ) ) {
		Alpine.store( STORE_NAME, /** @type {TabsState} */ ( {} ) );
	}

	return /** @type {TabsState} */ ( Alpine.store( STORE_NAME ) );
}

export function getActiveTabId( tabsId, fallback ) {
	const store = ensureStore();
	const storedIndex = store[ tabsId ];

	if ( storedIndex === undefined ) {
		return fallback;
	}

	return getTabId( tabsId, storedIndex );
}

export function setActiveTabIndex( tabsId, index ) {
	const store = ensureStore();

	store[ tabsId ] = index;
}

export function validateActiveTab( tabsId, tabCount ) {
	const store = ensureStore();
	const storedIndex = store[ tabsId ];

	if ( storedIndex === undefined ) {
		return;
	}

	if ( storedIndex >= tabCount ) {
		delete store[ tabsId ];
	}
}

```
