MDUIDocs
Copy llms.txt linkCopy llms-full.txt linkView this page in MarkdownDiscuss this page with ChatGPTDiscuss full project docs with ChatGPT
Preset Colors
Custom Color
Extract from Wallpaper
Please select a wallpaper
Getting Started
Overview Installation Usage TypeScript Support IDE Support Localization FAQ
AI-Assisted Development
Styles
Integration with Frameworks
Components
Functions
Libraries

FAQ

These are some frequently asked questions about mdui. Check them before posting in the community or opening a new issue.

Why Don't Components Display with Self-Closing Tags?

mdui is a library based on Web Components. Web Components do not support self-closing tags, so you should always use closing tags with mdui components.

<!-- Incorrect usage -->
<mdui-text-field />

<!-- Correct usage -->
<mdui-text-field></mdui-text-field>

How to Prevent Unstyled Components from Appearing Before They Load?

mdui components are registered via JavaScript, which can briefly leave them unstyled until the script loads and registers them. Here are two solutions:

One solution is to use the :defined pseudo-class to hide unregistered mdui components. The following CSS hides all unregistered mdui components and shows them once registered:

:not(:defined) {
  visibility: hidden;
}

Another solution is to use the customElements.whenDefined() method. This method returns a promise that resolves when the specified component is registered. To handle cases where some components may fail to load, use Promise.allSettled().

In the following example, the <body> element is initially hidden using opacity: 0 and fades in after the components are registered. Promise.allSettled() is used to wait for all promises to complete, ensuring the page displays properly even if a component fails to load.

<style>
  body {
    opacity: 0;
  }

  body.ready {
    opacity: 1;
    transition: 0.25s opacity;
  }
</style>

<script type="module">
  await Promise.allSettled([
    customElements.whenDefined('mdui-button'),
    customElements.whenDefined('mdui-card'),
    customElements.whenDefined('mdui-checkbox'),
  ]);

  // After registering the button, card, and checkbox components, add the 'ready' class to fade in the page
  document.body.classList.add('ready');
</script>
On this page