Skip to content

Commit

Permalink
Merge pull request #916 from alphagov/fix-global-tabs-class-name
Browse files Browse the repository at this point in the history
Replace global `js-hidden` class with tabs panel modifier
  • Loading branch information
NickColley committed Jul 17, 2018
2 parents 7c3f0a2 + c74b1ad commit 94f3cb7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@

🔧 Fixes:

- Pull Request Title goes here

Description goes here (optional)

([PR #N](https://github.com/alphagov/govuk-frontend/pull/N))
- Replace conflicting `js-hidden` class used within the tabs component with a new modifier class.
Because this class is defined and used within the JavaScript, no markup changes are required.
([PR #916](https://github.com/alphagov/govuk-frontend/pull/916))


## 1.1.1 (fix release)
Expand Down
8 changes: 4 additions & 4 deletions src/components/tabs/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@
border: 1px solid $govuk-border-colour;
border-top: 0;

&--hidden {
display: none;
}

& > :last-child {
margin-bottom: 0;
}
}
}

}

.js-hidden {
display: none;
}
}
2 changes: 1 addition & 1 deletion src/components/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Tabs ($module) {
this.$tabs = $module.querySelectorAll('.govuk-tabs__tab')

this.keys = { left: 37, right: 39, up: 38, down: 40 }
this.jsHiddenClass = 'js-hidden'
this.jsHiddenClass = 'govuk-tabs__panel--hidden'
}

Tabs.prototype.init = function () {
Expand Down
10 changes: 5 additions & 5 deletions src/components/tabs/tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ describe('/components/tabs', () => {
it('should display the first tab panel', async () => {
await page.goto(baseUrl + '/components/tabs/preview', { waitUntil: 'load' })

const tabPanelIsHidden = await page.evaluate(() => document.body.querySelector('.govuk-tabs > .govuk-tabs__panel').classList.contains('js-hidden'))
const tabPanelIsHidden = await page.evaluate(() => document.body.querySelector('.govuk-tabs > .govuk-tabs__panel').classList.contains('govuk-tabs__panel--hidden'))
expect(tabPanelIsHidden).toBeFalsy()
})

it('should hide all the tab panels except for the first one', async () => {
await page.goto(baseUrl + '/components/tabs/preview', { waitUntil: 'load' })

const tabPanelIsHidden = await page.evaluate(() => document.body.querySelector('.govuk-tabs > .govuk-tabs__panel ~ .govuk-tabs__panel').classList.contains('js-hidden'))
const tabPanelIsHidden = await page.evaluate(() => document.body.querySelector('.govuk-tabs > .govuk-tabs__panel ~ .govuk-tabs__panel').classList.contains('govuk-tabs__panel--hidden'))
expect(tabPanelIsHidden).toBeTruthy()
})
})
Expand All @@ -78,7 +78,7 @@ describe('/components/tabs', () => {

const secondTabPanelIsHidden = await page.evaluate(() => {
const secondTabAriaControls = document.body.querySelector('.govuk-tabs__list-item:nth-child(2) .govuk-tabs__tab').getAttribute('aria-controls')
return document.body.querySelector(`[id="${secondTabAriaControls}"]`).classList.contains('js-hidden')
return document.body.querySelector(`[id="${secondTabAriaControls}"]`).classList.contains('govuk-tabs__panel--hidden')
})
expect(secondTabPanelIsHidden).toBeFalsy()
})
Expand All @@ -105,7 +105,7 @@ describe('/components/tabs', () => {

const secondTabPanelIsHidden = await page.evaluate(() => {
const secondTabAriaControls = document.body.querySelector('.govuk-tabs__list-item:nth-child(2) .govuk-tabs__tab').getAttribute('aria-controls')
return document.body.querySelector(`[id="${secondTabAriaControls}"]`).classList.contains('js-hidden')
return document.body.querySelector(`[id="${secondTabAriaControls}"]`).classList.contains('govuk-tabs__panel--hidden')
})
expect(secondTabPanelIsHidden).toBeFalsy()
})
Expand All @@ -118,7 +118,7 @@ describe('/components/tabs', () => {
const currentTabAriaSelected = await page.evaluate(() => document.body.querySelector('.govuk-tabs__tab[href="#past-week"]').getAttribute('aria-selected'))
expect(currentTabAriaSelected).toEqual('true')

const currentTabPanelIsHidden = await page.evaluate(() => document.getElementById('past-week').classList.contains('js-hidden'))
const currentTabPanelIsHidden = await page.evaluate(() => document.getElementById('past-week').classList.contains('govuk-tabs__panel--hidden'))
expect(currentTabPanelIsHidden).toBeFalsy()
})
})
Expand Down

0 comments on commit 94f3cb7

Please sign in to comment.