Code Monkey home page Code Monkey logo

govuk-frontend's Introduction

GOV.UK Frontend · Build Status JavaScript Style Guide

GOV.UK Frontend contains the code you need to start building a user interface for government platforms and services.

See live examples of GOV.UK Frontend components, and guidance on when to use them in your service, in the GOV.UK Design System.

Contact the team

GOV.UK Frontend is maintained by a team at Government Digital Service. If you want to know more about GOV.UK Frontend, please email the Design System team or get in touch with them on Slack.

Quick start

There are 2 ways to start using GOV.UK Frontend in your app:

Once installed, you will be able to use the code from the examples in the GOV.UK Design System in your service.

You should also have a plan to stay up to date with changes.

Browser and assistive technology support

To help manage the ever-growing number of browser versions, we group browsers into 4 grades:

  • grade A - Most recent stable versions of Chrome, Firefox, Edge, Samsung Internet and Safari
  • grade B - All stable versions of Chrome, Firefox and Edge released in the last 6 months and the last 4 major stable releases of Safari which are not supported in Grade A
  • grade C - All browsers that support <script type="module"> (Chrome 61+, Edge 16-18, Edge 79+, Firefox 60+, Safari 11+)
  • grade X - All other browsers (including IE11 and older)

Note: Only browsers in grades A, B and C will run our JavaScript enhancements. We will not support our JavaScript enhancements for older browsers in grade X.

For more information see our Browser Support documentation.

GOV.UK Frontend also supports:

Accessibility

The GOV.UK Design System team works hard to ensure that GOV.UK Frontend is accessible.

Using Frontend will help your service meet level AA of WCAG 2.2. But you must still check that your service meets accessibility requirements, especially if you extend or modify components.

You should also use the JavaScript from GOV.UK Frontend and read the accessibility statement for the GOV.UK Design System.

Known issues flagged by validators or automated testing tools

Check our list of known issues that may be reported by HTML Validators or automated testing tools.

Security

GDS is an advocate of responsible vulnerability disclosure. If you’ve found a vulnerability, we would like to know so we can fix it.

For full details on how to tell us about vulnerabilities, see our security policy.

Licence

Unless stated otherwise, the codebase is released under the MIT License. This covers both the codebase and any sample code in the documentation. The documentation is © Crown copyright and available under the terms of the Open Government 3.0 licence.

Contributing

To learn how to help us build GOV.UK Frontend, see our contribution guidelines.

The govuk-frontend repository is public and we welcome contributions from anyone.

Contributors to alphagov repositories are expected to follow the Contributor Covenant Code of Conduct. Contributors working within government are also expected to follow the Civil Service code.

We're unable to monitor activity on this repository outside of our office hours (10am to 4pm, UK time). To get a faster response at other times, you can report abuse or spam to GitHub.

govuk-frontend's People

Contributors

36degrees avatar adamsilver avatar alex-ju avatar aliuk2012 avatar andymantell avatar charlottedowns avatar claireashworth avatar colinrotherham avatar daniel-ac-martin avatar debsdee avatar dependabot[bot] avatar domoscargin avatar emmalewis avatar eoinshaughnessy avatar frankieroberto avatar gemmaleigh avatar hannalaakso avatar htmlandbacon avatar joelanman avatar kevindew avatar lfdebrux avatar m-green avatar matteason avatar nataliecarey avatar nickcolley avatar owenatgov avatar patrickpatrickpatrick avatar querkmachine avatar romaricpascal avatar web-bert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

govuk-frontend's Issues

Utility spacer classes should be responsive

The utility classes e.g. govuk-u-pt-1 that are output from _spacing.scss define hard units. These classes should contain a breakpoint that follows this mapping.

60px (Desktop) > 40px (Mobile)
50px (Desktop) > 30px (Mobile)
30px (Desktop) > 20px (Mobile)
20px (Desktop) > 15px (Mobile)
---- No change below 15px ---
15px (Desktop) - 15px (Mobile)
10px (Desktop) - 10px (Mobile)
5px (Desktop) - 5px (Mobile)

Fieldsets are not wrapped correctly in checkboxes/radios

screen shot 2018-01-18 at 14 59 06

Can reproduce by rendering

  {{ govukRadios({
    "fieldset": {},
    "idPrefix": "radio-stacked",
    "name": "radio-stacked",
    "items": [
      {
        "value": "email",
        "text": "Email"
      },
      {
        "value": "phone",
        "text": "Phone"
      },
      {
        "value": "text",
        "text": "Text message"
      }
    ]
  }) }}

Improve the usability of the 'Back link' component

This issue is raised on behalf on @owenm6.


Suggested changes to the back link pattern

When not to use this component

On non-linear flows including a back link could confuse users or stop them completing a task

How to use this component

