hotwire_combobox 0.1.34 → 0.1.35

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d3bf6f83f984a36fb6e0491f68a71c9386c3f2a00e6b6082cd490b73e58d652d
4
- data.tar.gz: db089a58628fa02b4a173f18053a9a81a21402eeafdcfb943d403989597bf314
3
+ metadata.gz: 4b9f936869948e6767d3cdf4f02f226bfe4c3954d57172b37388239884b69ae6
4
+ data.tar.gz: b5495f56d66183c5ebb6c54a6a8e5278391df921f304b36b9da9ffb3bf752576
5
5
  SHA512:
6
- metadata.gz: '0483ae80475b1d52b9b74d21c5749ee0300914954f74e40267de50cfb96dbb77e44a8bdfb5448caf9d743798e2621d678986927c5f201c40052e049c2844a13f'
7
- data.tar.gz: 594db1df1c85dd096ca2cebf2ff9a7dc6564e061aee5f4403729eb94eaf55ab587f32ea620b0f359bd5f1c41e2e4c70096fb5ef04230a07ee13d6cda7873cd33
6
+ metadata.gz: 7bb2f124171055bc2b46c7584f31b3ae6426979dd9485645e8364bef559aa86cfa905f62f0db47e79d48db98f42d422b9c8fd9f342729e7da4704385d8544e3b
7
+ data.tar.gz: 27e49fa1cfd828d23f7dcf82b75a2ba7d7edc4adc8fcff88d35cab8cc41e666f39dffb82209c68740e8b4d9ec9236b1db3513e7c2952cf80cf6f96dc7608a39e
@@ -73,10 +73,10 @@ export default class HwComboboxController extends Concerns(...concerns) {
73
73
  endOfOptionsStreamTargetConnected(element) {
74
74
  const inputType = element.dataset.inputType
75
75
 
76
- this._preselectOption()
77
-
78
- if (inputType) {
76
+ if (inputType && inputType !== "hw:ensureSelection") {
79
77
  this._commitFilter({ inputType })
78
+ } else {
79
+ this._preselectOption()
80
80
  }
81
81
  }
82
82
  }
@@ -1,5 +1,3 @@
1
- export const nullEvent = new Event("NULL")
2
-
3
1
  export function Concerns(Base, ...mixins) {
4
2
  return mixins.reduce((accumulator, current) => current(accumulator), Base)
5
3
  }
@@ -39,7 +37,7 @@ export function startsWith(string, substring) {
39
37
  return string.toLowerCase().startsWith(substring.toLowerCase())
40
38
  }
41
39
 
42
- export function debounce(fn, delay = 150) {
40
+ export function debounce(fn, delay = 300) {
43
41
  let timeoutId = null
44
42
 
45
43
  return (...args) => {
@@ -48,7 +48,7 @@ Combobox.Filtering = Base => class extends Base {
48
48
  // Consider +_query+ will contain the full autocompleted value
49
49
  // after a certain point in the call chain.
50
50
  get _query() {
51
- return this._actingCombobox.value.trim()
51
+ return this._actingCombobox.value
52
52
  }
53
53
 
54
54
  set _query(value) {
@@ -1,5 +1,5 @@
1
1
  import Combobox from "hw_combobox/models/combobox/base"
2
- import { wrapAroundAccess, nullEvent } from "hw_combobox/helpers"
2
+ import { wrapAroundAccess } from "hw_combobox/helpers"
3
3
 
4
4
  Combobox.Selection = Base => class extends Base {
5
5
  selectOption(event) {
@@ -32,8 +32,6 @@ Combobox.Selection = Base => class extends Base {
32
32
  if (selected) {
33
33
  this.hiddenFieldTarget.value = option.dataset.value
34
34
  option.scrollIntoView({ block: "nearest" })
35
- } else {
36
- this.hiddenFieldTarget.value = null
37
35
  }
38
36
  }
39
37
 
@@ -48,6 +46,7 @@ Combobox.Selection = Base => class extends Base {
48
46
  _deselect() {
49
47
  const option = this._selectedOptionElement
50
48
  if (option) this._commitSelection(option, { selected: false })
49
+ this.hiddenFieldTarget.value = null
51
50
  }
52
51
 
53
52
  _selectNew() {
@@ -71,10 +70,10 @@ Combobox.Selection = Base => class extends Base {
71
70
  }
72
71
  }
73
72
 
74
- _selectFuzzyMatch() {
75
- if (this._isFuzzyMatch) {
76
- this._select(this._visibleOptionElements[0], { force: true })
77
- this.filter(nullEvent)
73
+ _ensureSelection() {
74
+ if (this._shouldEnsureSelection) {
75
+ this._select(this._ensurableOption, { force: true })
76
+ this.filter({ inputType: "hw:ensureSelection" })
78
77
  }
79
78
  }
80
79
 
@@ -82,7 +81,11 @@ Combobox.Selection = Base => class extends Base {
82
81
  return this.hiddenFieldTarget.value && !this._selectedOptionElement
83
82
  }
84
83
 
85
- get _isFuzzyMatch() {
86
- return this._isQueried && !!this._visibleOptionElements[0] && !this._isNewOptionWithPotentialMatches
84
+ get _shouldEnsureSelection() {
85
+ return this._isQueried && !!this._ensurableOption && !this._isNewOptionWithPotentialMatches
86
+ }
87
+
88
+ get _ensurableOption() {
89
+ return this._selectedOptionElement || this._visibleOptionElements[0]
87
90
  }
88
91
  }
@@ -50,10 +50,6 @@ Combobox.Toggle = Base => class extends Base {
50
50
  return clientX >= left && clientX <= right && clientY >= top && clientY <= bottom
51
51
  }
52
52
 
53
- _ensureSelection() {
54
- this._selectFuzzyMatch()
55
- }
56
-
57
53
  _openByFocusing() {
58
54
  this._actingCombobox.focus()
59
55
  }
@@ -1,3 +1,3 @@
1
1
  module HotwireCombobox
2
- VERSION = "0.1.34"
2
+ VERSION = "0.1.35"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire_combobox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.34
4
+ version: 0.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose Farias