Completed
Last Updated: 24 Aug 2022 10:46 by ADMIN
Release 3.6.0 (14 Sep 2022) (R3 2022)
Bernard
Created on: 07 Jan 2022 11:58
Category: Upload
Type: Feature Request
2
Expose Id Attribute for the Upload
Please implement an Id attribute for the Upload component. This will allows us to associate <label> tags to it and pass accessibility checks.
1 comment
ADMIN
Dimo
Posted on: 07 Jan 2022 12:01

Hello Bernard,

Indeed, an ID is important for the described scenario. Here is how to add it with JavaScript until we implement the built-in attribute.

@inject IJSRuntime js

<p><label for="foo-id">Label for Blazor Upload</label></p>

<TelerikUpload Class="foo-id"
               @ref="@MyUpload"
               Multiple="false">
</TelerikUpload>

<!-- Allow the <script> tag to reside here in the Razor file for this workaround -->
<script suppress-error="BL9992">function addUploadId(uploadClass) {
    var uploadInput = document.querySelector("." + uploadClass + " input");
    if (uploadInput) {
        uploadInput.setAttribute("id", uploadClass);
    }
}</script>

@code {
    TelerikUpload MyUpload { get; set; }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await js.InvokeVoidAsync("addUploadId", MyUpload.Class);
        }
        await base.OnAfterRenderAsync(firstRender);
    }
}

Regards,
Dimo
Progress Telerik

Learn about the important changes coming in UI for Blazor 3.0 in January 2022!