Skip to content
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

Add link to ui.tab to direct user to external URL when clicked on #2243

Open
nipunchamikara opened this issue Jan 31, 2024 · 1 comment
Open
Labels
feature Feature request ui Related to UI

Comments

@nipunchamikara
Copy link
Member

Is your feature request related to a problem? Please describe

I have a bunch of tabs which I use for navigation. I want the last one to link to documentation which is an external URL. However, I don't see a way to open an external URL using a tab.

Describe the solution you'd like

Ideally, the ability to specify an external URL in the tab, maybe a property called link just like a button.

Describe alternatives you've considered

For now, external URLs were opened by setting inline script to f'window.open("{external_url}");'. However, this is not ideal since the page has to be re-rendered. Do mention if there are any more elegant solutions to this.

@nipunchamikara nipunchamikara added the feature Feature request label Jan 31, 2024
@mturoci mturoci added the ui Related to UI label Feb 21, 2024
@rutujmirzapure
Copy link

Introduce a link property in ui.tab, similar to ui.button. When provided, the link property would override the tab's default behavior and redirect users to the specified URL. If not provided, the tab functions as it currently does, emitting an event to the backend.
`from h2o_wave import main, app, Q, ui

@app('/')
async def serve(q: Q):
if not q.client.initialized:
# Example usage of the proposed 'link' property in ui.tab
q.page['tabs'] = ui.tab_card(
box='1 1 4 1',
items=[
ui.tab(name='home', label='Home'), # Regular tab
ui.tab(name='about', label='About'), # Regular tab
ui.tab(name='documentation', label='Documentation', link='https://wave.h2o.ai') # Tab with external link
]
)
q.page['content'] = ui.markdown_card(
box='1 2 4 4',
title='Welcome',
content='Select a tab to navigate.'
)
q.client.initialized = True

# Backend logic for tabs that do not use the 'link' property
if q.args.home:
    q.page['content'].content = 'You are on the Home tab.'
elif q.args.about:
    q.page['content'].content = 'You are on the About tab.'

await q.page.save()

`

It will Simplifies navigation to external URLs without the need for custom scripts.Enhances the flexibility and usability of the ui.tab component.Reduces re-rendering overhead for static external links.

If this feature is not immediately available, users can achieve similar behavior with ui.inline_script:

q.page['script'] = ui.inline_script(""" document.querySelector('[data-tab-name="documentation"]').addEventListener('click', () => { window.open('https://wave.h2o.ai', '_blank'); }); """)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request ui Related to UI
Projects
None yet
Development

No branches or pull requests

3 participants