Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accordion component #958

Merged
merged 50 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a0e3a5c
Initial port of Accordion component
frankieroberto Jan 4, 2019
a29c419
Refactor to follow JS Standard and GOV.UK Frontend conventions
frankieroberto Jan 4, 2019
ce3507f
Refactor to follow govuk CSS naming convention
frankieroberto Aug 20, 2018
2bdfcd8
Add tests
frankieroberto Aug 20, 2018
493b873
Add $sections in Accordion module
hannalaakso Aug 30, 2018
961b4b4
Set button attributes in separate function
hannalaakso Aug 30, 2018
c2cf60f
Update the macro to allow setting initial state
frankieroberto Oct 11, 2018
80f4703
Add examples and params
hannalaakso Jan 4, 2019
56842f9
Add aria-labelledby relationship
frankieroberto Oct 25, 2018
78ccb57
Accessibility improvements
frankieroberto Oct 25, 2018
6de7352
Rename 'body' to 'panel'
frankieroberto Oct 25, 2018
3bc5f98
Switch to `index` over `index0`
frankieroberto Oct 30, 2018
e421382
Remove region role from panel
frankieroberto Oct 30, 2018
994b7b3
Replace button div with button element
frankieroberto Oct 30, 2018
7eafd31
Ability to specify html in header
frankieroberto Nov 1, 2018
2fbe98f
Adds the state of the accordion panel to sessionStorage so the accord…
injms Nov 6, 2018
41409dc
Add test to check if expanded state is stored
hannalaakso Jan 4, 2019
9d632a7
Add focus style
frankieroberto Nov 6, 2018
a1fc105
Add support for headingLevel param
frankieroberto Nov 6, 2018
95bc46a
Replace background image with inline SVG
frankieroberto Nov 7, 2018
fcd909c
Remove custom enter/space key handling
frankieroberto Nov 8, 2018
6550027
Check if console is available before logging
frankieroberto Nov 15, 2018
0f995a7
Margin and padding adjustments
frankieroberto Nov 16, 2018
7b71ccb
Add visually hidden text to "Open/Close all" button
hannalaakso Dec 11, 2018
a823816
Fix bug of <h2> and <div> inside <h2>
hannalaakso Dec 12, 2018
f58cd8b
Make BEM naming consistent with GOV.UK Frontend
hannalaakso Dec 12, 2018
7be772a
Standardise public API
hannalaakso Dec 12, 2018
0fe008c
Expand focus state to fill the heading
hannalaakso Jan 9, 2019
5fa40af
Add template tests
hannalaakso Dec 17, 2018
89f0b6c
Standardise "with JS" classes
hannalaakso Dec 17, 2018
ee411e6
Fix background button colour on FF adjusted colours view
hannalaakso Dec 17, 2018
6fd81b2
Replaces SVG +/- icon with CSS version.
hannalaakso Jan 9, 2019
245a56c
Fixes "Deep spot" in the header
aliuk2012 Dec 17, 2018
48db868
Add borders to show on no-JS view. Some refactoring.
hannalaakso Dec 17, 2018
3f551f5
Rename "expand-all" to "open-all"
hannalaakso Dec 17, 2018
661b230
Rename all instance of "panel" to "content"
hannalaakso Dec 18, 2018
8552fd2
Fix summary overlapping icon on mobile
hannalaakso Dec 18, 2018
6e0d834
Prefix section classes with "section"
hannalaakso Jan 9, 2019
cf5ffd9
Fix icon not changing colour in FF inverted colours view
hannalaakso Dec 18, 2018
2d29ff0
Update component README
hannalaakso Dec 18, 2018
395380d
Update CHANGELOG
hannalaakso Dec 18, 2018
027373d
Tidy up of `accordion.js`
hannalaakso Dec 19, 2018
a8d77a0
Simplify expanding logic
hannalaakso Jan 3, 2019
81e6b0d
Some general restructuring
hannalaakso Jan 4, 2019
c85f879
Move `govuk-heading-m` styles to scss, remove from template
hannalaakso Jan 4, 2019
cea28fe
Future proof `<span>` to `<button>` code
hannalaakso Jan 3, 2019
04b0ce6
Remove IE8 trigger reflow hack
hannalaakso Jan 3, 2019
c3957c6
fixes IE8 issue with "+/-" icons not being toggled
aliuk2012 Jan 4, 2019
67ae320
Refactors Accordion.js
aliuk2012 Dec 24, 2018
3845701
Store class names in `accordion.js` in `$module`
hannalaakso Jan 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

🆕 New features:

- Pull Request Title goes here
- Accordion component 🎉

Description goes here (optional)
Contributed by @frankieroberto, as well as @injms, @hannalaakso, @joelanman and others.

