Force resize of canvas using SfDocumentEditorContainer

Hi,

I've been working with the Blazor Word Processor component.

This is how I set it up:

<div>

<SfDocumentEditorContainer @ref="container" Height="600px" EnableToolbar=true ToolbarItems="@Items">

</SfDocumentEditorContainer>

</div>


@code {

    SfDocumentEditorContainer container;

    string[] Items = new string[14] { "New", "Open", "Separator", "Undo", "Redo", "Separator", "Image", "Table", "Hyperlink", "Separator", "Break", "Separator", "Comments", "TrackChanges"};

}


When I run my code the canvas appears in a small size. After clicking on the button that hides the text formatting tools twice, the canvas is resized to the desired size.

Before:



After:



How can I force the resize of the canvas to avoid the small size on load.

Regards,


9 Replies

SM Suriya Murugan Syncfusion Team July 15, 2022 03:52 AM UTC

Hi Sam,


Please call resize API in created event. Please check below code snippet for reference:


<div
style="height:70%;width:50%">

        <SfDocumentEditorContainer
@ref="container"
ID="editor"
EnableToolbar="true">

            <DocumentEditorContainerEvents
Created="OnCreated"></DocumentEditorContainerEvents>

        </SfDocumentEditorContainer>

    </div>

@code {

    SfDocumentEditorContainer container;

    public void OnCreated(object args)

    {

        container.ResizeAsync();

        container.DocumentEditor.Resize();

    }



Here, you can provide the specific height and width as parameter in resize API, if you need.


Documentation link: https://blazor.syncfusion.com/documentation/document-editor/how-to/resize-document-editor


Regards,

Suriya M.





SM Sam Mendes July 15, 2022 07:02 AM UTC

Hi Suriya,


I tried the suggested solution but it didn't work for me.


The line "container.DocumentEditor.Resize();" is obsolete. So I replaced it with "container.DocumentEditor.ResizeAsync();",


The Document Editor is still displayed with a small size on load. After interacting with the component the canvas resizes.


Also, I'm randomly (1 out of 10 tries) getting some of the symbols not loaded in the editor:



Regards,




SM Suriya Murugan Syncfusion Team July 19, 2022 04:08 AM UTC

Hi Sam,


Can you please share the simplified sample which you have tried at your end? that will be helpful for us to proceed further and provide you the solution   at the earliest.


Regards,

Suriya M.



SM Sam Mendes July 21, 2022 02:09 AM UTC

Hi Suriya,

I have created a a simplified sample to reproduce this error.

I was able to pinpoint the issue to the Document Editor inside a collapsible div which is initially hidden. When the div is shown the Document Editor is displayed with a with a small size as per my screenshot.

This solution uses the collapse function using jquery and bootstrap.


Include inside <body> tag in the _Host.cshtml file:

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>

       <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-VHvPCCyXqtD5DqJeNxl2dtTyhF78xXNXdkwX1CZeRusQfRKp+tA7hAShOK/B/fQ2" crossorigin="anonymous"></script>


    <script>

        function DivVisibility(param) {

            switch(param.mode) {

              case "min":

                $('.collapse.test'+param.id).collapse('hide');

                break;


             case
"max":

                $('.collapse.test'+param.id).collapse('show');

                break;

            }

        }

    </script>


Index.razor content:

@page "/"

@using Syncfusion.Blazor.Buttons

@using Syncfusion.Blazor.DocumentEditor

@inject IJSRuntime jsRuntime


<div>

    <SfButton OnClick="@(() => ChangeVisibility(1, "min"))">Hide</SfButton>

    <SfButton OnClick="@(() => ChangeVisibility(1, "max"))">Show</SfButton>

</div>

<div class="collapse show test1">

    <div>

        My Document Editor

    </div>

    <div>

        <SfDocumentEditorContainer @ref="container" Height="600px" EnableToolbar=true ToolbarItems="@Items">

            <DocumentEditorContainerEvents>

            </DocumentEditorContainerEvents>

        </SfDocumentEditorContainer>

    </div>

</div>


@code {

    SfDocumentEditorContainer container;

    string[] Items = new string[14] { "New", "Open", "Separator", "Undo", "Redo", "Separator", "Image", "Table", "Hyperlink", "Separator", "Break", "Separator", "Comments", "TrackChanges"};


    private class Params

    {

        public int id { get; set; }

        public string mode { get; set; }

    }


    private async Task ChangeVisibility(int id, string mode)

    {

        var param = new Params() { id = id, mode = mode };

        await jsRuntime.InvokeVoidAsync("DivVisibility",param);

    }



    protected override async Task OnAfterRenderAsync(bool firstRender)

    {

       if (firstRender)

        {

            //Change mode to "max" for the Document Editor to work as expected

            await ChangeVisibility(1, "min");

        }

    }

}


Click on the button "Show" and the Document Editor will be displayed with the small canvas. If I hide the toolbar in the Document Editor the canvas resizes and is displayed as expected.

If I set the default visibility to "max" in OnAfterRenderAsync the Document Editor is rendered as expected.

I think there is an issue when the control is collapsed/hidden and then displayed using Jquery.


Regards,



SM Suriya Murugan Syncfusion Team July 21, 2022 01:44 PM UTC

Hi Sam,


Thanks for sharing details.


We will check and update details by July 22, 2022.


Regards,

Suriya M.



SM Suriya Murugan Syncfusion Team July 26, 2022 03:53 AM UTC

Hi Sam,


We are checking on it and update details by July 26, 2022, without further delay.


Regards,

Suriya M.



SM Suriya Murugan Syncfusion Team July 27, 2022 01:42 PM UTC

Hi Sam,


Please add the highlighted code in below method:


private async Task ChangeVisibility(int id, string mode)


    {



        var param = new Params() { id = id, mode = mode };


        await jsRuntime.InvokeVoidAsync("DivVisibility", param);

        container.DocumentEditor.ResizeAsync();


    }



Please let us know if you still facing issues.


Regards,

Suriya M.



SM Sam Mendes July 29, 2022 03:56 AM UTC

Hi Suriya,

Adding the following line in the ChangeVisibility method fixed this issue.

  container.DocumentEditor.ResizeAsync();

I tried before using ResizeAsync in methods OnCreated and OnInitializedAsync. Now that you showed me where it should be called it makes perfect sense.

Thank you for your help.

Regards,



SM Suriya Murugan Syncfusion Team August 1, 2022 04:37 AM UTC

Hi Sam,


Thanks for your update.


Regards,

Suriya M.


Loader.
Up arrow icon