Prevent closing Dialog on enter key when there is primary button in dialog buttons template

If SfDialog has DialogButton with  parameter IsPrimary="true"  when  user hit enter in any control dialog close itself.
Is there a way to prevent this behaviour.
Easiest way is to set IsPrimary to false but , this break visually convention of other dialogs.


My app is webassembly and Syncfusin blazor componentes are on ver 18.3.0.48


1 Reply 1 reply marked as answer

IS Indrajith Srinivasan Syncfusion Team November 16, 2020 07:51 AM UTC

Hi Admir, 
 
Greetings from Syncfusion support, 
 
We have validated your reported query. Focusing of the primary button in the SfDialog is the default behavior, unless the SfDialog doesn’t have any focusable elements inside it. In order to prevent the enter key action, we suggest you to disable the SfDialog focusing in the Opened event. Check the below code blocks for reference. 
 
 
@using Syncfusion.Blazor.Popups 
@using Syncfusion.Blazor.Buttons 
 
<SfButton @onclick="@OpenDialog">Open Dialog</SfButton> 
 
<SfDialog Width="250px" ShowCloseIcon="true" IsModal="true" @bind-Visible="@IsVisible"> 
    <DialogEvents Opened="@onOpen"></DialogEvents> 
    <DialogTemplates> 
        <Header> Dialog </Header> 
        <Content> This is a Dialog with button and primary button </Content> 
    </DialogTemplates> 
    <DialogButtons> 
        <DialogButton Content="OK" IsPrimary="true" OnClick="@CloseDialog" /> 
        <DialogButton Content="Cancel" OnClick="@CloseDialog" /> 
    </DialogButtons> 
</SfDialog> 
 
@code { 
    private bool IsVisible { get; set; } = true; 
 
    private void OpenDialog() 
    { 
        this.IsVisible = true; 
    } 
 
    private void CloseDialog() 
    { 
        this.IsVisible = false; 
    } 
    public void onOpen(OpenEventArgs args) 
    { 
        args.PreventFocus = true; 
    } 
} 
 
 
Please let us know if the solution helps, 
 
Regards, 
Indrajith 


Marked as answer
Loader.
Up arrow icon