Adding a page title or ‘back to previous page’ makes it clearer to the user what to expect from the interaction. It also helps increase a users confidence that they will not lose their work.

Research

We have seen some users not understand the context of the current back link design. This has caused them anxiety.

Some users have been concerned that using the back link would lose their work.

Adjustments to design

  • change triangle to arrow (chevron)
  • use link colour for consistency

screen shot 2018-01-30 at 10 00 37

Code and examples

Rename 'Phase tag' component to 'Tag'

The Phase tag component has generic value beyond it's use in the Phase banner component.

For example, we could use it to style the task statuses in the task list pattern.

For this reason we should remove the reference to 'phase' from the name.

This is an example of a component that goes by a number of names - we should add 'pill' and 'chip' as aliases.

Macros Component API should not require internal classes for modifiers

Macros abstract our class names, if we were to change our class names, macro usage would break for our users.

In our button examples, we pass the internal button modifier class to make a button into a start button.

We could consider passing a boolean instead so that if we choose to change how our classes work, macros still function.

For example instead of

- name: start
  data:
    text: Start now button
    classes: 'govuk-c-button--start'

We could do:

- name: start
  data:
    text: Start now button
    start: true

See also the GOV.UK Publishing component: http://govuk-static.herokuapp.com/component-guide/button/start_now_button

Link to code: https://github.com/alphagov/static/blob/a9a040a72d475ef7015c1c9e690a5d77687fcfd8/app/views/govuk_component/button.raw.html.erb#L1

We constructed the class based on booleans, then finally merge with classes and inject into the markup.

Edit:
I put together an example showing how you can restructure the macro to avoid the confusing forking logic.

This approach only forks on individual parts of the template, which is easier to reason about.

https://glitch.com/edit/#!/flag-based-macro-approach?path=views/index.html:15:26

Add a 'highlighted text' style

There's occasionally the need to highlight text in user interfaces.

For example:

  • matching text in search results
  • placeholders in GOV.UK Notify templates
  • showing changes to contracts in Digital Marketplace

The Home Office design system has a style for this.

Ensure test suite is run before releasing GOV.UK Frontend

At the moment it is possible to have a failing master branch.

  1. Contributor 1 pushes PR 1
  2. PR 1 passes CI
  3. Contributor 2 pushes PR 2 with breaking changes that 1 relied on
  4. PR 2 passes CI and is merged into master
  5. PR 1 will not now be failing since Travis only runs on updates to an individual PR, not master changes.

Considered solution: Force branches to be up-to-date with master

screen shot 2018-02-02 at 10 57 44

We ruled this out since it would mean with so many PRs happening we'd have to rebase very often which would slow down the team.

Another option is to ensure that before releases our test suite is ran.

We need to update the build scripts or documentation to include this step.

Generated README files

To avoid duplicating code examples and documentation manually, as well as having full docs in the source directory for each component, we generate the README markdown file and a dev preview page from the same set of nunjucks templates.

This will allow us to test our assumptions with consumers.

It could be the case that we disable the generation task once we are confident in the docs content, but there is still the question creating and updating docs for component when a contribution happens.

Add a link style for non-link elements

Occasionally you need to style something that’s not a link as a link. For example, summary tags are styled as links on GOV.UK, and occasionally form controls need to be styled as links.

Constraining text Inputs and Safari autofill

If autofill is turned on (default) Safari adds the "person" icon to the right hand side of the input.

Relating to constraining inputs to an appropriate size of their content, this example on the DVLA Driving Licence service shows the autofill icon completely obscuring the content of the input. The user needs to type blindly and will only see what they have typed by de-focussing. (side note, this example will also lead to a year typed many times which is also not apparent even after de-focussing)

safari-autofill

Do we want to suggest that inputs should:
be "x" many characters bigger than expected content
or
override the autofill icon all together?

input::-webkit-contacts-auto-fill-button {
  visibility: hidden;
  display: none !important;
  pointer-events: none;
  position: absolute;
  right: 0;
}

Make all form elements the same height

If our form elements were the same height it would make it much easier to maintain a vertical rhythm and to create horizontal form layouts where necessary.

For example, we sometimes need to align buttons to the right of form fields (eg. search boxes). They'd look a lot nicer if they were the same height.

I'm thinking of the following elements in particular: radios, checkboxes, text fields, select boxes, type-aheads, buttons.

Make it clear that the "html" attribute can be unsafe

What

We had a discussion on a design system slack channel about the documentation not to encourage the use of html parameter in macros. We concluded, we shouldn't take away that functionality, but make it clear it's unsafe to use, causing people to rethink the strategy or apply necessary fixes before hand.

Why

It's more efficient to copy and paste a block of text without realising what it's doing. It could easily bring some XSS vulnerability into the application by accident, which we'd all like to avoid.

Proposal

Changing the name of the html attribute is a good start. This will need to be followed by some documentation changes on the Design System.

Before

{% from "panel/macro.njk" import govukPanel %}

{{ govukPanel({
  "titleText": "Application complete",
  "html": "Your reference number<br><strong>HDJ2123F</strong>"
})
}}

After

{% from "panel/macro.njk" import govukPanel %}

{{ govukPanel({
  "titleText": "Application complete",
  "unsafeHTML": "Your reference number<br><strong>HDJ2123F</strong>"
})
}}

Connection

alphagov/govuk-design-system#175

Should label hints be using aria-describedby?

https://govuk-frontend-review.herokuapp.com/components/label

Our hint text in labels are directly embedded, if this were very long it could make these labels unwieldily.

Should we be using aria-describedby and move these hints outside the label?

https://developer.paciellogroup.com/blog/2014/12/using-aria-describedby-to-provide-helpful-form-hints/

<label class="govuk-c-label">
  National Insurance number
  <span class="govuk-c-label__hint">
    It’s on your National Insurance card, benefit letter, payslip or P60. For example, ‘QQ 12 34 56 C’.
  </span>
</label>

vs

<input id="input-example" aria-describedby="label-hint"/>
<div class="govuk-c-label">
  <label class="govuk-c-label__text" for="input-example">National Insurance number</label>
  <span class="govuk-c-label__hint" id="label-hint">
    It’s on your National Insurance card, benefit letter, payslip or P60. For example, ‘QQ 12 34 56 C’.
  </span>
</div>

Manage component dependency

We want to create isolated components that include and call relevant dependencies without duplicating the imported code.

Possible approaches:

  1. use a sass mixin to check: http://paul.wellnerbou.de/2015/05/18/avoid-multiple-imports-of-the-same-scss-file-with-sass/ or https://github.com/carbon-design-system/carbon-components/blob/master/src/globals/scss/_import-once.scss

  2. Use an NPM module:
    https://www.npmjs.com/package/node-sass-import-once

Either way it might become redundant as of Sass 4.0: sass/sass#156

Proposal: add a 'positive' colour

Copied over from GOV.UK Frontend toolkit

There are cases where it's useful to have a colour with a semantic meaning of 'positive'.

We already have error_colour which is a good red for 'negative' - but we don't have a counterpart.

We could use an existing colour, or make a new colour. Either way, a semantic SASS name would be good.

The closest colour would be button_colour. An alternate would be #008800 which is the green used by petitions. It's warmer, which feels more positive to me.

image

Rename border variables based on px width

As mentioned by @dashouse in #519:

Might be worth thinking about all border widths being less specific in general and not worrying about specifying names based on usage?

$govuk-border-width-10: 10px
$govuk-border-width-5: 5px
$govuk-border-width-4: 4px
$govuk-border-width-2: 2px
$govuk-border-width-1: 1px

Add a link style for links with no visited state

There are some cases where it’s not appropriate to distinguish between visited and non-visited links.

An example is navigation links to pages with dynamic content, like dashboards in admin systems. The content on the page is changing all the time, so the fact that you’ve visited it before is not that important.

Allow for both responsive and fixed form field lengths

By default our input and select fields switch to 100% width for small screen sizes. In some cases however we want them to remain at a fixed width. For example, very short fields designed to take a specific number of characters, like day, month, year and postcode.

The code for Start button is complicated

Here is the code for a start button on the Prototype Kit:

<a class="govuk-c-button govuk-c-button--start govuk-!-mt-r2 govuk-!-mb-r8" href="/start" role="button">Start now</a>

This seems complicated for a standard component? Are we doing it right on the Prototype Kit, or can the Start Button component be tweaked somehow to make the code less complex?

Should inputs with active error state be adjusted to remain the same size as inputs without an error?

Potential problem:
When an input has an error it's border is increased from 2px to 4px. This means that input will become physically bigger than it's previous state.

When this input is in-line or part of a tight lockup with another element the component parts will become mis-aligned.

Should we adjust the padding of the input error state to compensate for the increased border?

For example

.govuk-c-input {
        padding: 5px 4px 4px;
}
.govuk-c-input--error {
        padding: 3px 2px 2px;
}

Before | After
screen shot 2017-07-06 at 16 15 39

Is there an alternative way of doing this with box-sizing?

Allow for smaller form fields

Some user interfaces are designed for high information density and regular use. In these cases, smaller form controls may be required.

The Home Office design system already has small versions of radio buttons and checkboxes, we should probably add text fields, select boxes and buttons to that list.

Implementation considerations:

  • is this a modifier class that you can apply to any form component?
  • does the class apply to all form elements inside the component?
  • for text input and select, does the font get smaller too?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.