Tabs
Task: split a page into sections, one visible at a time.
yaml
# Recipe: sections of a page in tabs.
paths:
components: ./componentsEach ui:tab is a section with a title; the first one opens with the page, or the one open names. With open="{tab}" and tab read from the address, an action that redirects to /?tab=Plan brings the page back on the tab the user was on. The content of every tab is on the page, so a hidden tab is still there for search and for tests.
xml
<q:component name="Settings">
<q:set name="plan" value="Pro" />
<!-- ?tab=Plan opens the Plan tab; without it, the first one opens -->
<q:set name="tab" value="{query.tab}" default="Profile" />
<!-- after the action, the page comes back on the tab it was sent from -->
<q:action name="renew" method="POST">
<q:redirect url="/?tab=Plan" flash="Plan renewed." />
</q:action>
<ui:window title="Settings">
<ui:vbox padding="lg">
<q:if condition="flash">
<ui:alert variant="success">{flash}</ui:alert>
</q:if>
<!-- One ui:tab per section; open names the one that opens. -->
<ui:tabpanel open="{tab}">
<ui:tab title="Profile">
<ui:text>Name: Ana Lima</ui:text>
<ui:text>E-mail: ana@example.com</ui:text>
</ui:tab>
<ui:tab title="Plan">
<ui:text>Current plan: {plan}</ui:text>
<ui:badge variant="success">active</ui:badge>
<ui:button on-click="renew">Renew</ui:button>
</ui:tab>
<ui:tab title="Security">
<ui:text>Two-step sign-in is off.</ui:text>
</ui:tab>
</ui:tabpanel>
</ui:vbox>
</ui:window>
</q:component>xml
<q:test name="every tab has its title" page="/">
<test:visit />
<test:expect text="Profile" />
<test:expect text="Plan" />
<test:expect text="Security" />
</q:test>
<q:test name="every tab's content is on the page" page="/">
<test:visit />
<test:expect text="Name: Ana Lima" />
<test:expect text="Current plan: Pro" />
<test:expect text="Two-step sign-in is off." />
</q:test>
<q:test name="renewing comes back on the Plan tab" page="/">
<test:submit action="renew" />
<test:expect status="302" redirect="/?tab=Plan" flash="Plan renewed." />
</q:test>text
tests/tabs.test.q
PASS every tab has its title
PASS every tab's content is on the page
PASS renewing comes back on the Plan tab
3 passed, 0 failedui:tabpanel is in the Core set drawn by the browser, the console, the desktop window and the Hive's screen: UI-7; open: UI-17.