Usage
Installation
React ≥ 18 is required.
Runtime environment
- Browser-oriented; server-side rendering (SSR) is not supported: floating components (
Popup, dropdown menus, toolbar popup panels) resolve their portal container and callcreatePortalduring render, which throws immediately on the server wheredocumentdoesn't exist. With isomorphic frameworks such as Next.js, keep these components out of the server render tree, or render them only after mounting on the client. - Both ESM and CJS builds are shipped, and they are separate module instances: when a Node process loads the package through both
importandrequire, the message registry and theOOUIProvidercontext are not shared; bundling for browsers is unaffected.
Outside MediaWiki sites (does anyone actually do that?), you have to load OOUI's theme CSS and the Codex design tokens yourself — as of oojs-ui 0.54, the token stylesheet must be loaded alongside it. Pick one theme stylesheet: wikimediaui is the current default, while apex is the legacy theme (some states look different between the two; the class names emitted by this library are valid under both):
The OOUI theme is sized against MediaWiki's body font size of 14px; keep your host page consistent with it.
The navbar of this site offers a "Preview theme" switcher to view all live demos under either wikimediaui or apex. The library itself ships no styles — whatever theme you switch to is exactly how the demos will look under it.
Using it on a MediaWiki site
This library was built first and foremost for user gadgets on MediaWiki sites. If bundle size matters to you, use the Preact compatibility layer instead of full React.
For working examples, see my Moegirlpedia gadgets repository:
Declaring dependencies
On a MediaWiki site the OOUI styles are served by its built-in oojs-ui resource modules. Load them at runtime with mw.loader.using or in your gadget's ResourceLoader definition:
The icon pack names are listed by group on the Icon component page.
Mounting
We recommend rendering into a div or a DocumentFragment, then inserting it before or after an anchor:
Preact compatibility
This library runs on the Preact compatibility layer (preact/compat); see the official guide for aliasing.
- Requires Preact ≥ 10.18.
react-dom/clientmust be aliased topreact/compat/client; without it the imperative APIs (confirm/alert/prompt) fail becausecreateRootis not available.