Skip to content

Commit

Permalink
defensive adjustment to setting input value on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
mynamesleon committed Mar 24, 2021
1 parent 434507b commit 525fbf9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

All notable changes to this project will be documented in this file.

## [1.3.1] - 2021-03-22
## [1.3.2] - 2021-03-24

### Changed

- adjusted the `confirmOnBlur` string matching behaviour to used the "cleaned" version of the search term and option label when blurring off of the field without a currently focused menu option.
- defensive adjustment to setting the input value and moving focus to it after the component area is blurred.

## [1.3.0] - 2021-03-07

Expand Down Expand Up @@ -103,6 +104,7 @@ All notable changes to this project will be documented in this file.
- Issue when clicking on a single-select autocomplete with minLength of 0 with a current selection, which was correctly searching with an empty string, but the polling method was then triggering a search with the value afterwards.
- Screen reader announcements for results ignoring the number of results rendered

[1.3.2]: https://github.com/mynamesleon/aria-autocomplete/compare/v1.3.0...v1.3.2
[1.3.0]: https://github.com/mynamesleon/aria-autocomplete/compare/v1.2.3...v1.3.0
[1.2.3]: https://github.com/mynamesleon/aria-autocomplete/compare/v1.2.0...v1.2.3
[1.2.0]: https://github.com/mynamesleon/aria-autocomplete/compare/v1.1.4...v1.2.0
Expand Down
2 changes: 1 addition & 1 deletion dist/aria-autocomplete.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aria-autocomplete",
"version": "1.3.1",
"version": "1.3.2",
"description": "Accessible, extensible, JavaScript autocomplete with multi-select",
"main": "dist/aria-autocomplete.min.js",
"style": "dist/aria-autocomplete.css",
Expand Down
12 changes: 8 additions & 4 deletions src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ export default class Autocomplete {
* set input value to specific string, and related component vars
*/
setInputValue(value?: string, setPollingValue: boolean = false) {
this.input.value = this.term = value;
this.term = value;
if (this.input) {
this.input.value = value;
}
if (setPollingValue) {
this.inputPollingValue = value;
}
Expand Down Expand Up @@ -689,7 +692,7 @@ export default class Autocomplete {
this.announce(`${option.label} ${this.options.srSelectedText}`, 0);

// return focus to input
if (!this.disabled && focusInputAfterSelection !== false) {
if (!this.disabled && focusInputAfterSelection !== false && this.input) {
this.input.focus();
}

Expand Down Expand Up @@ -1204,9 +1207,10 @@ export default class Autocomplete {
// if blurring from an option (currentSelectedIndex > -1), select it
let toUse: number = this.currentSelectedIndex;
if (typeof toUse !== 'number' || toUse === -1) {
// otherwise check for exact match of cleaned values
// otherwise check for exact match of cleaned values
// between current input value and available items
toUse = this.indexOfValueIn.call(this, this.filteredSource, cleanString(this.term), CLEANED_LABEL_PROP);
const cleanedTerm = cleanString(this.term);
toUse = this.indexOfValueIn.call(this, this.filteredSource, cleanedTerm, CLEANED_LABEL_PROP);
}
this.handleOptionSelect({}, toUse, false);
}
Expand Down

0 comments on commit 525fbf9

Please sign in to comment.