简体   繁体   English

在屏幕阅读器上工作的空闲超时警告模式

[英]Idle timeout warning modal working on screen reader

I need help with a modal that fires when user is idle. 我需要帮助一个在用户空闲时触发的模态。 It works great until I test on Firefox with NVDA running. 它运行良好,直到我在运行NVDA的Firefox上进行测试。 There are issues with focus when using the arrow keys and when I swipe on a mobile. 使用箭头键时以及在移动设备上滑动时会出现焦点问题。 When the modal appears and the user uses arrow or swipes the focus will bounce from the yes button to the header after a few seconds if I wait to click it. 当模态出现并且用户使用箭头或滑动时,如果我等待点击它,焦点将在几秒后从“是”按钮反弹到标题。 I have loaded the working example to: https://jsfiddle.net/ncanqaam/ 我已将工作示例加载到: https//jsfiddle.net/ncanqaam/

I changed the idle time period to one minute and removed a portion which calls the server to extend the user's session. 我将空闲时间段更改为一分钟,并删除了调用服务器以扩展用户会话的部分。

var state ="L";
var timeoutPeriod = 540000;
var oneMinute = 60000;
var sevenMinutes = 60000;

var lastActivity = new Date();

function getIdleTime() {
    return new Date().getTime() - lastActivity.getTime();
}

//Add Movement Detection
function addMovementListener() {
    $(document).on('mousemove',  onMovementHandler);
    $(document).on('keypress',  onMovementHandler);
    $(document).on('touchstart touchend',  onMovementHandler);
}
//Remove Movement Detection
function removeMovementListener() {
    $(document).off('mousemove', onMovementHandler);
    $(document).off('keypress',  onMovementHandler);
    $(document).off('touchstart touchend',  onMovementHandler);
}

//Create Movement Handler
function onMovementHandler(ev) {
    lastActivity = new Date();
    console.log("Something moved, idle time = " + lastActivity.getTime());
}

function hide() {
    $('#overlayTY').removeClass('opened'); // remove the overlay in order to  make the main screen available again
    $('#overlayTY, #modal-session-timeout').css('display', 'none'); // hide the modal window
    $('#modal-session-timeout').attr('aria-hidden', 'true'); // mark the modal window as hidden
    $('#modal-session-timeout').removeAttr('aria-hidden'); // mark the main page as visible
}

if (state == "L") {
    $(document).ready(function() {
        //Call Event Listerner to for movement detection
        addMovementListener();
        setInterval(checkIdleTime, 5000);
    });

    function endSession() {
        console.log('Goodbye!');
    }

    var modalActive = false;
    function checkIdleTime() {
        var idleTime = getIdleTime();
        console.log("The total idle time is " + idleTime / oneMinute + " minutes.");

        if (idleTime > sevenMinutes) {
            var prevFocus = $(document.activeElement);
            console.log('previously: ' + prevFocus);
            var modal = new window.AccessibleModal({
                mainPage: $('#oc-container'),
                overlay: $('#overlayTY').css('display', 'block'),
                modal: $('#modal-session-timeout')
            });

            if (modalActive === false) {
                console.log(modalActive);
                $('#modal-session-timeout').insertBefore('#oc-container');
                $('#overlayTY').insertBefore('#modal-session-timeout');
                modal.show();
                $('#modal-overlay').removeClass('opened');
                modalActive = true;
                console.log(modalActive);
                console.log('the modal is active');
                $('.js-timeout-refresh').on('click touchstart touchend', function(){
                    hide();
                    modalActive = false;
                    prevFocus.focus();
                    addMovementListener();
                    lastActivity = new Date();
                });

                $('.js-timeout-session-end').on('click touchstart touchend', function(){
                    hide();
                    $('#overlayTY').css('display', 'none');
                    endSession();
                });
            }   
        }
        if ($('#overlayTY').css('display') === 'block'){
            removeMovementListener();
        }

        if (idleTime > timeoutPeriod) {
            endSession();
        }
    }
}

Possibles solutions 可能的解决方案

  1. Disable pointer-events on body when overlay is visible. 当叠加可见时,禁用正文上的指针事件。 this will restrict keyboard/swipe events on body elements 这将限制body元素上的键盘/滑动事件
  2. Use JS/jQuery to trigger focus on the yes button 使用JS / jQuery触发焦点在yes按钮上

The issue is with Voiceover Safari when a user swipes on an anchor or button the focus is set on these elements; 当用户在锚点或按钮上滑动时,问题在于Voiceover Safari,焦点设置在这些元素上; however, if the element is an H2 it will not receive focus because natively it is not supposed to receive any. 但是,如果元素是H2,它将不会获得焦点,因为本身它不应该接收任何焦点。 To compensate I attempted to set gesture events on the H2 but, Voiceover Safari needs time to read the element text or label out load, so it prevents any event from firing and this creates a problem when trying to set focus on a modal which loads from a timeout function rather than a clickable element. 为了补偿我试图在H2上设置手势事件但是,Voiceover Safari需要时间来读取元素文本或标记输出加载,因此它可以防止任何事件被触发,这会在尝试将焦点设置为从加载的模态时产生问题超时功能而不是可点击元素。 Hopefully Apple will address this in the future. 希望Apple将来能够解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM