How to adjust kendo chat element to be full width

1 Answer 35 Views
Chat
Reza
Top achievements
Rank 1
Reza asked on 17 Jan 2025, 04:12 PM

Hi there,

 

In order to create a chat screen I need to adjust kendo chat to be full screen, how can I do that?

https://docs.telerik.com/aspnet-mvc/html-helpers/conversational-ui/chat/getting-started

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 20 Jan 2025, 09:44 PM

Hi Reza,

 

Thank you for contacting us.

You can achieve this requirement using the following CSS rule:

        .k-chat {
          max-width: 100%;
        }
Here is a live sample I've prepared for you:
https://dojo.telerik.com/AtKlPMkG/5

And the Chat takes all the available width:

Do you find this info beneficial? Let me know what you think.

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Reza
Top achievements
Rank 1
commented on 20 Jan 2025, 10:56 PM | edited

Hi Eyup,

Thank you for your response! It worked great. Could you also help me figure out how to adjust the input text button to multiline mode with a scrollbar?

Thank you,
Reza

Reza
Top achievements
Rank 1
commented on 22 Jan 2025, 09:20 PM

There isn’t a built-in feature to make the Kendo Chat input text element full width at this time. As a workaround, I hid the message box section and placed a Kendo TextArea and Kendo Upload elements behind it separately.


<style>
    body, html {
        height: 100%;
        margin: 0;
    }

    .k-chat {
        max-width: 100%;
    }

    .k-message-box {
        display: none;
    }
</style>


<div class="col-sm-12"> 
    <div id="chat"></div>
    <div id="chat-custom-editor">
        @(Html.Kendo().TextArea().Name("chat-textarea").Rows(5).HtmlAttributes(new { style = "width: 100%;", @class = "col-sm-12" }))
        @(Html.Kendo().Upload().Name("chat-user-files").Validation(validation => validation.AllowedExtensions(allowedExtensions.ToArray())).HtmlAttributes(new { aria_label = "files" }))
        @(Html.Kendo().Button().Name("chat-send-button").Icon("paper-plane"))
    </div>    
</div>


$(document).ready(function () {

    var chat;

    function initializeChat() {
        chat = $("#chat").kendoChat({
            user: {
                id: 1,
                name: 'User',
                iconUrl: '@Url.Content("~/Content/Images/user.png")'
            },
            post: function (args) {
                sendMessage(args.text, true);
            }
        }).data("kendoChat");

        if (!chat) {
            console.error("Failed to initialize chat widget");
            return;
        }
    }

    initializeChat();

    function sendMessage(text) {
        //any logic or api call here
        chat.renderMessage({
            type: "text",
            text: text,
            timestamp: new Date()
        }, chat.getUser());
        //or
        chat.renderMessage({
            type: "text",
            text: text,
            timestamp: new Date()
        }, {
            id: 2,
            name: "Robot",
            iconUrl: '@Url.Content("~/Content/Images/bot.png")'
        });
    }

    $("#chat-send-button").click(function () {
        sendMessage($("#chat-textarea").val());
    });


});

Eyup
Telerik team
commented on 23 Jan 2025, 10:21 AM

This is a nice approach.

Thank you for sharing it with our community!

Tags
Chat
Asked by
Reza
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or