MDL-70792 aria: Dropdown menu keyboard interaction fixes
[moodle.git] / theme / boost / amd / build / aria.min.js.map
blob963132acbcad7dbc2dc4a3e8eff7eca080bc64aa
1 {"version":3,"sources":["../src/aria.js"],"names":["dropdownFix","focusEnd","focusBackToTrigger","setFocusEnd","end","getFocusEnd","result","shiftFocus","element","setTimeout","delayedFocus","pendingPromise","focus","resolve","Pending","handleMenuButton","e","trigger","key","fixFocus","preventDefault","target","click","menu","parentElement","querySelector","menuItems","foundMenuItem","querySelectorAll","length","document","addEventListener","matches","closest","toLowerCase","i","item","itemText","text","trim","indexOf","next","on","autoFocus","window","alerts","Array","prototype","forEach","call","autofocusElement","innerHTML","removeAttribute","updateTabFocus","tabList","vertical","getAttribute","rtl","right_to_left","arrowNext","arrowPrevious","tabs","filter","tab","getComputedStyle","display","index","tabIndex","tabElementFix","includes","init"],"mappings":"2JAuBA,OACA,O,sDAKMA,CAAAA,CAAW,CAAG,UAAM,IAClBC,CAAAA,CAAQ,GADU,CAElBC,CAAkB,GAFA,CAGhBC,CAAW,CAAG,UAAgB,IAAfC,CAAAA,CAAe,2DAChCH,CAAQ,CAAGG,CACd,CALqB,CAMhBC,CAAW,CAAG,UAAM,CACtB,GAAMC,CAAAA,CAAM,CAAGL,CAAf,CACAA,CAAQ,GAAR,CACA,MAAOK,CAAAA,CACV,CAVqB,CAahBC,CAAU,CAAG,SAAAC,CAAO,CAAI,CAK1BC,UAAU,CAJW,QAAfC,CAAAA,YAAe,CAAAC,CAAc,CAAI,CACnCH,CAAO,CAACI,KAAR,GACAD,CAAc,CAACE,OAAf,EACH,CACS,CAAe,EAAf,CAAmB,GAAIC,UAAJ,CAAY,yBAAZ,CAAnB,CACb,CAnBqB,CAsBhBC,CAAgB,CAAG,SAAAC,CAAC,CAAI,IACpBC,CAAAA,CAAO,CAAGD,CAAC,CAACE,GADQ,CAEtBC,CAAQ,GAFc,CAK1B,GAAgB,GAAZ,GAAAF,CAAO,EAAwB,OAAZ,GAAAA,CAAvB,C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T,CAAoB,CAApB,CAhCR,CAkCH,C,CAKKC,CAAa,CAAG,UAAM,CACxBtC,QAAQ,CAACC,gBAAT,CAA0B,SAA1B,CAAqC,SAAAf,CAAC,CAAI,CACtC,GAAI,CAAC,SAAD,CAAY,WAAZ,CAAyB,WAAzB,CAAsC,YAAtC,CAAoD,MAApD,CAA4D,KAA5D,CAAmE,OAAnE,CAA4E,GAA5E,EAAiFqD,QAAjF,CAA0FrD,CAAC,CAACE,GAA5F,CAAJ,CAAsG,CAClG,GAAIF,CAAC,CAACK,MAAF,CAASW,OAAT,CAAiB,mCAAjB,CAAJ,CAAuD,CACnDqB,CAAc,CAACrC,CAAD,CACjB,CACJ,CACJ,CAND,EAQAc,QAAQ,CAACC,gBAAT,CAA0B,OAA1B,CAAmC,SAAAf,CAAC,CAAI,CACpC,GAAIA,CAAC,CAACK,MAAF,CAASW,OAAT,CAAiB,mCAAjB,CAAJ,CAAuD,CACnD,GAAM6B,CAAAA,CAAI,CAAG7C,CAAC,CAACK,MAAF,CAASY,OAAT,CAAiB,oBAAjB,EAAqCL,gBAArC,CAAsD,gBAAtD,CAAb,CACAZ,CAAC,CAACI,cAAF,GACA,cAAEJ,CAAC,CAACK,MAAJ,EAAY0C,GAAZ,CAAgB,MAAhB,EACAF,CAAI,CAACb,OAAL,CAAa,SAAAe,CAAG,CAAI,CAChBA,CAAG,CAACI,QAAJ,CAAe,CAAC,CACnB,CAFD,EAGAnD,CAAC,CAACK,MAAF,CAAS8C,QAAT,CAAoB,CACvB,CACJ,CAVD,CAWH,C,QAEmB,QAAPG,CAAAA,IAAO,EAAM,CACtBtE,CAAW,GACX2C,CAAS,GACTyB,CAAa,EAChB,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Enhancements to Bootstrap components for accessibility.\n *\n * @module     theme_boost/aria\n * @copyright  2018 Damyon Wiese <damyon@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\nimport Pending from 'core/pending';\n\n/**\n * Drop downs from bootstrap don't support keyboard accessibility by default.\n */\nconst dropdownFix = () => {\n    let focusEnd = false;\n    let focusBackToTrigger = true;\n    const setFocusEnd = (end = true) => {\n        focusEnd = end;\n    };\n    const getFocusEnd = () => {\n        const result = focusEnd;\n        focusEnd = false;\n        return result;\n    };\n\n    // Special handling for navigation keys when menu is open.\n    const shiftFocus = element => {\n        const delayedFocus = pendingPromise => {\n            element.focus();\n            pendingPromise.resolve();\n        };\n        setTimeout(delayedFocus, 50, new Pending('core/aria:delayed-focus'));\n    };\n\n    // Event handling for the dropdown menu button.\n    const handleMenuButton = e => {\n        const trigger = e.key;\n        let fixFocus = false;\n\n        // Space key or Enter key opens the menu.\n        if (trigger === ' ' || trigger === 'Enter') {\n            fixFocus = true;\n            // Cancel random scroll.\n            e.preventDefault();\n            // Open the menu instead.\n            e.target.click();\n        }\n\n        // Up and Down keys also open the menu.\n        if (trigger === 'ArrowUp' || trigger === 'ArrowDown') {\n            fixFocus = true;\n        }\n\n        // Pressing tab on the menu button should focus on the next element in the DOM and not back to the menu trigger.\n        if (trigger === 'Tab') {\n            focusBackToTrigger = false;\n        }\n\n        if (!fixFocus) {\n            // No need to fix the focus. Return early.\n            return;\n        }\n\n        // Fix the focus on the menu items when the menu is opened.\n        const menu = e.target.parentElement.querySelector('[role=\"menu\"]');\n        let menuItems = false;\n        let foundMenuItem = false;\n\n        if (menu) {\n            menuItems = menu.querySelectorAll('[role=\"menuitem\"]');\n        }\n        if (menuItems && menuItems.length > 0) {\n            // Up key opens the menu at the end.\n            if (trigger === 'ArrowUp') {\n                setFocusEnd();\n            } else {\n                setFocusEnd(false);\n            }\n\n            if (getFocusEnd()) {\n                foundMenuItem = menuItems[menuItems.length - 1];\n            } else {\n                // The first menu entry, pretty reasonable.\n                foundMenuItem = menuItems[0];\n            }\n        }\n\n        if (foundMenuItem) {\n            shiftFocus(foundMenuItem);\n        }\n    };\n\n    // Search for menu items by finding the first item that has\n    // text starting with the typed character (case insensitive).\n    document.addEventListener('keypress', e => {\n        if (e.target.matches('.dropdown [role=\"menu\"] [role=\"menuitem\"]')) {\n            const menu = e.target.closest('[role=\"menu\"]');\n            if (!menu) {\n                return;\n            }\n            const menuItems = menu.querySelectorAll('[role=\"menuitem\"]');\n            if (!menuItems) {\n                return;\n            }\n\n            const trigger = e.key.toLowerCase();\n\n            for (let i = 0; i < menuItems.length; i++) {\n                const item = menuItems[i];\n                const itemText = item.text.trim().toLowerCase();\n                if (itemText.indexOf(trigger) == 0) {\n                    shiftFocus(item);\n                    break;\n                }\n            }\n        }\n    });\n\n    // Keyboard navigation for arrow keys, home and end keys.\n    document.addEventListener('keydown', e => {\n\n        // We only want to set focus when users access the dropdown via keyboard as per\n        // guidelines defined in w3 aria practices 1.1 menu-button.\n        if (e.target.matches('[data-toggle=\"dropdown\"]')) {\n            handleMenuButton(e);\n        }\n\n        if (e.target.matches('.dropdown [role=\"menu\"] [role=\"menuitem\"]')) {\n            const trigger = e.key;\n            let next = false;\n            const menu = e.target.closest('[role=\"menu\"]');\n\n            if (!menu) {\n                return;\n            }\n            const menuItems = menu.querySelectorAll('[role=\"menuitem\"]');\n            if (!menuItems) {\n                return;\n            }\n            // Down key.\n            if (trigger == 'ArrowDown') {\n                for (let i = 0; i < menuItems.length - 1; i++) {\n                    if (menuItems[i] == e.target) {\n                        next = menuItems[i + 1];\n                        break;\n                    }\n                }\n                if (!next) {\n                    // Wrap to first item.\n                    next = menuItems[0];\n                }\n\n            } else if (trigger == 'ArrowUp') {\n                // Up key.\n                for (let i = 1; i < menuItems.length; i++) {\n                    if (menuItems[i] == e.target) {\n                        next = menuItems[i - 1];\n                        break;\n                    }\n                }\n                if (!next) {\n                    // Wrap to last item.\n                    next = menuItems[menuItems.length - 1];\n                }\n\n            } else if (trigger == 'Home') {\n                // Home key.\n                next = menuItems[0];\n\n            } else if (trigger == 'End') {\n                // End key.\n                next = menuItems[menuItems.length - 1];\n            } else if (trigger == 'Tab') {\n                // Pressing tab in the menu should focus on the next element in the DOM and not back to the menu trigger.\n                focusBackToTrigger = false;\n            }\n\n            // Variable next is set if we do want to act on the keypress.\n            if (next) {\n                e.preventDefault();\n                shiftFocus(next);\n            }\n            return;\n        }\n    });\n\n    $('.dropdown').on('hidden.bs.dropdown', e => {\n        // We need to focus on the menu trigger.\n        const trigger = e.target.querySelector('[data-toggle=\"dropdown\"]');\n        if (trigger && focusBackToTrigger) {\n            shiftFocus(trigger);\n        }\n        // Reset flag to focus back to the menu trigger.\n        focusBackToTrigger = true;\n    });\n};\n\n/**\n * After page load, focus on any element with special autofocus attribute.\n */\nconst autoFocus = () => {\n    window.addEventListener(\"load\", () => {\n        const alerts = document.querySelectorAll('[data-aria-autofocus=\"true\"][role=\"alert\"]');\n        Array.prototype.forEach.call(alerts, autofocusElement => {\n            // According to the specification an role=\"alert\" region is only read out on change to the content\n            // of that region.\n            autofocusElement.innerHTML += ' ';\n            autofocusElement.removeAttribute('data-aria-autofocus');\n        });\n    });\n};\n\n/**\n * Changes the focus to the correct tab based on the key that is pressed.\n * @param {KeyboardEvent} e\n */\nconst updateTabFocus = e => {\n    const tabList = e.target.closest('[role=\"tablist\"]');\n    const vertical = tabList.getAttribute('aria-orientation') == 'vertical';\n    const rtl = window.right_to_left();\n    const arrowNext = vertical ? 'ArrowDown' : (rtl ? 'ArrowLeft' : 'ArrowRight');\n    const arrowPrevious = vertical ? 'ArrowUp' : (rtl ? 'ArrowRight' : 'ArrowLeft');\n    const tabs = Array.prototype.filter.call(\n        tabList.querySelectorAll('[role=\"tab\"]'),\n        tab => getComputedStyle(tab).display !== 'none'); // We only work with the visible tabs.\n\n    for (let i = 0; i < tabs.length; i++) {\n        tabs[i].index = i;\n    }\n\n    switch (e.key) {\n        case arrowNext:\n            e.preventDefault();\n            if (e.target.index !== undefined && tabs[e.target.index + 1]) {\n                tabs[e.target.index + 1].focus();\n            } else {\n                tabs[0].focus();\n            }\n            break;\n        case arrowPrevious:\n            e.preventDefault();\n            if (e.target.index !== undefined && tabs[e.target.index - 1]) {\n                tabs[e.target.index - 1].focus();\n            } else {\n                tabs[tabs.length - 1].focus();\n            }\n            break;\n        case 'Home':\n            e.preventDefault();\n            tabs[0].focus();\n            break;\n        case 'End':\n            e.preventDefault();\n            tabs[tabs.length - 1].focus();\n            break;\n        case 'Enter':\n        case ' ':\n            e.preventDefault();\n            $(e.target).tab('show');\n            tabs.forEach(tab => {\n                tab.tabIndex = -1;\n            });\n            e.target.tabIndex = 0;\n    }\n};\n\n/**\n * Fix accessibility issues regarding tab elements focus and their tab order in Bootstrap navs.\n */\nconst tabElementFix = () => {\n    document.addEventListener('keydown', e => {\n        if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'Enter', ' '].includes(e.key)) {\n            if (e.target.matches('[role=\"tablist\"] [role=\"tab\"]')) {\n                updateTabFocus(e);\n            }\n        }\n    });\n\n    document.addEventListener('click', e => {\n        if (e.target.matches('[role=\"tablist\"] [role=\"tab\"]')) {\n            const tabs = e.target.closest('[role=\"tablist\"]').querySelectorAll('[role=\"tab\"]');\n            e.preventDefault();\n            $(e.target).tab('show');\n            tabs.forEach(tab => {\n                tab.tabIndex = -1;\n            });\n            e.target.tabIndex = 0;\n        }\n    });\n};\n\nexport const init = () => {\n    dropdownFix();\n    autoFocus();\n    tabElementFix();\n};\n"],"file":"aria.min.js"}