Skip to content

Commit

Permalink
Bind event handlers on the details summary only
Browse files Browse the repository at this point in the history
This fixes an issue where clicking the revealed content in browsers that do not support the native `details` element causes the details element to collapse. (Fixes #911)

It also fixes an issue in all browsers where clicking the revealed content ‘flips’ the aria-expanded attribute on the summary element and the aria-hidden attribute on the content element, causing them to get out of sync with the visible state of the component.
  • Loading branch information
36degrees committed Jul 17, 2018
1 parent 8f2fe56 commit ff89b79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/details/details.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Details.prototype.init = function () {
}

// Bind an event to handle summary elements
this.handleInputs($module, this.setAttributes.bind(this))
this.handleInputs($summary, this.setAttributes.bind(this))
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/components/details/details.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ describe('/components/details', () => {
expect(detailsOpen).not.toBeNull()
})

it('should not be affected when clicking the revealed content', async () => {
await page.goto(baseUrl + '/components/details/expanded/preview', { waitUntil: 'load' })

await page.click('.govuk-details__text')

const summaryAriaExpanded = await page.evaluate(() => document.body.getElementsByTagName('summary')[0].getAttribute('aria-expanded'))
expect(summaryAriaExpanded).toBe('true')
})

describe('when details is triggered', () => {
it('should indicate the expanded state of the summary using aria-expanded', async () => {
await page.goto(baseUrl + '/components/details/expanded/preview', { waitUntil: 'load' })
Expand Down

0 comments on commit ff89b79

Please sign in to comment.