Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/guides/custom-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ You register entire catalogs with your client application, not individual compon
4. **Agent Selects Catalog**: The agent chooses a catalog for a given UI surface.
5. **Agent Generates UI**: The agent generates `surfaceUpdate` messages using components from that catalog by name.

## Enabling Custom Components on the Surface

When using the `<a2ui-surface>` component, you must enable custom elements rendering by setting the `enableCustomElements` property to `true`. This allows custom components registered via the component registry to be rendered.

### Web (Lit)

```typescript
// Get reference to the surface element
const surfaceElement = document.querySelector('a2ui-surface');

// Enable custom elements
surfaceElement.enableCustomElements = true;

// Set other required properties
surfaceElement.surfaceId = 'main';
surfaceElement.surface = surface;
surfaceElement.processor = processor;
```

**Important**: Without setting `enableCustomElements = true`, custom components will not render, even if they are properly registered in the component registry.

### Why This is Required

The A2UI `Surface` component wraps the `Root` component, which handles the actual rendering. The `enableCustomElements` property controls whether the Root component should look up and instantiate custom elements from the component registry. By default, this is `false` to ensure only standard A2UI components are rendered unless explicitly enabled.

## Defining Custom Catalogs

TODO: Add detailed guide for defining custom catalogs for each platform.
Expand Down
4 changes: 4 additions & 0 deletions renderers/lit/src/0.8/ui/surface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export class Surface extends Root {
@property()
accessor processor: A2uiMessageProcessor | null = null;

@property({ type: Boolean })
accessor enableCustomElements = false;
Comment on lines +35 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This new property enables key functionality for the Surface component. Based on the repository's style guide (line 17), new code changes should include tests. Please add a unit test to verify that custom elements are correctly rendered when enableCustomElements is set to true on an <a2ui-surface> component.

References
  1. If there are code changes, code should have tests. (link)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing test suite (model.test.ts) focuses on the data processing layer and
doesn't include UI component rendering tests. UI component tests would require browser
globals (DOM, CustomEvent, HTMLElement, etc.) and a test environment setup (like
jsdom or happy-dom).


static styles = [
css`
:host {
Expand Down Expand Up @@ -118,6 +121,7 @@ export class Surface extends Root {
style=${styleMap(styles)}
.surfaceId=${this.surfaceId}
.processor=${this.processor}
.enableCustomElements=${this.enableCustomElements}
.childComponents=${this.surface?.componentTree
? [this.surface.componentTree]
: null}
Expand Down