• Molecule
  • CORE COMPONENT
  • Taxonomic name: M-PREFERRED CONTACT
  • Extension: FORMS-EXTENDED-A
  • Added on: v3.1.0 (08/12/17)
  • Updated on: v5.5.0 (23/03/21)

Preferred contact

The preferred contact component consists of a radio button attached to a textbox to allow a user to select a preferred contact option, for example one of two telephone numbers, or an email address over a telephone number.


Design and usage

Usage

  • Must be used for at least 2 or more questions of the same type.
  • Only use a radio button for preferred selection.
  • Only use with an active text field.
  • All fields within the preferred selection group can be disabled if required.

Accessibility

  • Aria-invalid must be used to indicate when an error has occurred with this element.
  • Aria-describedby must be used to link any help, instructional and/or error text with the element/form fields.

Design

  • Radio button is located to the right of the text box at desktop and tablet and below at mobile

Examples

Standard

Interactive example

Code example

<fieldset class"m-preferred-contact">
	<legend class="u-hidden--visually">...</legend>
	<div class="m-form-row">
		<label class="a-label" for="...">...</label>
		<div class="m-form-row__content">
			<div class="m-preferred-contact-item">
				<div class="m-preferred-contact-item__textbox">
					<input class="a-textbox" type="tel" id="..." />
				</div>
				<div class="m-preferred-contact-item__radio">
					<label class="a-radio" for="...">
						<input class="a-radio__input" type="radio" name="radio_group" id="..." value="..." />
						<span class="a-radio__label"><span class="a-radio__label-inner">...<span class="u-hidden--visually">...</span></span></span>
						<span class="a-radio__ui"></span>
					</label>
				</div>
			</div>
		</div>
	</div>	...</fieldset>

Preferred contact valid

When a correct number is entered, display validation below. The primary validation is shown 'Telephone number 1'.

Interactive example

Code example

<fieldset class"m-preferred-contact">
	<legend class="u-hidden--visually">...</legend>
	<div class="m-form-row is-valid">
		<label class="a-label" for="...">...</label>
		<div class="m-form-row__content">
			<p class="m-form-row__validation-message">...</p>
			<div class="m-preferred-contact-item">
				<div class="m-preferred-contact-item__textbox">
					<input class="a-textbox" type="tel" id="..." />
				</div>
				<div class="m-preferred-contact-item__radio">
					<label class="a-radio" for="...">
						<input class="a-radio__input" type="radio" name="radio_group" id="..." value="..." />
						<span class="a-radio__label"><span class="a-radio__label-inner">...<span class="u-hidden--visually">...</span></span></span>
						<span class="a-radio__ui"></span>
					</label>
				</div>
			</div>
		</div>
	</div>	...</fieldset>

Input error

No or invalid number entered

Rule 1: When no number is entered, display error below.

Rule 2: When an invalid number is entered, display error below.

Rule 3: When selecting preferred radio button and no number is entered, display error below.

Interactive example

Code example

<fieldset class"m-preferred-contact">
	<legend class="u-hidden--visually">...</legend>
	<div class="m-form-row is-error">
		<label class="a-label" for="...">...</label>
		<div class="m-form-row__content">
			<p class="m-form-row__error-message" id="..."><span class="u-hidden--visually">Error: </span>...</p>
			<div class="m-preferred-contact-item">
				<div class="m-preferred-contact-item__textbox">
					<input class="a-textbox" type="tel" id="..." aria-invalid="true" aria-describedby="..." />
				</div>
				<div class="m-preferred-contact-item__radio">
					<label class="a-radio" for="...">
						<input class="a-radio__input" type="radio" name="radio_group" id="..." value="..." />
						<span class="a-radio__label"><span class="a-radio__label-inner">...<span class="u-hidden--visually">...</span></span></span>
						<span class="a-radio__ui"></span>
					</label>
				</div>
			</div>
		</div>
	</div>	...</fieldset>

Preferred number not selected

When both numbers are entered and no number is selected as a preferred, a notification error is shown.

Interactive example

Code example

