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

Version Path
defra_ruby_template-3.15.1 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
defra_ruby_template-3.15.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-28.5.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-28.4.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-28.3.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-28.2.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-28.1.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-28.0.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.20.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.19.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.18.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_tech_docs-3.0.1 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.17.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.16.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.15.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.14.2 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.14.1 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.14.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.13.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js
govuk_publishing_components-27.12.0 node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js