• Organism
  • CORE COMPONENT
  • Taxonomic name: O-MODAL--FULLSCREEN
  • Added on: v4.0.0 (20/07/18)
  • Updated on: v5.9.0 (13/07/21)

Full screen modal

Full screen modals extend the functionality of standard modals by allowing short forms to take over the user's entire viewport to enable them to focus on a particular task.


Design and usage

Structure

  • Covers the whole viewport
  • Modal header contains a tertiary button to cancel and close the modal
  • Modals always have a heading
  • Any confirmation message of saving the content within the modal must be done within the page that it came from
  • Modals must include a secondary CTA cancel button to close them; any form data changed in the modal will not be submitted
  • A modal window can close when pressing the ESC key; again, any form data changed in the modal will not be submitted
  • When page is refreshed, all data entered inside form is wiped
  • Do not place multi-step user journeys inside a modal, ie. can't start another quote process inside modal
  • Do not place any confirmation message after submitting a modal within that same modal

Placement

  • CTAs that trigger a modal can be placed anywhere on a page

Labels

  • Button labels are customisable
  • Header close button label should not change - it always says 'Close' (or its local language equivalent)

Errors

  • Form errors need to display within the modal window
  • Page should not reload to present errors

Non-JavaScript

  • CTA for the modal window becomes an anchor link to a new page containing the modal content

Use case

  • For using forms in a modal, when you want to remove distractions for the user or have backend constraints requiring the user to stay on the same page
  • Saving a quote
  • Updating already saved personal information
  • Do not use for promotional / non-critical content, unless part of a process user journey like quote to buy
  • Do not use to hide content that is critical to making an informed decision to buy a product
  • Do not use to hide critical information that is part of a process user journey ie. how we use your email address during a change email journey
  • Do not use to hide legal or regulatory content
  • Do not use for anything other than forms - use standard modals instead

Examples

Interactive example

Code example

Linking to modal content

<!-- Full screen modal link -->
<a href="..." data-module="o-modal" data-module-load="true" data-modal-fullscreen="true">
	...
</a>

Target div for modal content to be inserted into

<div class="o-modal-target"></div>

Extended functionality

In the change email example, the emitter has been used to inject a notification card into the content following the running of the modal:destroy function (and to remove any existing ones beforehand. The secondary CTA has also been programmed to remove any existing notificataions once it has completed.

Please note that this is purely for demostration purposes and is not a complete working example.

<script>
document.addEventListener( 'frameworkready', function () {
	FRAMEWORK.require([ utility ], function ( utility ) {
		// Wrapping functionaility to run this once elements are on the page		document.querySelector( '.close-test' ).addEventListener( 'click', function listener( event ) {
			event.preventDefault();
			setTimeout( function () {
				utility.trigger( window, 'modal:close' );
				document.querySelector( '.notification-target' ).innerHTML = '';
			}, 1000 );
		});
		document.querySelector( '.destroy-test' ).addEventListener( 'click', function listener( event ) {
			event.preventDefault();
			setTimeout( function () {
				utility.trigger( window, 'modal:destroy' );
				document.querySelector( '.notification-target' ).innerHTML = '<div class="m-card m-card-notification m-card-notification--success" role="status"><div class="m-card-content"><div class="m-card-content__inner"><p>Function successful</p></div></div></div>';
			}, 1000 );
		});		// Closing wrapping functionality
	});
});
</script>
<a href="..." data-module="o-modal" data-module-load="true" data-modal-fullscreen="true">
	...
</a>
<div class="notification-target"></div>
<div class="o-modal-target"></div>

Development and test

Notes for developers

Content can only be loaded in to a full screen modal from another page on the same domain. All modal content must be available on a separate page when there is no JavaScript and in older browsers.

Content being loaded into the modal in sanitised prior to injection to the modal, meaning any inline JavaScript will not be run.

To include a button that closes the modal window, add the class a-button--cancel to the button. This will close the modal but retain any content contained on the form within it in case the user returns to the modal.

Controling modals programatically

Modals can be controlled programatically to open, close or destroy a particular modal.

A simple event listener has been included with options to either just close the modal, or to close the modal and remove the loaded content from the page (thus clearing the form). This can be run using the following code:

utility.trigger( window, 'modal:close' );
utility.trigger( window, 'modal:destroy');

For more information on this, see our page on how to add Javascript to Framework components.

Alternatively, an API is available offering the following methods (please note that these are only available when associated with a valid modal link):

Method Description
open( modalLinkElement ) Open the modal for the modal link node element passed in.
close() Close the modal that is currently open.
destroy() Destroy the modal that is currently open.

For example:

document.addEventListener( 'frameworkready', function () {
	FRAMEWORK.require([ 'blocks/o-modal' ], function ( oModalModule ) {
		var modalLinkEl = document.querySelector( '#modalId' ),
			modalInstance = oModalModule.initInstance( document.documentElement );		modalInstance.open( modalLinkEl );
	});
});

Changing locale settings

Default text for the close link and the loading indicator can be changed for a particular locale.

en: {
	oModal : {
		closeText : 'Close',
		loadingText : 'Please wait',
	},
},

For more information on this, see our page on how to change locale settings within JavaScript.


Notes for testers

  • Ensure that links can be accessed via the mouse as well as via tabbing using the keyboard.
  • Use a screen reader to confirm that the links are understandable as to where they will be going when listed out of context of the page.
  • Ensure that when hovering over a link the style changes noticeably.
  • Ensure that when a link has focus the style changes noticeably.
  • Ensure that when a modal is open focus remains within the o-modal.
  • Ensure that when JavaScript is not available, or for older browsers such as IE8, that any links to open modals take the user to a separate page containing the relevant content.
  • Ensure that any modules such as show/hide, tabs etc that are contained within a modal's content work as expected.
  • Ensure it is clear how to close the window - by the use of a prominent close buttons and also by using the ESC key.
  • Ensure it is clear how to submit the form in the modal
  • Ensure that the submit button closes the modal and causes the form fields within it to be emptied so that they are clear next time it is opened.
  • There should be a clear visual distinction between the window and the background, which should be completely hidden from view by the modal. The user should not be able to to scroll or interact with background content.
  • Focus should be returned to its original place when the window is closed.

Classes overview

The following table gives you a quick overview of the CSS classes that can be applied.

Class Outcome Required Applied to Comments
.o-modal-target Class for div to hold loaded modal content Yes div Should be placed where possible as last div on the page to avoid any potential conflicts.

Keyboard operations

TAB

Tabbing to an anchor should make the anchor clearly visually different so that the focus point on the page is obvious to the user

SPACE or ENTER

With focus on an anchor, pressing SPACE or ENTER will open the link. If the link is internal to the page it will scroll the page otherwise it will load the new page.

ESCAPE

With a modal visible, pressing ESCAPE will close the modal without submitting any form content. Any entered data should be retained for when the modal is reopened.

Component releases

  • Added on: v4.0.0 (20/07/18)
  • Updated on: v5.9.0 (13/07/21)

Latest update:

  • updated: Modals can now be controlled programatically to open, close or destroy a particular modal.
  • updated: It is now recommended that the data attribute data-module-load="true" is added alongside data-module="o-modal" in order to force loading of the JavaScript on page load instead of it being lazy loaded. This helps mitigate issues where modal content could remain visible until the anchor it is associated with comes into view.

Full version history

A full history of changes and enhancements detailing all minor and major updates to the component.

View full version history

Want something new in Framework, or to chat about an issue you're having with it?

Contact the team