haya-select 1.0.43 → 1.0.45

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "haya-select",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -39,6 +39,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
39
39
  multiple: PropTypes.bool.isRequired,
40
40
  name: PropTypes.string,
41
41
  onChange: PropTypes.func,
42
+ onChangeValue: PropTypes.func,
42
43
  onOptionsClosed: PropTypes.func,
43
44
  options: PropTypes.oneOfType([PropTypes.array, PropTypes.func]).isRequired,
44
45
  placeholder: PropTypes.node,
@@ -125,7 +126,9 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
125
126
  getValues = () => ("values" in this.props) ? this.p.values : this.s.currentOptions.map((currentOption) => currentOption.value)
126
127
  getCurrentOptions = () => {
127
128
  if ("values" in this.props && typeof this.props.values != "undefined") {
128
- if (this.s.loadedOptions || typeof this.props.options == "function" && this.props.values) {
129
+ if (Array.isArray(this.props.options)) {
130
+ return this.p.values.map((value) => this.p.options.find((option) => option.value == value))
131
+ } else if (this.s.loadedOptions || typeof this.props.options == "function" && this.props.values) {
129
132
  if (this.s.loadedOptions) {
130
133
  const result = this.p.values.map((value) => {
131
134
  let foundOption = this.s.loadedOptions.find((option) => option.value == value)
@@ -134,7 +137,10 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
134
137
  foundOption = this.s.currentOptions.find((option) => option.value == value)
135
138
 
136
139
  if (!foundOption) {
137
- throw new Error(`Couldn't find option: ${value} in loadedOptions or state currentOptions`)
140
+ console.error(
141
+ `Couldn't find option: ${value} in loadedOptions or state currentOptions`,
142
+ {stateLoadedOptions: this.s.loadedOptions, stateCurrentOptions: this.s.currentOptions, propsOptions: this.props.options}
143
+ )
138
144
  }
139
145
  }
140
146
 
@@ -145,8 +151,6 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
145
151
  } else {
146
152
  this.setCurrentFromGivenValues()
147
153
  }
148
- } else if (Array.isArray(this.props.options)) {
149
- return this.p.values.map((value) => this.p.options.find((option) => option.value == value))
150
154
  } else {
151
155
  return this.p.values.map((value) => ({value}))
152
156
  }
@@ -634,7 +638,6 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
634
638
 
635
639
  if (toggleOptions) {
636
640
  // Set fresh toggle
637
-
638
641
  newToggled[loadedOption.value] = toggleOptions[0].value
639
642
  newState.toggled = newToggled
640
643
  }
@@ -646,14 +649,28 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
646
649
  }
647
650
  }
648
651
 
652
+ const options = newState.currentOptions || currentOptions
653
+
649
654
  if (onChange) {
650
655
  onChange({
651
656
  event,
652
- options: newState.currentOptions || currentOptions,
657
+ options,
653
658
  toggles: newToggled
654
659
  })
655
660
  }
656
661
 
662
+ if (this.props.onChangeValue) {
663
+ let optionValue
664
+
665
+ if (multiple) {
666
+ optionValue = options.map((option) => option.value)
667
+ } else {
668
+ optionValue = dig(options, 0, "value")
669
+ }
670
+
671
+ this.p.onChangeValue(optionValue)
672
+ }
673
+
657
674
  if (!multiple) this.closeOptions()
658
675
  this.setState(newState)
659
676
  }