Skip to content
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

After a cascading value changes, MudMarkDown is failing to update the corresponding value. #166

Closed
cristianalemanGit opened this issue May 11, 2023 · 3 comments
Labels
question Further information is requested

Comments

@cristianalemanGit
Copy link

cristianalemanGit commented May 11, 2023

Hello, Is there a way to trigger a re-render of the MudMarkdown component when a cascading value is updated?

@MihailsKuzmins
Copy link
Member

Could you please provide a code block (or a sample solution) of what you want to achieve and what does not work with the current version?

To force re-rendering you might try to call StateHasChanged() on your component when the cascading value is updated.

@MihailsKuzmins MihailsKuzmins added the question Further information is requested label May 11, 2023
@cristianalemanGit
Copy link
Author

I attempted to use StateHasChanged() but unfortunately, it did not refresh the MudMarkdown component. However, If
the _htmlValue is placed on a MudText component, the value was successfully updated."

Here is a sample of my backEnd:

   [CascadingParameter]
   public Html Html { get; set; }

   private string _htmlValue;

   protected override void OnParametersSet()
   {
      
       _htmlValue = "```html\n" + Html + "\n```";
       
       StateHasChanged();
   }

And here is my frontEnd:

<MudCard>
    <MudCardHeader>
        <CardHeaderContent>
            <MudText Typo="Typo.body1">HTML Preview</MudText>
        </CardHeaderContent>
    </MudCardHeader>
    <MudCardContent>
        <MudMarkdown CodeBlockTheme="CodeBlockTheme.Default"
                     Value="@_htmlValue" />

        <MudText>@_htmlValue</MudText>
    </MudCardContent>
</MudCard>

@MihailsKuzmins MihailsKuzmins added bug Something isn't working and removed question Further information is requested labels May 16, 2023
@MihailsKuzmins
Copy link
Member

MihailsKuzmins commented May 26, 2023

Sorry for a late reply. Could you post a complete solutiuon with your expected behaviour (github repo will do)? Otherwise I do not really understand what you are trying to accomplish.
Calling "StateHashChanged" does refresh the component

<MudButton OnClick="OnClick">Refresh</MudButton>

<MudMarkdown
	Value="@Value"
	Styling="Styling"
	TableCellMinWidth="100"
	OverrideLinkUrl="OverrideLink"
	OverrideHeaderTypo="OverrideHeaderTypo" 
	CodeBlockTheme="CodeBlockTheme.DraculaBase16" />

@code
{
	void OnClick()
	{
		Value += Environment.NewLine + Value;
		StateHasChanged();
	}

	protected override async Task OnInitializedAsync()
	{
		Value = "**aaa** bbb _aaa_";
	}
}

refresh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants