@hero-design/rn 8.92.0 → 8.92.1

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.
@@ -863,6 +863,600 @@ exports[`OptionList render isLoading correctly 1`] = `
863
863
  </View>
864
864
  `;
865
865
 
866
+ exports[`OptionList render object value correctly 1`] = `
867
+ <View
868
+ style={
869
+ {
870
+ "flex": 1,
871
+ }
872
+ }
873
+ >
874
+ <RCTScrollView
875
+ ListFooterComponent={null}
876
+ data={
877
+ [
878
+ {
879
+ "category": "A",
880
+ "data": [
881
+ {
882
+ "text": "Item 1",
883
+ "value": {
884
+ "id": "1",
885
+ "label": "Item 1",
886
+ },
887
+ },
888
+ ],
889
+ },
890
+ {
891
+ "category": "B",
892
+ "data": [
893
+ {
894
+ "text": "Item 2",
895
+ "value": {
896
+ "id": "2",
897
+ "label": "Item 2",
898
+ },
899
+ },
900
+ ],
901
+ },
902
+ ]
903
+ }
904
+ getItem={[Function]}
905
+ getItemCount={[Function]}
906
+ keyExtractor={[Function]}
907
+ onContentSizeChange={[Function]}
908
+ onEndReached={[Function]}
909
+ onEndReachedThreshold={0.1}
910
+ onLayout={[Function]}
911
+ onMomentumScrollBegin={[Function]}
912
+ onMomentumScrollEnd={[Function]}
913
+ onScroll={[Function]}
914
+ onScrollBeginDrag={[Function]}
915
+ onScrollEndDrag={[Function]}
916
+ renderItem={[Function]}
917
+ scrollEventThrottle={0.0001}
918
+ stickyHeaderIndices={
919
+ [
920
+ 0,
921
+ 3,
922
+ ]
923
+ }
924
+ style={
925
+ [
926
+ {
927
+ "paddingHorizontal": 12,
928
+ },
929
+ [
930
+ {
931
+ "paddingBottom": 16,
932
+ },
933
+ {},
934
+ ],
935
+ ]
936
+ }
937
+ >
938
+ <View>
939
+ <View
940
+ onFocusCapture={[Function]}
941
+ onLayout={[Function]}
942
+ style={null}
943
+ >
944
+ <View
945
+ style={
946
+ [
947
+ {
948
+ "alignContent": "center",
949
+ "backgroundColor": "#f6f6f7",
950
+ "display": "flex",
951
+ "flexDirection": "row",
952
+ "justifyContent": "space-between",
953
+ "marginBottom": 16,
954
+ "paddingHorizontal": 16,
955
+ "paddingVertical": 8,
956
+ },
957
+ {
958
+ "marginBottom": 0,
959
+ },
960
+ ]
961
+ }
962
+ themeSize="medium"
963
+ >
964
+ <View
965
+ style={
966
+ [
967
+ {
968
+ "alignItems": "center",
969
+ "display": "flex",
970
+ "flexDirection": "row",
971
+ },
972
+ undefined,
973
+ ]
974
+ }
975
+ >
976
+ <View
977
+ style={
978
+ [
979
+ {
980
+ "marginRight": 12,
981
+ },
982
+ undefined,
983
+ ]
984
+ }
985
+ />
986
+ <Text
987
+ allowFontScaling={false}
988
+ style={
989
+ [
990
+ {
991
+ "color": "#001f23",
992
+ "fontFamily": "BeVietnamPro-Regular",
993
+ "fontSize": 14,
994
+ "letterSpacing": 0.48,
995
+ "lineHeight": 22,
996
+ },
997
+ undefined,
998
+ ]
999
+ }
1000
+ themeIntent="body"
1001
+ themeTypeface="neutral"
1002
+ themeVariant="small"
1003
+ >
1004
+ A
1005
+ </Text>
1006
+ </View>
1007
+ </View>
1008
+ </View>
1009
+ <View
1010
+ onFocusCapture={[Function]}
1011
+ onLayout={[Function]}
1012
+ style={null}
1013
+ >
1014
+ <View>
1015
+ <View
1016
+ highlighted={false}
1017
+ section={
1018
+ {
1019
+ "category": "A",
1020
+ "data": [
1021
+ {
1022
+ "text": "Item 1",
1023
+ "value": {
1024
+ "id": "1",
1025
+ "label": "Item 1",
1026
+ },
1027
+ },
1028
+ ],
1029
+ }
1030
+ }
1031
+ style={
1032
+ [
1033
+ {
1034
+ "marginTop": 12,
1035
+ },
1036
+ undefined,
1037
+ ]
1038
+ }
1039
+ trailingItem={
1040
+ {
1041
+ "text": "Item 1",
1042
+ "value": {
1043
+ "id": "1",
1044
+ "label": "Item 1",
1045
+ },
1046
+ }
1047
+ }
1048
+ trailingSection={
1049
+ {
1050
+ "category": "B",
1051
+ "data": [
1052
+ {
1053
+ "text": "Item 2",
1054
+ "value": {
1055
+ "id": "2",
1056
+ "label": "Item 2",
1057
+ },
1058
+ },
1059
+ ],
1060
+ }
1061
+ }
1062
+ />
1063
+ <View
1064
+ accessibilityState={
1065
+ {
1066
+ "disabled": false,
1067
+ }
1068
+ }
1069
+ accessibilityValue={
1070
+ {
1071
+ "max": undefined,
1072
+ "min": undefined,
1073
+ "now": undefined,
1074
+ "text": undefined,
1075
+ }
1076
+ }
1077
+ accessible={true}
1078
+ focusable={true}
1079
+ onClick={[Function]}
1080
+ onResponderGrant={[Function]}
1081
+ onResponderMove={[Function]}
1082
+ onResponderRelease={[Function]}
1083
+ onResponderTerminate={[Function]}
1084
+ onResponderTerminationRequest={[Function]}
1085
+ onStartShouldSetResponder={[Function]}
1086
+ style={
1087
+ [
1088
+ {
1089
+ "alignItems": "center",
1090
+ "backgroundColor": undefined,
1091
+ "borderRadius": 4,
1092
+ "flexDirection": "row",
1093
+ "opacity": 1,
1094
+ "padding": 16,
1095
+ },
1096
+ undefined,
1097
+ ]
1098
+ }
1099
+ >
1100
+ <View
1101
+ style={
1102
+ [
1103
+ {
1104
+ "flex": 1,
1105
+ },
1106
+ undefined,
1107
+ ]
1108
+ }
1109
+ >
1110
+ <Text
1111
+ allowFontScaling={false}
1112
+ style={
1113
+ [
1114
+ {
1115
+ "color": "#001f23",
1116
+ "fontFamily": "BeVietnamPro-Regular",
1117
+ "fontSize": 16,
1118
+ "letterSpacing": 0.48,
1119
+ "lineHeight": 24,
1120
+ },
1121
+ undefined,
1122
+ ]
1123
+ }
1124
+ themeIntent="body"
1125
+ themeTypeface="neutral"
1126
+ themeVariant="regular"
1127
+ >
1128
+ Item 1
1129
+ </Text>
1130
+ </View>
1131
+ </View>
1132
+ <View
1133
+ highlighted={false}
1134
+ leadingItem={
1135
+ {
1136
+ "text": "Item 1",
1137
+ "value": {
1138
+ "id": "1",
1139
+ "label": "Item 1",
1140
+ },
1141
+ }
1142
+ }
1143
+ section={
1144
+ {
1145
+ "category": "A",
1146
+ "data": [
1147
+ {
1148
+ "text": "Item 1",
1149
+ "value": {
1150
+ "id": "1",
1151
+ "label": "Item 1",
1152
+ },
1153
+ },
1154
+ ],
1155
+ }
1156
+ }
1157
+ style={
1158
+ [
1159
+ {
1160
+ "marginTop": 12,
1161
+ },
1162
+ undefined,
1163
+ ]
1164
+ }
1165
+ trailingSection={
1166
+ {
1167
+ "category": "B",
1168
+ "data": [
1169
+ {
1170
+ "text": "Item 2",
1171
+ "value": {
1172
+ "id": "2",
1173
+ "label": "Item 2",
1174
+ },
1175
+ },
1176
+ ],
1177
+ }
1178
+ }
1179
+ />
1180
+ </View>
1181
+ </View>
1182
+ <View
1183
+ onFocusCapture={[Function]}
1184
+ onLayout={[Function]}
1185
+ style={null}
1186
+ />
1187
+ <View
1188
+ onFocusCapture={[Function]}
1189
+ onLayout={[Function]}
1190
+ style={null}
1191
+ >
1192
+ <View
1193
+ style={
1194
+ [
1195
+ {
1196
+ "alignContent": "center",
1197
+ "backgroundColor": "#f6f6f7",
1198
+ "display": "flex",
1199
+ "flexDirection": "row",
1200
+ "justifyContent": "space-between",
1201
+ "marginBottom": 16,
1202
+ "paddingHorizontal": 16,
1203
+ "paddingVertical": 8,
1204
+ },
1205
+ {
1206
+ "marginBottom": 0,
1207
+ },
1208
+ ]
1209
+ }
1210
+ themeSize="medium"
1211
+ >
1212
+ <View
1213
+ style={
1214
+ [
1215
+ {
1216
+ "alignItems": "center",
1217
+ "display": "flex",
1218
+ "flexDirection": "row",
1219
+ },
1220
+ undefined,
1221
+ ]
1222
+ }
1223
+ >
1224
+ <View
1225
+ style={
1226
+ [
1227
+ {
1228
+ "marginRight": 12,
1229
+ },
1230
+ undefined,
1231
+ ]
1232
+ }
1233
+ />
1234
+ <Text
1235
+ allowFontScaling={false}
1236
+ style={
1237
+ [
1238
+ {
1239
+ "color": "#001f23",
1240
+ "fontFamily": "BeVietnamPro-Regular",
1241
+ "fontSize": 14,
1242
+ "letterSpacing": 0.48,
1243
+ "lineHeight": 22,
1244
+ },
1245
+ undefined,
1246
+ ]
1247
+ }
1248
+ themeIntent="body"
1249
+ themeTypeface="neutral"
1250
+ themeVariant="small"
1251
+ >
1252
+ B
1253
+ </Text>
1254
+ </View>
1255
+ </View>
1256
+ </View>
1257
+ <View
1258
+ onFocusCapture={[Function]}
1259
+ onLayout={[Function]}
1260
+ style={null}
1261
+ >
1262
+ <View>
1263
+ <View
1264
+ highlighted={false}
1265
+ leadingSection={
1266
+ {
1267
+ "category": "A",
1268
+ "data": [
1269
+ {
1270
+ "text": "Item 1",
1271
+ "value": {
1272
+ "id": "1",
1273
+ "label": "Item 1",
1274
+ },
1275
+ },
1276
+ ],
1277
+ }
1278
+ }
1279
+ section={
1280
+ {
1281
+ "category": "B",
1282
+ "data": [
1283
+ {
1284
+ "text": "Item 2",
1285
+ "value": {
1286
+ "id": "2",
1287
+ "label": "Item 2",
1288
+ },
1289
+ },
1290
+ ],
1291
+ }
1292
+ }
1293
+ style={
1294
+ [
1295
+ {
1296
+ "marginTop": 12,
1297
+ },
1298
+ undefined,
1299
+ ]
1300
+ }
1301
+ trailingItem={
1302
+ {
1303
+ "text": "Item 2",
1304
+ "value": {
1305
+ "id": "2",
1306
+ "label": "Item 2",
1307
+ },
1308
+ }
1309
+ }
1310
+ />
1311
+ <View
1312
+ accessibilityState={
1313
+ {
1314
+ "disabled": false,
1315
+ }
1316
+ }
1317
+ accessibilityValue={
1318
+ {
1319
+ "max": undefined,
1320
+ "min": undefined,
1321
+ "now": undefined,
1322
+ "text": undefined,
1323
+ }
1324
+ }
1325
+ accessible={true}
1326
+ focusable={true}
1327
+ onClick={[Function]}
1328
+ onResponderGrant={[Function]}
1329
+ onResponderMove={[Function]}
1330
+ onResponderRelease={[Function]}
1331
+ onResponderTerminate={[Function]}
1332
+ onResponderTerminationRequest={[Function]}
1333
+ onStartShouldSetResponder={[Function]}
1334
+ style={
1335
+ [
1336
+ {
1337
+ "alignItems": "center",
1338
+ "backgroundColor": "#ffffff",
1339
+ "borderRadius": 4,
1340
+ "flexDirection": "row",
1341
+ "opacity": 1,
1342
+ "padding": 16,
1343
+ },
1344
+ undefined,
1345
+ ]
1346
+ }
1347
+ >
1348
+ <View
1349
+ style={
1350
+ [
1351
+ {
1352
+ "flex": 1,
1353
+ },
1354
+ undefined,
1355
+ ]
1356
+ }
1357
+ >
1358
+ <Text
1359
+ allowFontScaling={false}
1360
+ style={
1361
+ [
1362
+ {
1363
+ "color": "#001f23",
1364
+ "fontFamily": "BeVietnamPro-Regular",
1365
+ "fontSize": 16,
1366
+ "letterSpacing": 0.48,
1367
+ "lineHeight": 24,
1368
+ },
1369
+ undefined,
1370
+ ]
1371
+ }
1372
+ themeIntent="body"
1373
+ themeTypeface="neutral"
1374
+ themeVariant="regular"
1375
+ >
1376
+ Item 2
1377
+ </Text>
1378
+ </View>
1379
+ </View>
1380
+ <View
1381
+ highlighted={false}
1382
+ leadingItem={
1383
+ {
1384
+ "text": "Item 2",
1385
+ "value": {
1386
+ "id": "2",
1387
+ "label": "Item 2",
1388
+ },
1389
+ }
1390
+ }
1391
+ leadingSection={
1392
+ {
1393
+ "category": "A",
1394
+ "data": [
1395
+ {
1396
+ "text": "Item 1",
1397
+ "value": {
1398
+ "id": "1",
1399
+ "label": "Item 1",
1400
+ },
1401
+ },
1402
+ ],
1403
+ }
1404
+ }
1405
+ section={
1406
+ {
1407
+ "category": "B",
1408
+ "data": [
1409
+ {
1410
+ "text": "Item 2",
1411
+ "value": {
1412
+ "id": "2",
1413
+ "label": "Item 2",
1414
+ },
1415
+ },
1416
+ ],
1417
+ }
1418
+ }
1419
+ style={
1420
+ [
1421
+ {
1422
+ "marginTop": 12,
1423
+ },
1424
+ undefined,
1425
+ ]
1426
+ }
1427
+ />
1428
+ </View>
1429
+ </View>
1430
+ <View
1431
+ onFocusCapture={[Function]}
1432
+ onLayout={[Function]}
1433
+ style={null}
1434
+ />
1435
+ </View>
1436
+ </RCTScrollView>
1437
+ <View
1438
+ pointerEvents="box-none"
1439
+ position="bottom"
1440
+ style={
1441
+ [
1442
+ {
1443
+ "bottom": 0,
1444
+ "elevation": 9999,
1445
+ "flexDirection": "column-reverse",
1446
+ "left": 0,
1447
+ "paddingHorizontal": 24,
1448
+ "paddingVertical": 16,
1449
+ "position": "absolute",
1450
+ "right": 0,
1451
+ "top": 0,
1452
+ },
1453
+ undefined,
1454
+ ]
1455
+ }
1456
+ />
1457
+ </View>
1458
+ `;
1459
+
866
1460
  exports[`OptionList renders correctly 1`] = `
867
1461
  <View
868
1462
  style={
@@ -267,6 +267,32 @@ describe('rendering', () => {
267
267
  expect(getByText('Monday')).toBeTruthy();
268
268
  expect(toJSON()).toMatchSnapshot();
269
269
  });
270
+
271
+ it('renders correct value when value is an object', () => {
272
+ const optionsWithObjectValue = [
273
+ {
274
+ value: { id: '1', label: 'Item 1' },
275
+ text: 'Option with object value 1',
276
+ },
277
+ {
278
+ value: { id: '2', label: 'Item 2' },
279
+ text: 'Option with object value 2',
280
+ },
281
+ ];
282
+ const { getByText, getByTestId } = renderWithTheme(
283
+ <SingleSelect
284
+ options={optionsWithObjectValue}
285
+ value={optionsWithObjectValue[0].value}
286
+ onConfirm={jest.fn()}
287
+ label="Select an item"
288
+ />
289
+ );
290
+
291
+ fireEvent.press(getByTestId('text-input'));
292
+
293
+ expect(getByText('Option with object value 1')).toBeVisible();
294
+ expect(getByText('Option with object value 2')).toBeVisible();
295
+ });
270
296
  });
271
297
 
272
298
  describe('behavior', () => {
@@ -7,6 +7,7 @@ import { TouchableOpacity, View } from 'react-native';
7
7
  import BottomSheet from '../../BottomSheet';
8
8
  import TextInput from '../../TextInput';
9
9
  import {
10
+ deepCompareValue,
10
11
  getScrollParams,
11
12
  toFlatOptions,
12
13
  toSections,
@@ -66,7 +67,10 @@ const SingleSelect = <V, T extends OptionType<V>>({
66
67
  const sectionListRef = useRef<SectionList<T, SectionType>>(null);
67
68
  const sections = toSections(options);
68
69
  const flatOptions = toFlatOptions(options);
69
- const displayedValue = flatOptions.find((opt) => value === opt.value)?.text;
70
+ const displayedValue = flatOptions.find((opt) =>
71
+ deepCompareValue(opt.value, value)
72
+ )?.text;
73
+
70
74
  const rawValue = value ? String(value) : undefined;
71
75
  const { variant: bottomSheetVariant, header: bottomSheetHeader } =
72
76
  bottomSheetConfig;
@@ -1,4 +1,5 @@
1
1
  import {
2
+ deepCompareValue,
2
3
  getScrollParams,
3
4
  isSections,
4
5
  toFlatOptions,
@@ -72,3 +73,38 @@ describe('getScrollParams', () => {
72
73
  });
73
74
  });
74
75
  });
76
+
77
+ describe('deepCompareValue', () => {
78
+ it.each`
79
+ a | b | expected
80
+ ${1} | ${1} | ${true}
81
+ ${'test'} | ${'test'} | ${true}
82
+ ${true} | ${true} | ${true}
83
+ ${null} | ${null} | ${true}
84
+ ${undefined} | ${undefined} | ${true}
85
+ ${1} | ${2} | ${false}
86
+ ${'test'} | ${'other'} | ${false}
87
+ ${true} | ${false} | ${false}
88
+ ${null} | ${undefined} | ${false}
89
+ ${NaN} | ${NaN} | ${false}
90
+ ${1} | ${NaN} | ${false}
91
+ ${[1, 2, 3]} | ${[1, 2, 3]} | ${true}
92
+ ${['a', 'b']} | ${['a', 'b']} | ${true}
93
+ ${[]} | ${[]} | ${true}
94
+ ${[1, 2]} | ${[1, 2, 3]} | ${false}
95
+ ${[1, 2]} | ${[2, 1]} | ${false}
96
+ ${[1, [2, 3]]} | ${[1, [2, 3]]} | ${true}
97
+ ${[1, [2, 3]]} | ${[1, [2, 4]]} | ${false}
98
+ ${{ a: 1, b: 2 }} | ${{ a: 1, b: 2 }} | ${true}
99
+ ${{}} | ${{}} | ${true}
100
+ ${{ a: 1 }} | ${{ a: 2 }} | ${false}
101
+ ${{ a: 1 }} | ${{ b: 1 }} | ${false}
102
+ ${{ a: 1 }} | ${{ a: 1, b: 2 }} | ${false}
103
+ ${{ a: { b: 1 } }} | ${{ a: { b: 1 } }} | ${true}
104
+ ${{ a: { b: 1 } }} | ${{ a: { b: 2 } }} | ${false}
105
+ ${1} | ${'1'} | ${false}
106
+ ${[]} | ${{}} | ${false}
107
+ `('should compare $a and $b correctly', ({ a, b, expected }) => {
108
+ expect(deepCompareValue(a, b)).toBe(expected);
109
+ });
110
+ });