([PR #N](https://github.com/alphagov/govuk-frontend/pull/N))
The accordion component lets users show and hide sections of related content on a page.

For more information see [guidance](https://design-system.service.gov.uk/components/accordion/).

([PR #958](https://github.com/alphagov/govuk-frontend/pull/958))

- Add desktop specific grid column widths

Expand Down
7 changes: 7 additions & 0 deletions src/all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { nodeListForEach } from './common'
import Accordion from './components/accordion/accordion'
import Button from './components/button/button'
import Details from './components/details/details'
import CharacterCount from './components/character-count/character-count'
Expand All @@ -12,6 +13,12 @@ function initAll () {
// Find all buttons with [role=button] on the document to enhance.
new Button(document).init()

// Find all global accordion components to enhance.
var $accordions = document.querySelectorAll('[data-module="accordion"]')
hannalaakso marked this conversation as resolved.
Show resolved Hide resolved
nodeListForEach($accordions, function ($accordion) {
new Accordion($accordion).init()
})

// Find all global details elements to enhance.
var $details = document.querySelectorAll('details')
nodeListForEach($details, function ($detail) {
Expand Down
1 change: 1 addition & 0 deletions src/components/_all.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "accordion/accordion";
@import "back-link/back-link";
@import "breadcrumbs/breadcrumbs";
@import "button/button";
Expand Down
17 changes: 17 additions & 0 deletions src/components/accordion/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Accordion

## Installation

See the [main README quick start guide](https://github.com/alphagov/govuk-frontend#quick-start) for how to install this component.

## Guidance and Examples

Find out when to use the details component in your service in the [GOV.UK Design System](https://design-system.service.gov.uk/components/accordion).

## Component options

Use options to customise the appearance, content and behaviour of a component when using a macro, for example, changing the text.

`id` option given to instances of the component must be **unique** across the domain of your service (as the expanded state of individual instances of the component persists across page loads using [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)).

See [options table](https://design-system.service.gov.uk/components/accordion/#options-example-default) for details.
173 changes: 173 additions & 0 deletions src/components/accordion/_accordion.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
@import "../../settings/all";
@import "../../tools/all";
@import "../../helpers/all";


@include govuk-exports("govuk/component/accordion") {

.govuk-accordion {
@include govuk-responsive-margin(6, "bottom");
// Border at the bottom of the whole accordion
border-bottom: 1px solid $govuk-border-colour;
}

// Borders between accordion sections
.govuk-accordion__section {
border-top: 1px solid $govuk-border-colour;
}

.govuk-accordion__section-header {
padding-bottom: govuk-spacing(3);
}

.govuk-accordion__section-heading {
margin-top: 0; // Override browser default
margin-bottom: 0; // Override browser default
}
hannalaakso marked this conversation as resolved.
Show resolved Hide resolved

// Buttons within the sections don’t need default styling
.govuk-accordion__section-button {
@include govuk-font($size: 24, $weight: bold);
margin-bottom: 0;
padding-top: govuk-spacing(3);
}

.govuk-accordion__section-summary {
margin-top: govuk-spacing(2);
margin-bottom: 0;
}

// JavaScript enabled
.js-enabled {

// Hide the body of collapsed sections
.govuk-accordion__section-content {
display: none;
@include govuk-responsive-padding(3, "top");
@include govuk-responsive-padding(3, "bottom");
}

// Remove the bottom margin from the last item inside the content
.govuk-accordion__section-content > :last-child {
margin-bottom: 0;
}

// Show the body of expanded sections
.govuk-accordion__section--expanded .govuk-accordion__section-content {
display: block;
}

// This is styled to look like a link not a button
.govuk-accordion__open-all {
@include govuk-font($size: 16);
@include govuk-link-common;
display: inline;
border-width: 0;
color: $govuk-link-colour;
background: none;
cursor: pointer;

&:focus {
background: none;
}
}

// Section headers have a pointer cursor as an additional affordance
.govuk-accordion__section-header {
position: relative;
// Safe area on the right to avoid clashing with icon
padding-right: 40px;
cursor: pointer;
}

// Section headers have a grey background on hover as an additional affodance
.govuk-accordion__section-header:hover {
background-color: govuk-colour("grey-4");
}

// Setting focus styles on header so that summary that is not part of the button is included in focus
.govuk-accordion__section-header--focused {
// These replicate @mixin govuk-focusable (the mixin can't be used as the header doesn't get the focus)
outline: $govuk-focus-width solid $govuk-focus-colour;
outline-offset: 0;
}

// Buttons within the headers don’t need default styling
.govuk-accordion__section-button {
@include govuk-link-common;
width: 100%;
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
padding-top: govuk-spacing(3);
padding-bottom: 0;
padding-left: 0;
border-width: 0;
// Headings in section headers have link colours as an additional affodance
color: $govuk-link-colour;
background: none;
text-align: left;
cursor: pointer;

&:focus {
outline: none;
background: none;
}
}

// Extend the touch area of the button to span the section header
.govuk-accordion__section-button:after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}

.govuk-accordion__controls {
text-align: right;
}

// Display an icon to the right of each header to indicate open/closed status,
// and as an additional affordance.
.govuk-accordion__icon {
position: absolute;
top: 50%;
right: 15px;
width: 16px;
height: 16px;
margin-top: -8px;
}

.govuk-accordion__icon:after,
.govuk-accordion__icon:before {
content: "";
box-sizing: border-box;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 25%;
height: 25%;
margin: auto;
border: 2px solid transparent;
background-color: govuk-colour("black");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be currentColor? That'll mean that when users change their colours it will override as expected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @NickColley. currentColor is not supported by IE8. I've just added in a fix which makes sure that the icon displays for users who change their colours.

}

.govuk-accordion__icon:before {
width: 100%;
}

.govuk-accordion__icon:after {
height: 100%;
}

// Vertical bar should be hidden when section is open, to display a '-' icon
.govuk-accordion__section--expanded .govuk-accordion__icon:after {
content: " ";
display: none;
}
}
}
Loading