在MudBlazor文件上传中的可关闭芯片

huangapple go评论71阅读模式
英文:

Closeable Chip on Mudblazor fileupload

问题

芯片不可点击,如果我更改MudFileUpload控件的Z-Index,它会崩溃。我还尝试将芯片的Z-Index设置为20以上,但仍然无法单击它。


你可以尝试将MudChip组件的@onclick属性设置为处理点击事件的方法,以便使芯片可点击。此外,你还需要确保MudFileUpload组件的Z-Index不会遮挡住芯片。以下是你可以尝试的更改:

<MudChip Color="Color.Dark" Text="@file" OnClose="Closed" @onclick="HandleChipClick" />

然后,在你的代码中添加一个处理点击事件的方法:

private void HandleChipClick()
{
    // 处理芯片的点击事件
}

这将使MudChip组件变为可点击。另外,请确保MudFileUpload组件的Z-Index不会遮挡住芯片,以确保它仍然可以点击。

英文:

How can I create a closeable chip on Mudblazor Fileupload Drag&Drop?
Here is an example: https://try.mudblazor.com/snippet/GYwHEQvURJEkHBcX

@inject ISnackbar Snackbar

&lt;MudStack Style=&quot;width: 100%&quot;&gt;
    &lt;MudFileUpload T=&quot;IReadOnlyList&lt;IBrowserFile&gt;&quot; OnFilesChanged=&quot;OnInputFileChanged&quot; Hidden=&quot;false&quot; Class=&quot;flex-1&quot; InputClass=&quot;absolute mud-width-full mud-height-full overflow-hidden z-20&quot; InputStyle=&quot;opacity:0&quot;
                   @ondragenter=&quot;@SetDragClass&quot; @ondragleave=&quot;@ClearDragClass&quot; @ondragend=&quot;@ClearDragClass&quot;&gt;
        &lt;ButtonTemplate&gt;
            &lt;MudPaper Height=&quot;300px&quot; Outlined=&quot;true&quot; Class=&quot;@DragClass&quot;&gt;
                &lt;MudText Typo=&quot;Typo.h6&quot;&gt;Drag and drop files here or click&lt;/MudText&gt;
                @foreach (var file in fileNames)
                {
                    &lt;MudChip Color=&quot;Color.Dark&quot; Text=&quot;@file&quot; OnClose=&quot;Closed&quot; /&gt;
                }
            &lt;/MudPaper&gt;
        &lt;/ButtonTemplate&gt;
    &lt;/MudFileUpload&gt;
    &lt;MudToolBar DisableGutters=&quot;true&quot; Class=&quot;gap-4&quot;&gt;
        &lt;MudButton OnClick=&quot;Upload&quot; Disabled=&quot;@(!fileNames.Any())&quot; Color=&quot;Color.Primary&quot; Variant=&quot;Variant.Filled&quot;&gt;Upload&lt;/MudButton&gt;
        &lt;MudButton OnClick=&quot;Clear&quot; Disabled=&quot;@(!fileNames.Any())&quot; Color=&quot;Color.Error&quot; Variant=&quot;Variant.Filled&quot;&gt;Clear&lt;/MudButton&gt;
    &lt;/MudToolBar&gt;
&lt;/MudStack&gt;
@code {
    private static string DefaultDragClass = &quot;relative rounded-lg border-2 border-dashed pa-4 mt-4 mud-width-full mud-height-full z-10&quot;;
    private string DragClass = DefaultDragClass;
    private List&lt;string&gt; fileNames = new List&lt;string&gt;();

    private void OnInputFileChanged(InputFileChangeEventArgs e)
    {
        ClearDragClass();
        var files = e.GetMultipleFiles();
        foreach (var file in files)
        {
            fileNames.Add(file.Name);
        }
    }

    void Closed(MudChip chip) {
        fileNames.Remove(chip.Text);
    }

    private async Task Clear()
    {
        fileNames.Clear();
        ClearDragClass();
        await Task.Delay(100);
    }
    private void Upload()
    {
        //Upload the files here
        Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
        Snackbar.Add(&quot;TODO: Upload your files!&quot;, Severity.Normal);
    }

    private void SetDragClass()
    {
        DragClass = $&quot;{DefaultDragClass} mud-border-primary&quot;;
    }

    private void ClearDragClass()
    {
        DragClass = DefaultDragClass;
    }
}

The chip is not clickable and if I change the Z-Index of the MudFileUpload control it collapses. I also tried to add Z-Index above 20 to the chip but I still cannot click it.

