Abas
Tradução automática
Esta página foi traduzida automaticamente do inglês e ainda não foi revisada por um falante nativo; correções são bem-vindas no GitHub. Se algo não bater, vale o original em inglês. O código e os resultados são os mesmos do original, importados dos arquivos testados.
Tarefa: dividir uma página em seções, uma visível de cada vez.
yaml
# Recipe: sections of a page in tabs.
paths:
components: ./componentsCada ui:tab é uma seção com um title; a primeira abre com a página. O conteúdo de todas as abas está na página, então uma aba escondida continua lá para a busca e para os testes.
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 faz parte do conjunto do Núcleo desenhado pelo navegador, pelo console e pela janela de desktop: UI-7.