<fieldset class"m-preferred-contact is-group-error" aria-invalid="true aria-describedby="...">
	<legend class="u-hidden--visually">...</legend>	<div class="m-card m-card-notification m-card-notification--warning" role="status" id="...">
		<div class="m-card-content">
			<div class="m-card-content__inner">
				<p>...</p>
			</div>
		</div>
	</div>	<div class="m-form-row">
		<label class="a-label" for="...">...</label>
		<div class="m-form-row__content">
			<div class="m-preferred-contact-item">
				<div class="m-preferred-contact-item__textbox">
					<input class="a-textbox" type="tel" id="..." />
				</div>
				<div class="m-preferred-contact-item__radio">
					<label class="a-radio" for="...">
						<input class="a-radio__input" type="radio" name="radio_group" id="..." value="..." />
						<span class="a-radio__label"><span class="a-radio__label-inner">...<span class="u-hidden--visually">...</span></span></span>
						<span class="a-radio__ui"></span>
					</label>
				</div>
			</div>
		</div>
	</div>	...</fieldset>

Preferred number disabled state

Interactive example

Code example

<fieldset class"m-preferred-contact">
	<legend class="u-hidden--visually">...</legend>
	<div class="m-form-row is-disabled">
	<label class="a-label" for="...">...</label>
		<div class="m-form-row__content">
			<div class="m-preferred-contact-item">
				<div class="m-preferred-contact-item__textbox">
					<input class="a-textbox" type="tel" disabled id="..." />
				</div>
				<div class="m-preferred-contact-item__radio">
					<label class="a-radio" for="...">
						<input class="a-radio__input" type="radio" name="radio_group" id="..." value="..." disabled />
						<span class="a-radio__label"><span class="a-radio__label-inner">...<span class="u-hidden--visually">...</span></span></span>
						<span class="a-radio__ui"></span>
					</label>
				</div>
			</div>
		</div>
	</div>	...</fieldset>

Required fields

At least one required

<fieldset class"m-preferred-contact" aria-required="true">
	<legend class="u-hidden--visually">...</legend>
	<div class="m-form-row">
		<label class="a-label" for="...">...</label>
		<div class="m-form-row__content">
			<div class="m-preferred-contact-item">
				<div class="m-preferred-contact-item__textbox">
					<input class="a-textbox" type="tel" id="..." />
				</div>
				<div class="m-preferred-contact-item__radio">
					<label class="a-radio" for="...">
						<input class="a-radio__input" type="radio" name="radio_group" id="..." value="..." />
						<span class="a-radio__label"><span class="a-radio__label-inner">...<span class="u-hidden--visually">...</span></span></span>
						<span class="a-radio__ui"></span>
					</label>
				</div>
			</div>
		</div>
	</div>	...</fieldset>

Particular field required

<fieldset class"m-preferred-contact">
	<legend class="u-hidden--visually">...</legend>
	<div class="m-form-row">
		<label class="a-label" for="...">...</label>
		<div class="m-form-row__content">
			<div class="m-preferred-contact-item">
				<div class="m-preferred-contact-item__textbox">
					<input class="a-textbox" type="tel" id="..." aria-required="true" />
				</div>
				<div class="m-preferred-contact-item__radio">
					<label class="a-radio" for="...">
						<input class="a-radio__input" type="radio" name="radio_group" id="..." value="..." />
						<span class="a-radio__label"><span class="a-radio__label-inner">...<span class="u-hidden--visually">...</span></span></span>
						<span class="a-radio__ui"></span>
					</label>
				</div>
			</div>
		</div>
	</div>	...</fieldset>

Development and test

Notes for developers

The radio button can only be combined with text inputs, and can not be paired with other form field types.

Visible labels and accessible names

An extra span with the class u-hidden--visually is required within the a-radio__label-inner to hold the hidden text required to make the accessible name for the label meaningful to screen readers. The visible label should always come first, with the hidden text following on to extend this by adding meaning and context, for example:

<span class="a-radio__label"><span class="a-radio__label-inner"> Preferred <span class="u-hidden--visually"> home phone number</span></span></span>

Visible labels and accessible names

An extra span with the class u-hidden--visually is required within the a-radio__label-inner to hold the hidden text required to make the accessible name for the label meaningful to screen readers. The visible label should always come first, with the hidden text following on to extend this by adding meaning and context, for example:

<span class="a-radio__label"><span class="a-radio__label-inner"> Preferred <span class="u-hidden--visually"> home phone number</span></span></span>

Input types

Care should be taken when choosing input field types for various uses, particularly with regard to number entry, as making the wrong selection could prevent users from inputting the required details into a form. For further information, see the form introduction page.

