@ministryofjustice/hmpps-connect-dps-shared-items 4.2.2 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -51,7 +51,7 @@ export class AutosuggestUi {
51
51
  this.resultOptions = []
52
52
  this.data = []
53
53
  this.numberOfResults = 0
54
- this.highlightedResultIndex = 0
54
+ this.highlightedResultIndex = null
55
55
  this.blurring = false
56
56
  this.blurTimeout = null
57
57
  this.scrolling = false
@@ -243,6 +243,7 @@ export class AutosuggestUi {
243
243
  this.context.classList.remove(`${this.stylingBaseClass}${classSuffixHasResults}`)
244
244
  this.input.removeAttribute('aria-activedescendant')
245
245
  this.input.setAttribute('aria-expanded', false)
246
+ this.setHighlightedResult(null)
246
247
  this.setAriaStatus()
247
248
  }
248
249
 
@@ -260,7 +261,7 @@ export class AutosuggestUi {
260
261
  return listElement
261
262
  }) ?? []
262
263
 
263
- this.setHighlightedResult(0)
264
+ this.setHighlightedResult(null)
264
265
  this.input.setAttribute('aria-expanded', this.numberOfResults ? 'true' : 'false')
265
266
 
266
267
  if (!!this.numberOfResults && this.sanitisedQuery.length >= this.minChars) {
@@ -322,9 +323,11 @@ export class AutosuggestUi {
322
323
 
323
324
  if (this.highlightedResultIndex === null) {
324
325
  this.input.removeAttribute('aria-activedescendant')
325
- } else if (this.numberOfResults) {
326
+ }
327
+
328
+ if (this.numberOfResults) {
326
329
  this.resultOptions.forEach((option, optionIndex) => {
327
- if (optionIndex === index) {
330
+ if (index !== null && optionIndex === index) {
328
331
  if (this.isAboveViewport(option)) {
329
332
  this.handleScroll(option, true)
330
333
  }
@@ -347,7 +350,12 @@ export class AutosuggestUi {
347
350
  selectResult(index) {
348
351
  if (!this.results.length) return
349
352
 
350
- const result = this.results[index || this.highlightedResultIndex || 0]
353
+ const selectedIndex = typeof index === 'number' ? index : this.highlightedResultIndex
354
+ if (selectedIndex === null || selectedIndex === undefined) return
355
+
356
+ const result = this.results[selectedIndex]
357
+ if (!result) return
358
+
351
359
  this.onSelect(result)
352
360
  this.clearListbox()
353
361
  this.setAriaStatus(`${this.ariaYouHaveSelected}: ${result.displayText}.`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-connect-dps-shared-items",
3
- "version": "4.2.2",
3
+ "version": "4.3.0",
4
4
  "description": "A package to share Connect DPS functionality across applications",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.esm.js",
@@ -63,9 +63,9 @@
63
63
  "jest-html-reporter": "^4.4.0",
64
64
  "jest-junit": "^17.0.0",
65
65
  "lint-staged": "^17.2.0",
66
- "nock": "14.0.16",
67
- "rollup": "4.62.3",
68
- "rollup-plugin-dts": "6.4.1",
66
+ "nock": "14.0.17",
67
+ "rollup": "4.62.4",
68
+ "rollup-plugin-dts": "6.5.1",
69
69
  "ts-jest": "29.4.12",
70
70
  "tslib": "^2.8.1",
71
71
  "typescript": "6.0.3"