Custom Components

Web SDK provides multiple ways to integrate custom components, allowing you to extend and customize its functionality. This guide will introduce several common methods.

Univer does not accept a component as an argument to a render function. A component must first be registered through the Facade API before it can be used at any location where Univer mounts custom content.

If a Facade API instance is not available yet, see Facade API.

Registering custom components

TypeScript
univerAPI.registerComponent(componentKey, CustomComponent, options)

Use univerAPI.registerComponent to register a custom component. The method accepts three parameters:

  • componentKey: the unique identifier of the component, which Univer uses to reference it later.
  • CustomComponent: the component implementation, which can be a React component, a Vue component, or a Web Component.
  • options: optional settings, such as the framework the component depends on.

React components

React components require no additional setup. Any valid React component can be registered:

TSX
function ReactComponent(props: Record<string, any>) {  return <div>Hello Univer!</div>}univerAPI.registerComponent('MyReactComponent', ReactComponent)

Vue components

Vue 3.x

Vue components require an adapter. Install and register UniverVue3AdapterPlugin from @univerjs/ui-adapter-vue3:

Shell
pnpm add @univerjs/ui-adapter-vue3
TypeScript
import { UniverVue3AdapterPlugin } from '@univerjs/ui-adapter-vue3'univer.registerPlugin(UniverVue3AdapterPlugin)

Set the framework option to 'vue3' when a Vue component is registered:

TSX
const Vue3Component = defineComponent({  setup(props) {    return () => <div>Hello Univer!</div>  },})univerAPI.registerComponent('MyVue3Component', Vue3Component, {  framework: 'vue3',})

Vue 2.x

Vue 2.x is EOL (End of Life) and no longer maintained, so Univer does not provide a UI adapter plugin for it. A custom plugin can implement the adapter instead. The following example shows one implementation:

TypeScript
import { DependentOn, Inject, Injector, Plugin } from '@univerjs/core'import { ComponentManager, UniverUIPlugin } from '@univerjs/ui'import Vue from 'vue'/** * The plugin that allows Univer to use Vue 2 components as UI components. */@DependentOn(UniverUIPlugin)export class UniverVue2AdapterPlugin extends Plugin {  static override pluginName = 'UNIVER_UI_VUE2_ADAPTER_PLUGIN'  constructor(    private readonly _config = {},    @Inject(Injector) protected readonly _injector: Injector,    @Inject(ComponentManager) protected readonly _componentManager: ComponentManager,  ) {    super()  }  override onStarting(): void {    const { createElement, useEffect, useRef } = this._componentManager.reactUtils    this._componentManager.setHandler('vue2', (component: any) => {      return (props: Record<string, any>) =>        createElement(VueComponentWrapper, {          component,          props: Object.keys(props).reduce<Record<string, any>>((acc, key) => {            if (key !== 'key') {              acc[key] = props[key]            }            return acc          }, {}),          reactUtils: { createElement, useEffect, useRef },        })    })  }}export function VueComponentWrapper(options: {  component: any  props: Record<string, any>  reactUtils: typeof ComponentManager.prototype.reactUtils}) {  const { component, props, reactUtils } = options  const { createElement, useEffect, useRef } = reactUtils  const domRef = useRef<HTMLDivElement>(null)  useEffect(() => {    if (!domRef.current) return    const Constructor = Vue.extend(component)    const instance = new Constructor({      data: props,    })    instance.$mount()    domRef.current.appendChild(instance.$el)    return () => {      instance.$destroy()    }  }, [props])  return createElement('div', { ref: domRef })}

Then register the plugin:

TypeScript
import { UniverVue2AdapterPlugin } from './ui-adapter-vue2'univer.registerPlugin(UniverUIPlugin)univer.registerPlugin(UniverVue2AdapterPlugin)

Vue 2.x components require the framework option to be set to 'vue2':

TSX
const Vue2Component = Vue.component('MyVue2Component', {  template: '<div>Hello, Univer!</div>',})univerAPI.registerComponent('MyVue2Component', Vue2Component, {  framework: 'vue2',})

Web Components

Web Components must follow the Web Components standard. Install and register UniverWebComponentAdapterPlugin from @univerjs/ui-adapter-web-component:

Shell
pnpm add @univerjs/ui-adapter-web-component
TypeScript
import { UniverWebComponentAdapterPlugin } from '@univerjs/ui-adapter-web-component'univer.registerPlugin(UniverWebComponentAdapterPlugin)

Set the framework option to 'web-component' when a Web Component is registered:

TSX
class WebComponent extends HTMLElement {  constructor() {    super()    const shadow = this.attachShadow({ mode: 'open' })    const div = document.createElement('div')    div.textContent = 'Hello Univer!'    shadow.appendChild(div)  }}univerAPI.registerComponent('my-web-component', WebComponent, {  framework: 'web-component',})

Angular

Convert an Angular component into a custom element with createCustomElement from @angular/elements, then register the element through the Univer Web Component adapter. The component can then be used in a Univer sidebar or dialog.

Keep @angular/elements on the same version as @angular/core, and @univerjs/ui-adapter-web-component on the same version as the other Univer packages.

Call the function after Univer has been initialized, and pass the Angular injector of the host component. Obtain the injector with private readonly injector = inject(Injector), then call registerAngularPanel(univer, univerAPI, this.injector). The host component imports inject and Injector from @angular/core.

