Skip to content

feat: Add element_name to CustomElement to allow for distinct CustomElements #2158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

brunnelu
Copy link

@brunnelu brunnelu commented May 7, 2025

Introduce the element_name attribute to the CustomElement class, allowing for distinct identification of custom elements. Update relevant methods and interfaces to ensure compatibility with this new attribute. For backwards compatibility the element_name equals the name of custom element if not defined.

This solves the issue: #1841

I'll add the following example to the docs if you like this feature.

hello.py

import chainlit as cl
from chainlit import Message, on_chat_start


@on_chat_start
async def main():

    await cl.Message(
        content="Lorem Ipsum, ... source: source_1",
        author="AI Search",
        elements=[
            cl.CustomElement(
                element_name="IFrame",
                name="source_1",
                display="side",
                props={
                    "url": "https://example.com",
                    "title": "Some Title",
                },
            )
        ],
    ).send()

public/elements/IFrame.jsx

export default function IFrame() {
    return (
        <iframe
            src={props.url}
            title={props.title}
            style={{ width: "100%", height: "100%", border: "none" }}
        />
    );
}

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. backend Pertains to the Python backend. enhancement New feature or request frontend Pertains to the frontend. labels May 7, 2025
@brunnelu
Copy link
Author

brunnelu commented May 7, 2025

Just to clarify: this change is fully backwards compatible. If element_name is not defined, it simply defaults to the value of name, preserving existing behavior. This update only adds the option to set a different identifier (element_name) when needed, without breaking existing code.

@brunnelu
Copy link
Author

@willydouhard, could you please take a look? I tink this will feature will be appreciated.

Copy link
Contributor

@hayescode hayescode left a comment

Choose a reason for hiding this comment

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

You would need to update the data layers to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Pertains to the Python backend. enhancement New feature or request frontend Pertains to the frontend. size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants