<ui-outlet>

ui-outlet.mjs · ui-tab.mjs · ui-code.mjs · view.mjs · UiElement.mjs

ElementAttributesPropertiesMethodsEvents
<ui-outlet> active, load-feedback-delay .active, .current_view show(content, attrs?, name?) → Promise<bool>, show_from_element(el) view-changed, view-stop-request
<ui-tab> outlet, value, disabled — — —
<ui-code> src, for, lang — — —

View protocol: .readyP (Promise) · .ready (boolean) · .stop() (async) · view-stop-request (cancelable)

1. Element instance

show() accepts an already-created element. Properties set on the instance (non-string data, callbacks, objects) survive the switch — unlike attributes, which can only carry strings and booleans.

Show code

2. Async factory

show() also accepts a function that returns an element (or a Promise of an element). This is the idiomatic form for a view that needs data before it can render: fetch the data first, build the element with the data in place, return — no intermediate phase where the element exists without its data.

Show code

3. Tag name and attributes

show(tag, attrs) creates the element for you and applies any attributes. Simplest form when the view doesn't need rich data up front — the element fetches its own data in connectedCallback.

Show code

4a. Tabs — automatic activation

Arrow keys switch view immediately. Recommended when view content appears without delay.

Show code

4b. Tabs — manual activation

Arrow keys move focus. Enter/space switches view. Recommended for network loading or heavy rendering.

Show code

5. Unsaved changes guard

The view rejects view-stop-request via preventDefault(). Tick the box to allow switching.

Show code

6. Slow loading — debounced feedback

A view loading through an async factory or promise (section 2), or a view with a .readyP promise, gets automatic loading feedback via aria-busy. One busy period covers both waits. The feedback is debounced: the attribute is set only if loading takes longer than load-feedback-delay (in ms, default 200). Fast loads (under the delay) never flash. The CSS transition makes fade-in/fade-out visible once the feedback is shown.

slow-view resolves after 800ms. Change load-feedback-delay to see the difference.

Show code

7. stop() cleanup

View with a stop() method that logs cleanup. Verifies that it runs before removal.

Show code

8. Rapid switching

Runs show('a'), show('b'), show('a') in rapid succession. Only the last should win.

Show code

9. Declarative initial view

<ui-outlet active="test-view-a"> shows automatically on connect.

Leave the outlet empty in markup. It creates the view named by active and removes that view when replacing it. It does not remove unrelated children, so a panel placed inside it manually would remain visible beneath later views.

Removing active, or setting outlet.active = null, empties the outlet. Setting it again loads the named view. An outlet with no active attribute at connection starts empty.

Show code

10. Custom tab activation (show_from_element)

Values for show_from_element can be overridden to control what is rendered per tab — e.g. to deliver pre-initialized data. The value passed to show() as the third argument becomes the view's name and is reflected on ui-outlet[active].

Show code