Sha256: eee946b0f2dedd86cbe94e4c7b77b455a17d82a8c632eb7991f2d96a5c9a3ce1
Contents?: true
Size: 1.59 KB
Versions: 116
Compression:
Stored size: 1.59 KB
Contents
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define('GOVUKFrontend', factory) : (global.GOVUKFrontend = factory()); }(this, (function () { 'use strict'; function NotificationBanner ($module) { this.$module = $module; } /** * Initialise the component */ NotificationBanner.prototype.init = function () { var $module = this.$module; // Check for module if (!$module) { return } this.setFocus(); }; /** * Focus the element * * If `role="alert"` is set, focus the element to help some assistive technologies * prioritise announcing it. * * You can turn off the auto-focus functionality by setting `data-disable-auto-focus="true"` in the * component HTML. You might wish to do this based on user research findings, or to avoid a clash * with another element which should be focused when the page loads. */ NotificationBanner.prototype.setFocus = function () { var $module = this.$module; if ($module.getAttribute('data-disable-auto-focus') === 'true') { return } if ($module.getAttribute('role') !== 'alert') { return } // Set tabindex to -1 to make the element focusable with JavaScript. // Remove the tabindex on blur as the component doesn't need to be focusable after the page has // loaded. if (!$module.getAttribute('tabindex')) { $module.setAttribute('tabindex', '-1'); $module.addEventListener('blur', function () { $module.removeAttribute('tabindex'); }); } $module.focus(); }; return NotificationBanner; })));
Version data entries
116 entries across 116 versions & 3 rubygems