Skip to content

Commit

Permalink
Merge pull request #1049 from nhsuk/update-frontend
Browse files Browse the repository at this point in the history
install latest version of the frontend library
  • Loading branch information
chrimesdev authored Mar 16, 2021
2 parents 4fe5db5 + c1da742 commit 0bad0e6
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:wrench **Fixes**

- use maincontent as the ID for the main element across the NHS digital service manual and examples for consistency and to match the Skip link anchor (https://github.com/nhsuk/nhsuk-frontend/issues/716)
- use the latest version of NHS.UK frontend (v5.0.0)
- update dependencies to the latest versions

## 3.13.0 - 11 March 2021
Expand Down
62 changes: 62 additions & 0 deletions app/scripts/autocomplete/autoCompleteConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import AccessibleAutoComplete from 'accessible-autocomplete';

/**
@typedef autocompleteConfig
@type {Object}
Optional param for NHS.UK functionality
@property {string=} formId ID of form element containing autocomplete.
Required params for accessible-autocomplete
@property {string} inputId ID of the input field.
@property {string} containerId ID of element in which the autocomplete will be rendered in.
@property {function} source Function called on input change
*/

/**
* Create an autocomplete.
* @param {autocompleteConfig} config
*/
export default (config) => {
const { formId, inputId, containerId } = config;

const form = document.getElementById(formId);
const input = document.getElementById(inputId);
const container = document.getElementById(containerId);

/**
* Adds event to catch enter presses when the main input is focused and submits the form
*/
const addFormEvents = () => {
// Attach event to form as the original input element is cloned by autoComplete plugin
form.addEventListener('keyup', ({ key }) => {
// Submit search using current input value if input is focused and enter is pressed
if (key === 'Enter' && document.activeElement.id === inputId) form.submit();
});
};

const initAutoComplete = () => {
const defaultConfig = {
confirmOnBlur: false,
element: container,
id: inputId,
minLength: 2,
name: input.name,
placeholder: input.placeholder,
};

// Remove original search input as it will be replaced by accessibleAutocomplete
input.parentNode.removeChild(input);

// Initialise accessibleAutocomplete
AccessibleAutoComplete({
...defaultConfig,
...config,
});
};

// Add autocomplete functionality if required config options exist
if (input && container && config.source) {
initAutoComplete();
// If form element exists then add events to add standard form functionality
if (form) addFormEvents();
}
};
2 changes: 1 addition & 1 deletion app/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-new */
// NHS.UK frontend components
import AutoComplete from 'nhsuk-frontend/packages/components/header/autoCompleteConfig';
import MenuToggle from 'nhsuk-frontend/packages/components/header/menuToggle';
import SearchToggle from 'nhsuk-frontend/packages/components/header/searchToggle';
import AutoComplete from './autocomplete/autoCompleteConfig';
import SkipLink from '../../node_modules/nhsuk-frontend/packages/components/skip-link/skip-link';
import Details from '../../node_modules/nhsuk-frontend/packages/components/details/details';
import Checkboxes from '../../node_modules/nhsuk-frontend/packages/components/checkboxes/checkboxes';
Expand Down
1 change: 1 addition & 0 deletions app/styles/app/_app.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import 'app-reading-width';
@import 'autocomplete';
@import 'beta-banner';
@import 'code-block';
@import 'code-highlight';
Expand Down
185 changes: 185 additions & 0 deletions app/styles/app/_autocomplete.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/* ==========================================================================
COMPONENTS / #HEADER / #AUTOCOMPLETE
========================================================================== */

/**
* 1. IE 10 prefix for flexbox
* 2. Proprietary extension so form field looks the same in Safari
* 3. Custom height and width of form items
* 4. Custom height and width of svg icons
* 5. Custom spacing to position the search icon
* 6. Drop shadow on search suggestions dopdown box, custom spread and blur
* 7. Z-index to bring the dropdown to the front
* 8. No current spacing at 12px so using this value
* 9. Z-index to being search box to the front for focus state style
* 10. Custom padding to stop text jumping on focus
*/

.autocomplete-container {
display: inline-block;
z-index: 1; /* [9] */

@include mq($until: tablet) {
display: inline;
width: 100%;
}
}

@include mq($until: tablet) {
/* duplicate of .nhsuk-search__input in _header.scss, for non javascript version */
.autocomplete__input {
-ms-flex-positive: 2; /* [1] */
-webkit-appearance: listbox; // sass-lint:disable-line prefixes /* [2] */
border-bottom: 1px solid $color_nhsuk-grey-3;
border-bottom-left-radius: $nhsuk-border-radius;
border-bottom-right-radius: 0;
border-left: 1px solid $color_nhsuk-grey-3;
border-right: 0;
border-top: 1px solid $color_nhsuk-grey-3;
border-top-left-radius: $nhsuk-border-radius;
border-top-right-radius: 0;
flex-grow: 2;
font-size: inherit;
height: 52px; /* [3] */
margin: 0;
outline: none;
padding: 0 nhsuk-spacing(3);
width: 100%; /* [3] */

&:focus {
border: $nhsuk-focus-width solid $nhsuk-focus-text-color;
box-shadow: 0 0 0 $nhsuk-focus-width $nhsuk-focus-color;
outline: $nhsuk-focus-width solid transparent;
outline-offset: $nhsuk-focus-width;
padding: 0 13px; /* [10] */
}
}
}

@include mq($from: tablet) {
/* duplicate of .nhsuk-search__input in _header.scss, for non javascript version */
.autocomplete__input {
-webkit-appearance: listbox; // sass-lint:disable-line prefixes /* [2] */
border: 1px solid $color_nhsuk-white;
border-bottom-left-radius: $nhsuk-border-radius;
border-bottom-right-radius: 0;
border-right: 0;
border-top-left-radius: $nhsuk-border-radius;
border-top-right-radius: 0;
font-size: $nhsuk-base-font-size;
height: 40px; /* [3] */
padding: 0 12px; /* [9] */
width: 200px; /* [3] */

&:focus {
border: 2px solid $nhsuk-focus-text-color;
box-shadow: 0 0 0 $nhsuk-focus-width $nhsuk-focus-color;
outline: $nhsuk-focus-width solid transparent;
outline-offset: $nhsuk-focus-width;
padding: 0 11px; /* [10] */
}

&::placeholder {
color: $color_nhsuk-grey-2;
font-size: $nhsuk-base-font-size;
}
}
}

@include mq($from: desktop) {
.autocomplete__input {
width: 235px;
}
}

.autocomplete__menu {
// sass-lint:disable-block no-vendor-prefixes, no-color-literals
-moz-box-shadow: 0 3px 5px rgba($nhsuk-box-shadow-color, $alpha-transparency-50); /* [6] */
-webkit-box-shadow: 0 3px 5px rgba($nhsuk-box-shadow-color, $alpha-transparency-50); /* [6] */
background-color: $color_nhsuk-white;
border-bottom: 1px solid $color_nhsuk-grey-4;
border-bottom-left-radius: $nhsuk-border-radius;
border-bottom-right-radius: $nhsuk-border-radius;
border-left: 1px solid $color_nhsuk-grey-4;
border-right: 1px solid $color_nhsuk-grey-4;
box-shadow: 0 0 ($nhsuk-box-shadow-spread - 1) 0 rgba($nhsuk-box-shadow-color, $alpha-transparency-50); /* [6] */
list-style: none;
margin-top: 2px;
overflow-x: hidden;
overflow-y: auto;
padding: nhsuk-spacing(3);
position: absolute;
top: 100%;
width: 100%;
z-index: 1; /* [7] */

@include mq($until: tablet) {
border: 0;
box-shadow: none;
margin: 0;
padding-left: 0;
padding-right: 0;
position: relative;
}
}

.autocomplete__menu--visible {
display: block;
}

.autocomplete__menu--hidden {
display: none;
}

.autocomplete__option {
border-bottom: 1px solid $color_nhsuk-grey-5;
color: $color_nhsuk-blue;
cursor: pointer;
font-size: $nhsuk-base-font-size;
padding-bottom: 12px; /* [8] */
text-align: left;
text-decoration: underline;

.nhsuk-icon__search {
fill: $color_nhsuk-grey-3;
float: left;
height: 22px; /* [4] */
margin: 2px 4px 0 0; /* [5] */
width: 22px; /* [4] */
}

&:hover,
&:active {
text-decoration: none;
}

&:focus {
outline: 1px solid transparent;
text-decoration: none;

a {
@include nhsuk-focused-text();
}
}

@include mq($from: tablet) {
&:last-child {
border-bottom: 0;
}
}
}

.autocomplete__option--no-results {
border-bottom: 0;
color: $color_nhsuk-black;
font-size: $nhsuk-base-font-size;
line-height: $nhsuk-base-line-height;
margin: 0;
padding: 0;
text-align: left;
text-decoration: none;

@include mq($until: tablet) {
padding: nhsuk-spacing(3) 0;
}
}
6 changes: 2 additions & 4 deletions app/views/includes/_header-prototype.njk
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
<header class="nhsuk-header nhsuk-header__menu--only" role="banner">
<div class="nhsuk-width-container nhsuk-header__container app-width-container">
<div class="nhsuk-header__logo"><a class="nhsuk-header__link nhsuk-header__link--service " href="/" aria-label="NHS digital service manual homepage">
<svg class="nhsuk-logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" role="presentation" focusable="false" viewBox="0 0 40 16">
<svg class="nhsuk-logo" xmlns="http://www.w3.org/2000/svg" role="presentation" focusable="false" viewBox="0 0 40 16">
<path class="nhsuk-logo__background" d="M0 0h40v16H0z"></path>
<path class="nhsuk-logo__text" d="M3.9 1.5h4.4l2.6 9h.1l1.8-9h3.3l-2.8 13H9l-2.7-9h-.1l-1.8 9H1.1M17.3 1.5h3.6l-1 4.9h4L25 1.5h3.5l-2.7 13h-3.5l1.1-5.6h-4.1l-1.2 5.6h-3.4M37.7 4.4c-.7-.3-1.6-.6-2.9-.6-1.4 0-2.5.2-2.5 1.3 0 1.8 5.1 1.2 5.1 5.1 0 3.6-3.3 4.5-6.4 4.5-1.3 0-2.9-.3-4-.7l.8-2.7c.7.4 2.1.7 3.2.7s2.8-.2 2.8-1.5c0-2.1-5.1-1.3-5.1-5 0-3.4 2.9-4.4 5.8-4.4 1.6 0 3.1.2 4 .6"></path>
<image src="https://assets.nhs.uk/images/nhs-logo.png" xlink:href=""></image>
</svg>
<span class="nhsuk-header__service-name">
Digital service manual
Expand Down Expand Up @@ -71,10 +70,9 @@
<header class="nhsuk-header" role="banner">
<div class="nhsuk-width-container nhsuk-header__container app-width-container">
<div class="nhsuk-header__logo"><a class="nhsuk-header__link nhsuk-header__link--service " href="/" aria-label="NHS digital service manual homepage">
<svg class="nhsuk-logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" role="presentation" focusable="false" viewBox="0 0 40 16">
<svg class="nhsuk-logo" xmlns="http://www.w3.org/2000/svg" role="presentation" focusable="false" viewBox="0 0 40 16">
<path class="nhsuk-logo__background" d="M0 0h40v16H0z"></path>
<path class="nhsuk-logo__text" d="M3.9 1.5h4.4l2.6 9h.1l1.8-9h3.3l-2.8 13H9l-2.7-9h-.1l-1.8 9H1.1M17.3 1.5h3.6l-1 4.9h4L25 1.5h3.5l-2.7 13h-3.5l1.1-5.6h-4.1l-1.2 5.6h-3.4M37.7 4.4c-.7-.3-1.6-.6-2.9-.6-1.4 0-2.5.2-2.5 1.3 0 1.8 5.1 1.2 5.1 5.1 0 3.6-3.3 4.5-6.4 4.5-1.3 0-2.9-.3-4-.7l.8-2.7c.7.4 2.1.7 3.2.7s2.8-.2 2.8-1.5c0-2.1-5.1-1.3-5.1-5 0-3.4 2.9-4.4 5.8-4.4 1.6 0 3.1.2 4 .6"></path>
<image src="https://assets.nhs.uk/images/nhs-logo.png" xlink:href=""></image>
</svg>
<span class="nhsuk-header__service-name">
Digital service manual
Expand Down
2 changes: 1 addition & 1 deletion app/views/includes/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{%- from 'textarea/macro.njk' import textarea %}
{%- from 'includes/design-example.njk' import designExample %}
<!DOCTYPE html>
<!--[if lt IE 9]><html class="ie8" lang="en"><![endif]--><!--[if IE 9]><html class="ie9" lang="en"><![endif]--><!--[if gt IE 9]><!--><html lang="en"><!--<![endif]-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down
2 changes: 1 addition & 1 deletion app/views/includes/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% from 'skip-link/macro.njk' import skipLink %}

<!DOCTYPE html>
<!--[if lt IE 9]><html class="ie8" lang="en"><![endif]--><!--[if IE 9]><html class="ie9" lang="en"><![endif]--><!--[if gt IE 9]><!--><html lang="en" style="{{ html_style }}"><!--<![endif]-->
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Expand Down
18 changes: 7 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"license": "MIT",
"dependencies": {
"accessible-autocomplete": "^2.0.3",
"axios": "^0.21.1",
"basic-auth": "^2.0.1",
"browser-sync": "^2.26.14",
Expand All @@ -57,7 +58,7 @@
"eslint-plugin-import": "^2.22.1",
"iframe-resizer": "^3.6.6",
"jest": "^25.5.4",
"nhsuk-frontend": "^4.1.0",
"nhsuk-frontend": "^5.0.0",
"node-sass": "^4.14.1",
"nodemon": "^2.0.7",
"sass-lint": "^1.13.1",
Expand Down

0 comments on commit 0bad0e6

Please sign in to comment.