Pestañas
Traducción automática
Esta página se tradujo automáticamente del inglés y todavía no la revisó un hablante nativo; las correcciones son bienvenidas en GitHub. Si algo no coincide, vale el original en inglés.
Tarea: dividir una página en secciones, con una visible a la vez.
yaml
# Recipe: sections of a page in tabs.
paths:
components: ./componentsCada ui:tab es una sección con un title; la primera se abre con la página. El contenido de todas las pestañas está en la página, así que una pestaña oculta sigue ahí para la búsqueda y para las pruebas.
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 está en el conjunto del Núcleo que dibujan el navegador, la consola y la ventana de escritorio: UI-7.