Skip to content

feat: introduced 'tab' component for more organized UI (fixes issue #520) #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

avyuktsoni0731
Copy link

Related Issue
Fixes #520

Description of Changes
This PR implements a TabWidget component for rendering grouped UI elements within tabbed interfaces. It solves the issue where components passed to tab() were being rendered both inside the tab and again outside, causing duplication and incorrect layout behavior.

  • 🧩 New TabWidget: A dynamic ShadCN-based tab UI that renders individual components inside their respective tab panels. Handles raw strings, objects without types, and standard widget objects.
  • Normalized Component Handling: Inside TabWidget.jsx, raw string components like "Welcome to the Iris app" are normalized to text components with proper structure.
  • 🧼 ID-based Filtering: In App.jsx, added logic to filter out components that belong to a tab to prevent them from appearing both inside and outside the tab.
  • 🛡️ Ensures clean isolation of tab components during rendering inside DynamicComponents.
  • 💬 Properly passes onComponentUpdate to ensure tab-internal widgets update state correctly.

Files added/updated:

  • src/components/widgets/TabWidget.jsx (new)
  • DynamicComponents.jsxcase 'tab' added
  • package.json – added shadCN dependencies
  • App.jsx – filters components.rows based on tab-owned IDs
  • components.py – added tab() component
  • __init__.py – imported tab from components.py

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Testing

  • Modified a iris example with the following configuration:
from preswald import tab, table, plotly, text, get_df, connect
import plotly.express as px

connect()
df = get_df("iris_csv")
fig = px.scatter(df, x="sepal.length", y="sepal.width", color="variety")

text("Welcome to Iris App")

tab(
    label="Data Views",
    tabs=[
        {"title": "Table", "components": [table(df)]},
        {"title": "Plot", "components": [plotly(fig)]},
    ]
)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have run my code against examples and ensured no errors
  • Any dependent changes have been merged and published in downstream modules

@amrutha97 amrutha97 force-pushed the main branch 2 times, most recently from 6ac1dad to bdb2c4e Compare April 24, 2025 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Introduce tab() Component for Multi-Section UI Navigation
1 participant