答案1

得分: 1

X 按钮不可点击,您必须将 "MudChip" 放在 MudFileUpload 标记外部,像这样:

&lt;MudStack Style=&quot;width: 100%&quot;&gt;
    &lt;MudFileUpload T=&quot;IReadOnlyList&lt;IBrowserFile&gt;&quot; OnFilesChanged=&quot;OnInputFileChanged&quot; Hidden=&quot;false&quot; Class=&quot;flex-1&quot; InputClass=&quot;absolute mud-width-full mud-height-full overflow-hidden z-20&quot; InputStyle=&quot;opacity:0&quot;
                   @ondragenter=&quot;@SetDragClass&quot; @ondragleave=&quot;@ClearDragClass&quot; @ondragend=&quot;@ClearDragClass&quot;&gt;
        &lt;ButtonTemplate&gt;
            &lt;MudPaper Height=&quot;300px&quot; Outlined=&quot;true&quot; Class=&quot;@DragClass&quot;&gt;
                &lt;MudText Typo=&quot;Typo.h6&quot;&gt;拖放文件到此处或点击&lt;/MudText&gt;
            &lt;/MudPaper&gt;
        &lt;/ButtonTemplate&gt;
    &lt;/MudFileUpload&gt;
    @foreach (var file in fileNames)
    {
        &lt;MudChip Color=&quot;Color.Dark&quot; Text=&quot;@file&quot; OnClose=&quot;Closed&quot; /&gt;
    }
    &lt;MudToolBar DisableGutters=&quot;true&quot; Class=&quot;gap-4&quot;&gt;
        &lt;MudButton OnClick=&quot;Upload&quot; Disabled=&quot;@(!fileNames.Any())&quot; Color=&quot;Color.Primary&quot; Variant=&quot;Variant.Filled&quot;&gt;上传&lt;/MudButton&gt;
        &lt;MudButton OnClick=&quot;Clear&quot; Disabled=&quot;@(!fileNames.Any())&quot; Color=&quot;Color.Error&quot; Variant=&quot;Variant.Filled&quot;&gt;清除&lt;/MudButton&gt;
    &lt;/MudToolBar&gt;
&lt;/MudStack&gt;
英文:

The X button is not clickable, you have to put The "MudChip" outside the MudFileUpload tag like this :


&lt;MudStack Style=&quot;width: 100%&quot;&gt;
    &lt;MudFileUpload T=&quot;IReadOnlyList&lt;IBrowserFile&gt;&quot; OnFilesChanged=&quot;OnInputFileChanged&quot; Hidden=&quot;false&quot; Class=&quot;flex-1&quot; InputClass=&quot;absolute mud-width-full mud-height-full overflow-hidden z-20&quot; InputStyle=&quot;opacity:0&quot;
                   @ondragenter=&quot;@SetDragClass&quot; @ondragleave=&quot;@ClearDragClass&quot; @ondragend=&quot;@ClearDragClass&quot;&gt;
        &lt;ButtonTemplate&gt;
            &lt;MudPaper Height=&quot;300px&quot; Outlined=&quot;true&quot; Class=&quot;@DragClass&quot;&gt;
                &lt;MudText Typo=&quot;Typo.h6&quot;&gt;Drag and drop files here or click&lt;/MudText&gt;
            &lt;/MudPaper&gt;
        &lt;/ButtonTemplate&gt;
    &lt;/MudFileUpload&gt;
    @foreach (var file in fileNames)
    {
        &lt;MudChip Color=&quot;Color.Dark&quot; Text=&quot;@file&quot; OnClose=&quot;Closed&quot; /&gt;
    }
    &lt;MudToolBar DisableGutters=&quot;true&quot; Class=&quot;gap-4&quot;&gt;
        &lt;MudButton OnClick=&quot;Upload&quot; Disabled=&quot;@(!fileNames.Any())&quot; Color=&quot;Color.Primary&quot; Variant=&quot;Variant.Filled&quot;&gt;Upload&lt;/MudButton&gt;
        &lt;MudButton OnClick=&quot;Clear&quot; Disabled=&quot;@(!fileNames.Any())&quot; Color=&quot;Color.Error&quot; Variant=&quot;Variant.Filled&quot;&gt;Clear&lt;/MudButton&gt;
    &lt;/MudToolBar&gt;
&lt;/MudStack&gt;

huangapple
  • 本文由 发表于 2023年2月16日 17:46:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470446.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定