For the complete documentation index, see llms.txt. This page is also available as Markdown.

rw.setRootElement

The rw.setRootElement() function configures the root HTML element that wraps your component. This allows you to control the element tag, CSS classes, and HTML attributes.

Syntax

rw.setRootElement({
    as: 'tagName',      // HTML tag to use
    class: 'classes',   // CSS classes
    args: { }           // HTML attributes
});

Parameters

Parameter
Type
Description

as

String

HTML tag name (e.g., 'div', 'section', 'article', 'a')

class

String

CSS classes to apply to the element

args

Object

HTML attributes as key-value pairs

Basic Examples

Setting the Tag

const transformHook = (rw) => {
    rw.setRootElement({
        as: 'section'
    });
};

exports.transformHook = transformHook;

Output: <section>...</section>

Adding Classes

Output: <div class="container p-4 m-2">...</div>

Adding Attributes

Output: <div class="my-component" id="hero" data-theme="dark" aria-label="Main content">...</div>

Common Patterns

Custom HTML Tag from Properties

Container with Full Styling

Alpine.js Integration

Accordion/Disclosure Pattern

Notes

  • The args object is spread directly as HTML attributes

  • Use undefined values to conditionally omit attributes

  • Classes are concatenated into a single class attribute

  • Works seamlessly with Tailwind CSS utility classes

Last updated

Was this helpful?