Sha256: 8706b47bd770be41e9bc411654bc2835992bcc40a023cc7a5ca84fabeed22748

Contents?: true

Size: 1.59 KB

Versions: 45

Compression:

Stored size: 1.59 KB

Contents

import { mergeConfigs, setFocus } from '../../common/index.mjs';
import { normaliseDataset } from '../../common/normalise-dataset.mjs';
import { GOVUKFrontendComponent } from '../../govuk-frontend-component.mjs';

/**
 * Notification Banner component
 *
 * @preserve
 */
class NotificationBanner extends GOVUKFrontendComponent {
  /**
   * @param {Element | null} $root - HTML element to use for notification banner
   * @param {NotificationBannerConfig} [config] - Notification banner config
   */
  constructor($root, config = {}) {
    super($root);
    this.config = void 0;
    this.config = mergeConfigs(NotificationBanner.defaults, config, normaliseDataset(NotificationBanner, this.$root.dataset));
    if (this.$root.getAttribute('role') === 'alert' && !this.config.disableAutoFocus) {
      setFocus(this.$root);
    }
  }
}

/**
 * Notification banner config
 *
 * @typedef {object} NotificationBannerConfig
 * @property {boolean} [disableAutoFocus=false] - If set to `true` the
 *   notification banner will not be focussed when the page loads. This only
 *   applies if the component has a `role` of `alert` – in other cases the
 *   component will not be focused on page load, regardless of this option.
 */

/**
 * @typedef {import('../../common/index.mjs').Schema} Schema
 */
NotificationBanner.moduleName = 'govuk-notification-banner';
NotificationBanner.defaults = Object.freeze({
  disableAutoFocus: false
});
NotificationBanner.schema = Object.freeze({
  properties: {
    disableAutoFocus: {
      type: 'boolean'
    }
  }
});

export { NotificationBanner };
//# sourceMappingURL=notification-banner.mjs.map

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
govuk_publishing_components-51.1.1 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-51.1.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-51.0.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-50.0.1 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-50.0.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-49.1.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-49.0.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-48.0.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-47.0.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-46.4.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-46.3.1 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-46.3.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-46.2.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-46.1.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-46.0.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-45.10.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-45.9.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-45.8.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-45.7.0 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs
govuk_publishing_components-45.6.1 node_modules/govuk-frontend/dist/govuk/components/notification-banner/notification-banner.mjs