haya-select 1.0.42 → 1.0.43

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.42",
3
+ "version": "1.0.43",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -127,7 +127,21 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
127
127
  if ("values" in this.props && typeof this.props.values != "undefined") {
128
128
  if (this.s.loadedOptions || typeof this.props.options == "function" && this.props.values) {
129
129
  if (this.s.loadedOptions) {
130
- return this.p.values.map((value) => this.s.loadedOptions.find((option) => option.value == value))
130
+ const result = this.p.values.map((value) => {
131
+ let foundOption = this.s.loadedOptions.find((option) => option.value == value)
132
+
133
+ if (!foundOption) {
134
+ foundOption = this.s.currentOptions.find((option) => option.value == value)
135
+
136
+ if (!foundOption) {
137
+ throw new Error(`Couldn't find option: ${value} in loadedOptions or state currentOptions`)
138
+ }
139
+ }
140
+
141
+ return foundOption
142
+ })
143
+
144
+ return result
131
145
  } else {
132
146
  this.setCurrentFromGivenValues()
133
147
  }
@@ -141,6 +155,14 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
141
155
  return this.s.currentOptions
142
156
  }
143
157
 
158
+ getCurrentOptionValues() {
159
+ if ("values" in this.props) {
160
+ return this.p.values
161
+ }
162
+
163
+ return this.getCurrentOptions().map((option) => option.value)
164
+ }
165
+
144
166
  componentDidMount() {
145
167
  const {attribute, defaultValue, defaultValues, defaultValuesFromOptions, model, options} = this.props
146
168
 
@@ -382,7 +404,7 @@ export default memo(shapeComponent(class HayaSelect extends ShapeComponent {
382
404
 
383
405
  return (
384
406
  <Option
385
- currentOptions={this.getCurrentOptions()}
407
+ currentOptionValues={this.getCurrentOptionValues()}
386
408
  icon={this.iconForOption(loadedOption)}
387
409
  key={key}
388
410
  option={loadedOption}
@@ -5,7 +5,7 @@ import {View} from "react-native"
5
5
 
6
6
  export default memo(shapeComponent(class Option extends ShapeComponent {
7
7
  static propTypes = {
8
- currentOptions: PropTypes.array.isRequired,
8
+ currentOptionValues: PropTypes.array.isRequired,
9
9
  disabled: PropTypes.bool,
10
10
  icon: PropTypes.string,
11
11
  onOptionClicked: PropTypes.func.isRequired,
@@ -20,8 +20,9 @@ export default memo(shapeComponent(class Option extends ShapeComponent {
20
20
  }
21
21
 
22
22
  render() {
23
- const disabled = Boolean(this.props.option.disabled)
24
- const selected = Boolean(this.props.currentOptions.find((currentOption) => currentOption.value == this.props.option.value))
23
+ const {currentOptionValues, option} = this.p
24
+ const disabled = Boolean(option.disabled)
25
+ const selected = Boolean(currentOptionValues.find((currentOptionValue) => currentOptionValue == option.value))
25
26
  const style = {
26
27
  paddingTop: 4,
27
28
  paddingRight: 8,
@@ -53,12 +54,12 @@ export default memo(shapeComponent(class Option extends ShapeComponent {
53
54
  selected,
54
55
  value: this.props.option.value
55
56
  }}
56
- onClick={this.onClick}
57
- onPointerOver={this.onPointerOver}
58
- onPointerOut={this.onPointerOut}
57
+ onClick={this.tt.onClick}
58
+ onPointerOver={this.tt.onPointerOver}
59
+ onPointerOut={this.tt.onPointerOut}
59
60
  style={style}
60
61
  >
61
- {this.props.presentOption(this.props.option)}
62
+ {this.props.presentOption(option)}
62
63
  </View>
63
64
  )
64
65
  }