A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
return empty string if no tabs (#7772)
Shahmir Varqha3f016ac9ae3d
diff --git a/marimo/_plugins/ui/_impl/tabs.py b/marimo/_plugins/ui/_impl/tabs.pyindex 53e3b318b2..6a437a4423 100644--- a/marimo/_plugins/ui/_impl/tabs.py+++ b/marimo/_plugins/ui/_impl/tabs.py@@ -98,6 +98,8 @@ class tabs(UIElement[str, str]):def _convert_value(self, value: str) -> str:if not value:- return self._tab_keys[0]+ if self._tab_keys:+ return self._tab_keys[0]+ return ""index = int(value)return self._tab_keys[index]diff --git a/tests/_plugins/ui/_impl/test_tabs.py b/tests/_plugins/ui/_impl/test_tabs.pynew file mode 100644index 0000000000..767e83b030--- /dev/null+++ b/tests/_plugins/ui/_impl/test_tabs.py@@ -0,0 +1,45 @@+# Copyright 2026 Marimo. All rights reserved.+from __future__ import annotations++from marimo._plugins import ui+++def test_tabs_basic() -> None:+ tab = ui.tabs({"Tab 1": "Content 1", "Tab 2": "Content 2"})+ # Default value should be the first tab+ assert tab.value == "Tab 1"+++def test_tabs_with_initial_value() -> None:+ tab = ui.tabs({"Tab 1": "Content 1", "Tab 2": "Content 2"}, value="Tab 2")+ assert tab.value == "Tab 2"+++def test_tabs_update() -> None:+ tab = ui.tabs({"Tab 1": "Content 1", "Tab 2": "Content 2"})+ assert tab.value == "Tab 1"++ # Simulate selecting the second tab (index 1)+ tab._update("1")+ assert tab.value == "Tab 2"+++def test_tabs_empty() -> None:+ # Empty tabs should not raise an error+ tab = ui.tabs({})+ assert tab.value == ""+++def test_tabs_with_invalid_initial_value() -> None:+ # Invalid value should default to empty string, which converts to first tab+ tab = ui.tabs(+ {"Tab 1": "Content 1", "Tab 2": "Content 2"}, value="Invalid"+ )+ assert tab.value == "Tab 1"+++def test_tabs_lazy() -> None:+ tab = ui.tabs({"Tab 1": "Content 1", "Tab 2": "Content 2"}, lazy=True)+ assert tab.value == "Tab 1"+ # Verify lazy loading is enabled by checking the slotted HTML contains lazy+ assert "marimo-lazy" in tab.text