Skip to content

Commit

Permalink
Merge pull request #621 from alphagov/rpa-handle-query-change
Browse files Browse the repository at this point in the history
Handle query change when the text length does not change
  • Loading branch information
romaricpascal committed Jan 12, 2024
2 parents 180c230 + 58822ea commit 9010b0b
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- [Pull request #621: Handle query change when the text length does not change](https://github.com/alphagov/accessible-autocomplete/pull/621)
- [Pull request #620: Add `className` attribute to status component](https://github.com/alphagov/accessible-autocomplete/pull/620)
- [Pull request #591: Add menuAttributes to fix #361](https://github.com/alphagov/accessible-autocomplete/pull/591)

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.

2 changes: 1 addition & 1 deletion src/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default class Autocomplete extends Component {
const autoselect = this.hasAutoselect()
const query = event.target.value
const queryEmpty = query.length === 0
const queryChanged = this.state.query.length !== query.length
const queryChanged = this.state.query !== query
const queryLongEnough = query.length >= minLength

this.setState({
Expand Down
6 changes: 6 additions & 0 deletions test/functional/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ describe('Autocomplete', () => {
expect(autocomplete.state.menuOpen).to.equal(false)
})

it('searches with the new term when query length changes', () => {
autocomplete.setState({ query: 'fr', options: ['France'] })
autocomplete.handleInputChange({ target: { value: 'fb' } })
expect(autocomplete.state.options.length).to.equal(0)
})

it('removes the aria-describedby attribute when query is non empty', () => {
expect(autocomplete.state.ariaHint).to.equal(true)
autocomplete.handleInputChange({ target: { value: 'a' } })
Expand Down

0 comments on commit 9010b0b

Please sign in to comment.