Aria usage for errors and help text

To aid screen reader users in completing forms without error and also with understanding and fixing any errors that have occured, some additional aria attributes are now recommended to be applied across all form fields/rows.

All form row help, explanatory text, form row instructions and form row errors must have a unique id assigned to them and be appropriately linked to either the individual form input or the form row using aria-describedby. This ensures that the help text is read out immediately on focus of the form input/fieldset. When there is more that one item that requires referencing within the aria-describedby attribute the id values must be supplied in the form of a space separated list. For example if there is an error with id of 'err1' and help text with id of 'help1' the value for the aria-describedby attribute would be 'err1 help1'.

All inline form error messages should start with the hidden text 'Error: ' so that when read by out by a screen reader it is immediately clear that the text being read is an error message.

All erroring form fields (or fieldset if a group or radios/checkboxes) must have aria-invalid="true" set on them, ensuring that when a user focus' on an errored form field, the field will be announced as invalid, so the user is then aware that there in an issue that requires fixing.

When linking help or errors, or even adding aria-invalid to the markup careful consideration must be taken as to where it is most appropriate to apply the value. The following rules should be used to decide where the attribute(s) should be applied.

  • Single form field - All attributes should be applied directly to that form field
  • Group of form fields but only one in error or help text applies to only one - Apply the attribute(s) to the only field in error or where the help text applies
  • Group of form field where all in error or the help text applies to all - Apply the attribute(s) to the groups surrounding fieldset (form row)

There may situations where more than one of these rules applies to the overall form row for example a date range where the instruction text applies to both fields so should be linked to the fieldset for the date range but one of the two fields is in error so the error should be linked to just that field not to the fieldset.

Important messages

To help those using assistive technologies, make sure that success/error messages which need to be announced to users have their aria attributes updated to role="alert" and/or aria-live="assertive".

Using autocomplete

Users appreciate when websites save them time by automatically filling common fields like names, email addresses and other frequently used fields, plus it helps to reduce potential input errors, especially on virtual keyboards and small devices.

Browsers use many methods to determine which fields they can auto-populate based on previously specified data by the user, and you can give hints to the browser by providing both the name attribute and the autocomplete attribute on each input element.

Further details can be found in the developer notes on the form introduction page.

Extension component

This component forms part of the 'forms-extended-a' extension and so requires an additional stylesheet to be loaded in order to be used; include the following code in the header of your page to attach the relevant additional stylesheet:

<link media="all" href="./assets/[ theme type ]/[ release version ]/[ organisation ]/[ theme name ]/css/forms-extended-a.css" rel="stylesheet" />

Notes for testers

The label should be displayed to the right of the radio button and should activate the radio button when selected (as should the radio button itself.


Classes overview

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

Class Outcome Required Applied to
.m-preferred-contact Needed to for error and valid states to work properly Yes fieldset
.m-preferred-contact-item Base for individual form rows Yes .m-preferred-contact .m-form-row__content > div
.m-preferred-contact-item__textbox Textbox styling for preferred contact Yes .m-preferred-contact-item > div
.a-textbox Additional styles for textboxes Yes .m-preferred-contact-item__textbox > input
.m-preferred-contact-item__radio Container for preferred radio Yes .m-preferred-contact-item__textbox + div
.a-radio Additional styles for radios Yes .m-preferred-contact-item__radio > label
.a-radio__input Additional styles for radio Yes .a-radio > input
a-radio__label Styles for radio label Yes .a-radio__input + span
.radio__label--inner Styles in order to keep the label centered when multiple lines are needed Yes .a-radio__label > span
.a-radio__ui Animations for the radio Yes .a-radio__label + span
is-group-error Error styling for radio area   .m-preferred-contact

Keyboard operations

TAB

Tabbing to an group of radio should make the radio option clearly visually different so that the focus point on the page is obvious to the user.

SPACE

With focus on the radio option, pressing SPACE will select/de-select the radio option.

CURSOR KEYS

With focus on the radio option, pressing any CURSOR KEY will move the focus to the next/previous option within the radio option group.

Component releases

  • Added on: v3.1.0 (08/12/17)
  • Updated on: v5.5.0 (23/03/21)

Latest update:

  • updated: Additional aria attributes are now recommended to be applied across all form fields/rows so as to aid screen reader users in completing forms without error and also with understanding and fixing any errors that have occurred.

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