TypeScript
import type { Injector } from '@angular/core'import type { FUniver, Univer } from '@univerjs/presets'import { Component } from '@angular/core'import { createCustomElement } from '@angular/elements'import { UniverWebComponentAdapterPlugin } from '@univerjs/ui-adapter-web-component'@Component({  selector: 'app-angular-panel',  standalone: true,  template: '<p>Hello from Angular!</p>',})export class AngularPanelComponent {}export function registerAngularPanel(univer: Univer, univerAPI: FUniver, injector: Injector) {  const element = createCustomElement(AngularPanelComponent, { injector })  univer.registerPlugin(UniverWebComponentAdapterPlugin)  return univerAPI.registerComponent('univer-angular-panel', element, {    framework: 'web-component',  })}

After the editor has rendered, use the registered key as the sidebar content:

TypeScript
const sidebar = univerAPI.openSidebar({  header: { title: 'Angular' },  children: { label: 'univer-angular-panel' },  width: 360,})

Retain the returned registration and sidebar handles and call dispose() on each when it is no longer needed. Register the element once per application. Its name must contain a hyphen and must differ from the Angular component selector.

Angular Elements maps inputs to element properties and outputs to DOM CustomEvent events. The Univer adapter sets properties but does not subscribe to Angular outputs. The application subscribes to those events when they are required.

Using custom components

The methods below cover the common ways to place a custom component in the Univer UI.

Caution

  1. Wait until Univer has finished rendering before calling these methods. 2. Register components that require registration before use. 3. Call dispose() to clean up and remove added components; otherwise the application leaks memory.

Adding custom menu items

Both the top menu bar (Ribbon) and the right-click menu (Context Menu) can contain custom components. Adding a component to a menu item requires a custom plugin.

Replacing built-in components

Warning

Replacing a built-in component can break other features that depend on it. Read the source code and the documentation before replacing a component, and proceed with caution.

univerAPI.registerComponent registers an override by default (override: true). The override takes precedence over the built-in component whether the plugin registers its default before or after this call. Only one override can be active per componentKey, so dispose the previous registration before registering another. Calling dispose() on the returned registration restores the built-in default if one is registered. Pass { override: false } to register a default instead.

Register an override before the corresponding view opens for the first time. Registration changes do not automatically rerender views that are already mounted.

For example, replacing the built-in ColorPicker component requires a single call:

TSX
// Following code only replaces the UI of the built-in ColorPicker component, not its functionalityuniverAPI.registerComponent('UI_COLOR_PICKER_COMPONENT', () => <input type="color" />)

Replacing user information rendering

@univerjs/ui renders user names and avatars through UserInfo. UserInfo renders through the component registered for USER_INFO_COMPONENT and falls back to DefaultUserInfo when none is registered. Register a host component before the corresponding view opens:

TSX
import { USER_INFO_COMPONENT } from '@univerjs/ui'import type { IUserInfoProps } from '@univerjs/ui'function HostUserInfo({ user, part, context, className, fallbackSrc }: IUserInfoProps) {  if (part === 'avatar') {    return <img className={className} src={user.avatar ?? fallbackSrc} alt="" />  }  return (    <span className={className} data-user-id={user.userId} data-scene={context.scene}>      {user.name ?? user.userId}    </span>  )}univerAPI.registerComponent(USER_INFO_COMPONENT, HostUserInfo)

UserInfo passes the following fields:

  • user: { userId?, name?, avatar?, isAnonymous? }. userId is the source identity and is available before the profile loads. It is never a collaboration session ID.
  • part: 'name' or 'avatar'. The component renders each part separately.
  • context: { scene, unitId?, subUnitId?, commentId?, threadId?, versionId?, objectId?, tableId?, fieldId?, recordId? }. scene is one of 'comment-author', 'history-author', 'history-filter', 'permission-member', 'permission-creator', or 'base-person'. unitId is absent for standalone controls that have no associated document.
  • avatarSize?, fallbackSrc?, and className?: optional rendering hints for avatars and the name element.

DefaultUserInfo renders the built-in name and avatar and can be used for scenes that a host does not customize. inheritUserInfoComponent(source, target) registers the source ComponentManager's user-info component in another component manager, such as a child Univer instance for history or preview, so the same override applies there. It registers DefaultUserInfo when the source has no user-info component.

The override changes rendering only. It does not change persisted mentions, search text, or Canvas output. As with other component overrides, register before the view first opens. Registration changes do not rerender views that are already mounted.

Using as content components

In the sidebar

univerAPI.openSidebar opens a sidebar in the Univer interface whose content is a registered component.

TSX
// You should register the component at an appropriate time (e.g., after Univer has loaded)univerAPI.registerComponent('MyCustomSidebarComponent', () => <div>Hello Univer!</div>)const sidebar = univerAPI.openSidebar({  header: { title: 'My Sidebar' },  children: { label: 'MyCustomSidebarComponent' },  onClose: () => {    console.log('close')  },  width: 360,})// Later close the sidebarsidebar.dispose()

See univerAPI.openSidebar.

In a dialog

univerAPI.openDialog opens a dialog whose content is a custom component.

TSX
// You should register the component at an appropriate time (e.g., after Univer has loaded)univerAPI.registerComponent('MyCustomDialogComponent', () => <div>Hello Univer!</div>)const dialog = univerAPI.openDialog({  id: 'unique-dialog-id', // The unique identifier for the dialog  draggable: true,  width: 300,  title: { title: 'My Dialog' },  children: {    label: 'MyCustomDialogComponent',  },  destroyOnClose: true,  preservePositionOnDestroy: true,  onClose: () => {},})// Later close the dialogdialog.dispose()

See univerAPI.openDialog.

How is this guide?

© 2026 DreamNum Co., Ltd.