Completed
Last Updated: 08 Nov 2023 14:39 by David
Release 4.1.0 (15/03/2023)
Matt
Created on: 17 Jul 2021 10:27
Category: Window
Type: Feature Request
11
Modal Window should trap the Tab keys so you cannot focus content "behind" the window
The modal shouldn't prevent tabbing into the browser controls. But the problem is, when using the modal, you can tab to controls and HTML elements behind the modal on the page. You shouldn't be able to interact with these in this way, and in fact mouse clicks are blocked.

This is an accessibility requirement - the behavior should work as expected for mouse users and keyboard users.
9 comments
David
Posted on: 08 Nov 2023 14:39

Hello Dimo,

 

That is good to know for future reference, if I find myself in the same situation again. The reason I have omitted the DialogButtons is because I needed to use FormButtons inside of the Dialog, which didn't appear usable from the DialogButtons Tag.

 

Cheers!

David Lamonaca.

ADMIN
Dimo
Posted on: 07 Nov 2023 20:51

Hi David,

The Dialog expects to have action buttons at the bottom and their lack is causing the undesired behavior.

The Dialog action buttons represent the main feature of the Dialog, which distinguishes it from the Window. If you don't need them, you might as well switch to a modal non-resizable non-draggable Window.

Regards,
Dimo
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
David
Posted on: 07 Nov 2023 19:24

Hello Dimo,

 

That scenario is very similar. However, I am using a TelerikDialog instead of a TelerikWindow.

 

Cheers!

David Lamonaca.

ADMIN
Dimo
Posted on: 02 Nov 2023 15:26

Hi David,

Is this your scenario - Grid popup editing with a custom modal Window opened from the popup edit form

I can't tab outside the second modal, no matter how many times I open it.

Regards,
Dimo
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
David
Posted on: 01 Nov 2023 16:58

Greetings Dimo,

I see from the most recent comment that a planned released to fix this was set for early March.

"Yes, we aim to include this behavior in the next release 4.1. in early March."

 

I am unsure if this change had made it through to that release or not. However, I am experience the same issue other have been facing. a key difference being that the content behind the modal is only accessible on the second open of the modal. 

I am using a TelerikGrid which opens a TelerikForm and inside that form I have a button that opens a modal. If the user opens the modal inside the form the first time, everything works as attended, but if they close the modal and open it again they are able to tab out of the modal and into the TelerikForm. 

 

As can be seen in the provided image, my modal has ended up behind the TelerikForm.

Cheers!

David Lamonaca.

ADMIN
Dimo
Posted on: 01 Feb 2023 11:23

Hi Alexander and everyone,

Yes, we aim to include this behavior in the next release 4.1. in early March.

Regards,
Dimo
Progress Telerik

Learn about the important changes coming in UI for Blazor 4.0 in January 2023!
Alexander
Posted on: 01 Feb 2023 09:10
Any progress on this? We also noticed this a few days ago. Do you have an estimate on when you'll be able to properly implement modal windows?
ADMIN
Dimo
Posted on: 07 Feb 2022 13:49

Hello all,

While we implement this feature, consider the following workaround. It uses JavaScript to prevent focus behind the modal Window. It can rely on a specific parent container or work with all elements outside a Window.

@inject IJSRuntime js

<div id="container">
    <TelerikButton OnClick="@ShowWindow">Show Window</TelerikButton>

    <p>some focusable elements here:</p>
    <div contenteditable="true" tabindex="1">custom focusable element</div>
    <p><input /></p>
    <p><a href="#">link</a></p>
</div>

<TelerikWindow Visible="@WindowVisible"
               VisibleChanged="@WindowVisibleChanged"
               Centered="true"
               Modal="true">
    <WindowActions>
        <WindowAction Name="Close" />
    </WindowActions>
    <WindowTitle>
        Window title
    </WindowTitle>
    <WindowContent>
        <p>Focus outside the Window is now disabled.</p>
        <p>If you want to experiment while the Window is open:</p>
        <TelerikButton OnClick="@PreventFocus">Prevent Focus</TelerikButton>
        <TelerikButton OnClick="@RestoreFocus">Restore Focus</TelerikButton>
    </WindowContent>
</TelerikWindow>

@* Move this script to a proper location in a production app *@
<script suppress-error="BL9992">function preventFocus(containerSelector) {
    processTabindex(containerSelector, "tabindex", "back_tabindex");
}
function restoreFocus(containerSelector) {
    processTabindex(containerSelector, "back_tabindex", "tabindex");
}
function processTabindex(containerSelector, attr, backAttr) {
    // workaround for a specific container
    //var container = document.querySelector(containerSelector);
    //var elements = container.querySelectorAll("input, textarea, a, button, [tabindex]");

    // OR
    // workaround for all elements outside a Window
    var elements = document.querySelectorAll(":not(.k-window) input, :not(.k-window) textarea, :not(.k-window) a, :not(.k-window) button, :not(.k-window) [tabindex]");
    
    elements.forEach(el => {

        if (attr == "back_tabindex") {
            // restoring saved tabindex, we remove tabindex -1
            el.removeAttribute("tabindex");
        }

        var tabindex = el.getAttribute(attr);

        if (tabindex != null) {
            el.setAttribute(backAttr, tabindex);
        }

        if (attr == "tabindex") {
            // preventing focus, we set tabindex -1 to everything
            el.setAttribute(attr, "-1");
        } else {
            // restoring saved tabindex, we remove the temporary attribute
            el.removeAttribute(attr);
        }
    });
}</script>

@code {
    bool WindowVisible { get; set; }

    async Task ShowWindow()
    {
        WindowVisible = true;
        await PreventFocus();
    }

    async Task WindowVisibleChanged(bool newVisible)
    {
        WindowVisible = newVisible;

        if (WindowVisible)
        {
            await PreventFocus();
        }
        else
        {
            await RestoreFocus();
        }
    }

    async Task PreventFocus()
    {
        await js.InvokeVoidAsync("preventFocus", "#container");
    }

    async Task RestoreFocus()
    {
        await js.InvokeVoidAsync("restoreFocus", "#container");
    }
}

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Alex
Posted on: 31 Jan 2022 17:54
Having the same problem here.

Items behind the window are accesible by keyboard.