Skip to content

Commit

Permalink
Merge pull request #379 from alphagov/fix-fixed-ids
Browse files Browse the repository at this point in the history
Ensure multiple autocompletes on one page do not have conflicting id attributes
  • Loading branch information
NickColley authored Sep 27, 2019
2 parents 35b5556 + 0a112a1 commit 896dd9e
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Unreleased

## Fixes

- [Pull request #379: Ensure multiple autocompletes on one page do not have conflicting id attributes](https://github.com/alphagov/accessible-autocomplete/pull/379)

## 2.0.0 - 2019-09-26

We recommend you update to the latest release using npm:
Expand Down
2 changes: 1 addition & 1 deletion dist/accessible-autocomplete.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/accessible-autocomplete.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.preact.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.preact.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.react.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lib/accessible-autocomplete.react.min.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,9 @@ export default class Autocomplete extends Component {
: ''
const showHint = hasPointerEvents && hintValue

const assistiveHintID = id + '__assistiveHint'
const ariaDescribedProp = (ariaHint) ? {
'aria-describedby': 'assistiveHint'
'aria-describedby': assistiveHintID
} : null

let dropdownArrow
Expand All @@ -474,6 +475,7 @@ export default class Autocomplete extends Component {
return (
<div className={wrapperClassName} onKeyDown={this.handleKeyDown}>
<Status
id={id}
length={options.length}
queryLength={query.length}
minQueryLength={minLength}
Expand Down Expand Up @@ -555,7 +557,7 @@ export default class Autocomplete extends Component {
)}
</ul>

<span id='assistiveHint' style={{ display: 'none' }}>{tAssistiveHint()}</span>
<span id={assistiveHintID} style={{ display: 'none' }}>{tAssistiveHint()}</span>

</div>
)
Expand Down
5 changes: 3 additions & 2 deletions src/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class Status extends Component {

render () {
const {
id,
length,
queryLength,
minQueryLength,
Expand Down Expand Up @@ -98,14 +99,14 @@ export default class Status extends Component {
width: '1px'
}}>
<div
id='ariaLiveA'
id={id + '__status--A'}
role='status'
aria-atomic='true'
aria-live='polite'>
{(!silenced && debounced && bump) ? content : ''}
</div>
<div
id='ariaLiveB'
id={id + '__status--B'}
role='status'
aria-atomic='true'
aria-live='polite'>
Expand Down
4 changes: 2 additions & 2 deletions test/functional/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ describe('Autocomplete', () => {
})

it('renders with an aria-describedby attribute', () => {
render(<Autocomplete required />, scratch)
render(<Autocomplete id='autocomplete-default' />, scratch)

let wrapperElement = scratch.getElementsByClassName('autocomplete__wrapper')[0]
let inputElement = wrapperElement.getElementsByTagName('input')[0]

expect(inputElement.getAttribute('aria-describedby')).to.equal('assistiveHint')
expect(inputElement.getAttribute('aria-describedby')).to.equal('autocomplete-default__assistiveHint')
})

describe('renders with an aria-autocomplete attribute', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const basicExample = () => {
// in Chrome
if (isChrome) {
it('should announce status changes using two alternately updated aria live regions', () => {
const flip = browser.$('div#ariaLiveA')
const flop = browser.$('div#ariaLiveB')
const flip = browser.$('#autocomplete-default__status--A')
const flop = browser.$('#autocomplete-default__status--B')

browser.click(input)
browser.setValue(input, 'a')
Expand Down

0 comments on commit 896dd9e

Please sign in to comment.