@hero-design/rn 8.92.0 → 8.92.1-alpha.2
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/es/index.js +40 -11
- package/lib/index.js +40 -11
- package/package.json +3 -2
- package/src/components/Calendar/__tests__/CalendarRange.spec.tsx +26 -11
- package/src/components/Calendar/__tests__/helper.spec.ts +65 -58
- package/src/components/Calendar/helpers.ts +8 -13
- package/src/components/Select/SingleSelect/OptionList.tsx +6 -5
- package/src/components/Select/SingleSelect/__tests__/OptionList.spec.tsx +24 -0
- package/src/components/Select/SingleSelect/__tests__/__snapshots__/OptionList.spec.tsx.snap +594 -0
- package/src/components/Select/SingleSelect/__tests__/index.spec.tsx +26 -0
- package/src/components/Select/SingleSelect/index.tsx +5 -1
- package/src/components/Select/__tests__/helpers.spec.tsx +36 -0
- package/src/components/Select/helpers.tsx +45 -0
- package/types/components/Select/SingleSelect/OptionList.d.ts +1 -1
- package/types/components/Select/helpers.d.ts +1 -0
- package/types/theme/global/shadows/shadows.d.ts +9 -0
- package/types/theme/global/shadows/swagLight.d.ts +3 -0
- package/types/theme/global/shadows/swagLightJobs.d.ts +3 -0
- package/types/theme/global/shadows.d.ts +16 -0
- package/.turbo/turbo-build.log +0 -13
package/es/index.js
CHANGED
|
@@ -13204,11 +13204,11 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
|
|
|
13204
13204
|
var date = _ref2.date,
|
|
13205
13205
|
startDate = _ref2.startDate,
|
|
13206
13206
|
endDate = _ref2.endDate;
|
|
13207
|
-
//
|
|
13207
|
+
// If both dates are set, selecting start or end date will set the same date
|
|
13208
13208
|
if (startDate && endDate && (isEqDate(date, startDate) || isEqDate(date, endDate))) {
|
|
13209
13209
|
return {
|
|
13210
|
-
startDate:
|
|
13211
|
-
endDate:
|
|
13210
|
+
startDate: date,
|
|
13211
|
+
endDate: date
|
|
13212
13212
|
};
|
|
13213
13213
|
}
|
|
13214
13214
|
// No start date yet - set as start
|
|
@@ -13235,13 +13235,10 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
|
|
|
13235
13235
|
endDate: undefined
|
|
13236
13236
|
};
|
|
13237
13237
|
}
|
|
13238
|
-
// Clicking outside range -
|
|
13239
|
-
return
|
|
13238
|
+
// Clicking outside range - reset range
|
|
13239
|
+
return {
|
|
13240
13240
|
startDate: date,
|
|
13241
|
-
endDate:
|
|
13242
|
-
} : {
|
|
13243
|
-
startDate: startDate,
|
|
13244
|
-
endDate: date
|
|
13241
|
+
endDate: undefined
|
|
13245
13242
|
};
|
|
13246
13243
|
};
|
|
13247
13244
|
|
|
@@ -18710,6 +18707,38 @@ var useKeyboard = function useKeyboard() {
|
|
|
18710
18707
|
keyboardHeight: keyboardHeight
|
|
18711
18708
|
};
|
|
18712
18709
|
};
|
|
18710
|
+
var deepCompareValue = function deepCompareValue(a, b) {
|
|
18711
|
+
// Handle strict equality first (handles primitives, null, undefined)
|
|
18712
|
+
if (a === b) return true;
|
|
18713
|
+
// Special handling for NaN (NaN !== NaN in JS)
|
|
18714
|
+
if (typeof a === 'number' && typeof b === 'number' && Number.isNaN(a) && Number.isNaN(b)) {
|
|
18715
|
+
return false;
|
|
18716
|
+
}
|
|
18717
|
+
// If either is null or undefined (but they are not strictly equal), return false
|
|
18718
|
+
if (a == null || b == null) return false;
|
|
18719
|
+
// If types don't match, they can't be equal
|
|
18720
|
+
if (_typeof(a) !== _typeof(b)) return false;
|
|
18721
|
+
// Handle array comparison
|
|
18722
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
18723
|
+
if (a.length !== b.length) return false;
|
|
18724
|
+
return a.every(function (val, index) {
|
|
18725
|
+
return deepCompareValue(val, b[index]);
|
|
18726
|
+
});
|
|
18727
|
+
}
|
|
18728
|
+
// If one is array and the other isn't, return false
|
|
18729
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
18730
|
+
// Handle object comparison
|
|
18731
|
+
if (_typeof(a) === 'object' && _typeof(b) === 'object') {
|
|
18732
|
+
var keysA = Object.keys(a);
|
|
18733
|
+
var keysB = Object.keys(b);
|
|
18734
|
+
if (keysA.length !== keysB.length) return false;
|
|
18735
|
+
return keysA.every(function (key) {
|
|
18736
|
+
return keysB.includes(key) && deepCompareValue(a[key], b[key]);
|
|
18737
|
+
});
|
|
18738
|
+
}
|
|
18739
|
+
// If none of the above conditions matched, they're not equal
|
|
18740
|
+
return false;
|
|
18741
|
+
};
|
|
18713
18742
|
|
|
18714
18743
|
var SectionSpacer = index$a(View)(function (_ref) {
|
|
18715
18744
|
var theme = _ref.theme;
|
|
@@ -19038,7 +19067,7 @@ var OptionList = function OptionList(_ref) {
|
|
|
19038
19067
|
rest = _objectWithoutProperties(_ref, _excluded$c);
|
|
19039
19068
|
var renderItem = function renderItem(info) {
|
|
19040
19069
|
var item = info.item;
|
|
19041
|
-
var selected = item.value
|
|
19070
|
+
var selected = deepCompareValue(item.value, value);
|
|
19042
19071
|
var onItemPress = function onItemPress() {
|
|
19043
19072
|
if (value === item.value) {
|
|
19044
19073
|
onPress(null);
|
|
@@ -19109,7 +19138,7 @@ var SingleSelect = function SingleSelect(_ref) {
|
|
|
19109
19138
|
var sections = toSections(options);
|
|
19110
19139
|
var flatOptions = toFlatOptions(options);
|
|
19111
19140
|
var displayedValue = (_flatOptions$find = flatOptions.find(function (opt) {
|
|
19112
|
-
return
|
|
19141
|
+
return deepCompareValue(opt.value, value);
|
|
19113
19142
|
})) === null || _flatOptions$find === void 0 ? void 0 : _flatOptions$find.text;
|
|
19114
19143
|
var rawValue = value ? String(value) : undefined;
|
|
19115
19144
|
var bottomSheetVariant = bottomSheetConfig.variant,
|
package/lib/index.js
CHANGED
|
@@ -13232,11 +13232,11 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
|
|
|
13232
13232
|
var date = _ref2.date,
|
|
13233
13233
|
startDate = _ref2.startDate,
|
|
13234
13234
|
endDate = _ref2.endDate;
|
|
13235
|
-
//
|
|
13235
|
+
// If both dates are set, selecting start or end date will set the same date
|
|
13236
13236
|
if (startDate && endDate && (isEqDate(date, startDate) || isEqDate(date, endDate))) {
|
|
13237
13237
|
return {
|
|
13238
|
-
startDate:
|
|
13239
|
-
endDate:
|
|
13238
|
+
startDate: date,
|
|
13239
|
+
endDate: date
|
|
13240
13240
|
};
|
|
13241
13241
|
}
|
|
13242
13242
|
// No start date yet - set as start
|
|
@@ -13263,13 +13263,10 @@ var setStartOrEndDate = function setStartOrEndDate(_ref2) {
|
|
|
13263
13263
|
endDate: undefined
|
|
13264
13264
|
};
|
|
13265
13265
|
}
|
|
13266
|
-
// Clicking outside range -
|
|
13267
|
-
return
|
|
13266
|
+
// Clicking outside range - reset range
|
|
13267
|
+
return {
|
|
13268
13268
|
startDate: date,
|
|
13269
|
-
endDate:
|
|
13270
|
-
} : {
|
|
13271
|
-
startDate: startDate,
|
|
13272
|
-
endDate: date
|
|
13269
|
+
endDate: undefined
|
|
13273
13270
|
};
|
|
13274
13271
|
};
|
|
13275
13272
|
|
|
@@ -18738,6 +18735,38 @@ var useKeyboard = function useKeyboard() {
|
|
|
18738
18735
|
keyboardHeight: keyboardHeight
|
|
18739
18736
|
};
|
|
18740
18737
|
};
|
|
18738
|
+
var deepCompareValue = function deepCompareValue(a, b) {
|
|
18739
|
+
// Handle strict equality first (handles primitives, null, undefined)
|
|
18740
|
+
if (a === b) return true;
|
|
18741
|
+
// Special handling for NaN (NaN !== NaN in JS)
|
|
18742
|
+
if (typeof a === 'number' && typeof b === 'number' && Number.isNaN(a) && Number.isNaN(b)) {
|
|
18743
|
+
return false;
|
|
18744
|
+
}
|
|
18745
|
+
// If either is null or undefined (but they are not strictly equal), return false
|
|
18746
|
+
if (a == null || b == null) return false;
|
|
18747
|
+
// If types don't match, they can't be equal
|
|
18748
|
+
if (_typeof(a) !== _typeof(b)) return false;
|
|
18749
|
+
// Handle array comparison
|
|
18750
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
18751
|
+
if (a.length !== b.length) return false;
|
|
18752
|
+
return a.every(function (val, index) {
|
|
18753
|
+
return deepCompareValue(val, b[index]);
|
|
18754
|
+
});
|
|
18755
|
+
}
|
|
18756
|
+
// If one is array and the other isn't, return false
|
|
18757
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
18758
|
+
// Handle object comparison
|
|
18759
|
+
if (_typeof(a) === 'object' && _typeof(b) === 'object') {
|
|
18760
|
+
var keysA = Object.keys(a);
|
|
18761
|
+
var keysB = Object.keys(b);
|
|
18762
|
+
if (keysA.length !== keysB.length) return false;
|
|
18763
|
+
return keysA.every(function (key) {
|
|
18764
|
+
return keysB.includes(key) && deepCompareValue(a[key], b[key]);
|
|
18765
|
+
});
|
|
18766
|
+
}
|
|
18767
|
+
// If none of the above conditions matched, they're not equal
|
|
18768
|
+
return false;
|
|
18769
|
+
};
|
|
18741
18770
|
|
|
18742
18771
|
var SectionSpacer = index$a(reactNative.View)(function (_ref) {
|
|
18743
18772
|
var theme = _ref.theme;
|
|
@@ -19066,7 +19095,7 @@ var OptionList = function OptionList(_ref) {
|
|
|
19066
19095
|
rest = _objectWithoutProperties(_ref, _excluded$c);
|
|
19067
19096
|
var renderItem = function renderItem(info) {
|
|
19068
19097
|
var item = info.item;
|
|
19069
|
-
var selected = item.value
|
|
19098
|
+
var selected = deepCompareValue(item.value, value);
|
|
19070
19099
|
var onItemPress = function onItemPress() {
|
|
19071
19100
|
if (value === item.value) {
|
|
19072
19101
|
onPress(null);
|
|
@@ -19137,7 +19166,7 @@ var SingleSelect = function SingleSelect(_ref) {
|
|
|
19137
19166
|
var sections = toSections(options);
|
|
19138
19167
|
var flatOptions = toFlatOptions(options);
|
|
19139
19168
|
var displayedValue = (_flatOptions$find = flatOptions.find(function (opt) {
|
|
19140
|
-
return
|
|
19169
|
+
return deepCompareValue(opt.value, value);
|
|
19141
19170
|
})) === null || _flatOptions$find === void 0 ? void 0 : _flatOptions$find.text;
|
|
19142
19171
|
var rawValue = value ? String(value) : undefined;
|
|
19143
19172
|
var bottomSheetVariant = bottomSheetConfig.variant,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hero-design/rn",
|
|
3
|
-
"version": "8.92.
|
|
3
|
+
"version": "8.92.1-alpha.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -95,5 +95,6 @@
|
|
|
95
95
|
"ts-jest": "^29.1.1",
|
|
96
96
|
"typescript": "^5.7.3"
|
|
97
97
|
},
|
|
98
|
-
"prettier": "prettier-config-hd"
|
|
98
|
+
"prettier": "prettier-config-hd",
|
|
99
|
+
"react-native": "src/index.ts"
|
|
99
100
|
}
|
|
@@ -47,17 +47,32 @@ describe('CalendarRange', () => {
|
|
|
47
47
|
expect(queryAllByTestId('calendar-disabled-cell')).toHaveLength(0);
|
|
48
48
|
expect(queryAllByTestId('calendar-date-mark')).toHaveLength(5);
|
|
49
49
|
|
|
50
|
-
//
|
|
51
|
-
fireEvent.press(queryAllByText('11')[0]);
|
|
50
|
+
// Select outside range
|
|
51
|
+
fireEvent.press(queryAllByText('11')[0]);
|
|
52
52
|
expect(onChange).toHaveBeenCalledWith({
|
|
53
53
|
startDate: new Date('2022-10-11'),
|
|
54
|
-
endDate:
|
|
54
|
+
endDate: undefined,
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
// Select start date
|
|
58
|
+
fireEvent.press(queryAllByText('12')[0]);
|
|
58
59
|
expect(onChange).toHaveBeenCalledWith({
|
|
59
60
|
startDate: new Date('2022-10-12'),
|
|
60
|
-
endDate: new Date('2022-10-
|
|
61
|
+
endDate: new Date('2022-10-12'),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Select end date
|
|
65
|
+
fireEvent.press(queryAllByText('15')[0]);
|
|
66
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
67
|
+
startDate: new Date('2022-10-15'),
|
|
68
|
+
endDate: new Date('2022-10-15'),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Select inside range
|
|
72
|
+
fireEvent.press(queryAllByText('13')[0]);
|
|
73
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
74
|
+
startDate: new Date('2022-10-13'),
|
|
75
|
+
endDate: undefined,
|
|
61
76
|
});
|
|
62
77
|
|
|
63
78
|
fireEvent.press(queryByTestId('previous-icon-button'));
|
|
@@ -129,14 +144,14 @@ describe('CalendarRange', () => {
|
|
|
129
144
|
// Test range selection within constraints
|
|
130
145
|
fireEvent.press(getByText('17')); // Select start date
|
|
131
146
|
expect(onChange).toHaveBeenCalledWith({
|
|
132
|
-
startDate: new Date('2022-10-
|
|
133
|
-
endDate:
|
|
147
|
+
startDate: new Date('2022-10-17'),
|
|
148
|
+
endDate: undefined,
|
|
134
149
|
});
|
|
135
150
|
|
|
136
151
|
fireEvent.press(getByText('11')); // Select end date
|
|
137
152
|
expect(onChange).toHaveBeenCalledWith({
|
|
138
153
|
startDate: new Date('2022-10-11'),
|
|
139
|
-
endDate:
|
|
154
|
+
endDate: undefined,
|
|
140
155
|
});
|
|
141
156
|
});
|
|
142
157
|
|
|
@@ -156,14 +171,14 @@ describe('CalendarRange', () => {
|
|
|
156
171
|
fireEvent.press(getByText('11'));
|
|
157
172
|
expect(onChange).toHaveBeenCalledWith({
|
|
158
173
|
startDate: new Date('2022-10-11'),
|
|
159
|
-
endDate:
|
|
174
|
+
endDate: undefined,
|
|
160
175
|
});
|
|
161
176
|
|
|
162
177
|
// Select end date
|
|
163
178
|
fireEvent.press(getByText('20'));
|
|
164
179
|
expect(onChange).toHaveBeenCalledWith({
|
|
165
|
-
startDate: new Date('2022-10-
|
|
166
|
-
endDate:
|
|
180
|
+
startDate: new Date('2022-10-20'),
|
|
181
|
+
endDate: undefined,
|
|
167
182
|
});
|
|
168
183
|
|
|
169
184
|
// Select new start date (should clear end date)
|
|
@@ -73,99 +73,106 @@ describe('isDateInRange', () => {
|
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
describe('setStartOrEndDate', () => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
const today = new Date('2024-01-01');
|
|
77
|
+
const tomorrow = new Date('2024-01-02');
|
|
78
|
+
const nextWeek = new Date('2024-01-08');
|
|
79
|
+
|
|
80
|
+
it('should set start date when no dates are selected', () => {
|
|
81
|
+
const result = setStartOrEndDate({
|
|
82
|
+
date: today,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(result).toEqual({
|
|
86
|
+
startDate: today,
|
|
87
|
+
endDate: undefined,
|
|
88
|
+
});
|
|
84
89
|
});
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
it('should set end date when only start date is selected', () => {
|
|
92
|
+
const result = setStartOrEndDate({
|
|
93
|
+
date: tomorrow,
|
|
94
|
+
startDate: today,
|
|
95
|
+
});
|
|
90
96
|
|
|
91
|
-
const result = setStartOrEndDate({ date, startDate });
|
|
92
97
|
expect(result).toEqual({
|
|
93
|
-
startDate:
|
|
94
|
-
endDate:
|
|
98
|
+
startDate: today,
|
|
99
|
+
endDate: tomorrow,
|
|
95
100
|
});
|
|
96
101
|
});
|
|
97
102
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
it('should set start date when date is before current start date', () => {
|
|
104
|
+
const result = setStartOrEndDate({
|
|
105
|
+
date: today,
|
|
106
|
+
startDate: tomorrow,
|
|
107
|
+
});
|
|
101
108
|
|
|
102
|
-
const result = setStartOrEndDate({ date });
|
|
103
109
|
expect(result).toEqual({
|
|
104
|
-
startDate:
|
|
105
|
-
endDate:
|
|
110
|
+
startDate: today,
|
|
111
|
+
endDate: tomorrow,
|
|
106
112
|
});
|
|
107
113
|
});
|
|
108
114
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
it('should set end date when date is after current start date', () => {
|
|
116
|
+
const result = setStartOrEndDate({
|
|
117
|
+
date: tomorrow,
|
|
118
|
+
startDate: today,
|
|
119
|
+
});
|
|
113
120
|
|
|
114
|
-
const result = setStartOrEndDate({ date, startDate });
|
|
115
121
|
expect(result).toEqual({
|
|
116
|
-
startDate:
|
|
117
|
-
endDate:
|
|
122
|
+
startDate: today,
|
|
123
|
+
endDate: tomorrow,
|
|
118
124
|
});
|
|
119
125
|
});
|
|
120
126
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
it('should reset selection when clicking within range', () => {
|
|
128
|
+
const result = setStartOrEndDate({
|
|
129
|
+
date: tomorrow,
|
|
130
|
+
startDate: today,
|
|
131
|
+
endDate: nextWeek,
|
|
132
|
+
});
|
|
125
133
|
|
|
126
|
-
const result = setStartOrEndDate({ date, startDate });
|
|
127
134
|
expect(result).toEqual({
|
|
128
|
-
startDate:
|
|
129
|
-
endDate:
|
|
135
|
+
startDate: tomorrow,
|
|
136
|
+
endDate: undefined,
|
|
130
137
|
});
|
|
131
138
|
});
|
|
132
139
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
it('should reset selection when clicking outside range', () => {
|
|
141
|
+
const result = setStartOrEndDate({
|
|
142
|
+
date: nextWeek,
|
|
143
|
+
startDate: today,
|
|
144
|
+
endDate: tomorrow,
|
|
145
|
+
});
|
|
138
146
|
|
|
139
|
-
const result = setStartOrEndDate({ date, startDate, endDate });
|
|
140
147
|
expect(result).toEqual({
|
|
141
|
-
startDate:
|
|
148
|
+
startDate: nextWeek,
|
|
142
149
|
endDate: undefined,
|
|
143
150
|
});
|
|
144
151
|
});
|
|
145
152
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
153
|
+
it('should set same date for both start and end when clicking start date', () => {
|
|
154
|
+
const result = setStartOrEndDate({
|
|
155
|
+
date: today,
|
|
156
|
+
startDate: today,
|
|
157
|
+
endDate: tomorrow,
|
|
158
|
+
});
|
|
151
159
|
|
|
152
|
-
const result = setStartOrEndDate({ date, startDate, endDate });
|
|
153
160
|
expect(result).toEqual({
|
|
154
|
-
startDate:
|
|
155
|
-
endDate:
|
|
161
|
+
startDate: today,
|
|
162
|
+
endDate: today,
|
|
156
163
|
});
|
|
157
164
|
});
|
|
158
165
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
166
|
+
it('should set same date for both start and end when clicking end date', () => {
|
|
167
|
+
const result = setStartOrEndDate({
|
|
168
|
+
date: tomorrow,
|
|
169
|
+
startDate: today,
|
|
170
|
+
endDate: tomorrow,
|
|
171
|
+
});
|
|
164
172
|
|
|
165
|
-
const result = setStartOrEndDate({ date, startDate, endDate });
|
|
166
173
|
expect(result).toEqual({
|
|
167
|
-
startDate:
|
|
168
|
-
endDate:
|
|
174
|
+
startDate: tomorrow,
|
|
175
|
+
endDate: tomorrow,
|
|
169
176
|
});
|
|
170
177
|
});
|
|
171
178
|
});
|
|
@@ -54,15 +54,15 @@ export const setStartOrEndDate = ({
|
|
|
54
54
|
startDate?: Date;
|
|
55
55
|
endDate?: Date;
|
|
56
56
|
}) => {
|
|
57
|
-
//
|
|
57
|
+
// If both dates are set, selecting start or end date will set the same date
|
|
58
58
|
if (
|
|
59
59
|
startDate &&
|
|
60
60
|
endDate &&
|
|
61
61
|
(isEqDate(date, startDate) || isEqDate(date, endDate))
|
|
62
62
|
) {
|
|
63
63
|
return {
|
|
64
|
-
startDate,
|
|
65
|
-
endDate,
|
|
64
|
+
startDate: date,
|
|
65
|
+
endDate: date,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -95,14 +95,9 @@ export const setStartOrEndDate = ({
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
// Clicking outside range -
|
|
99
|
-
return
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
: {
|
|
105
|
-
startDate,
|
|
106
|
-
endDate: date,
|
|
107
|
-
};
|
|
98
|
+
// Clicking outside range - reset range
|
|
99
|
+
return {
|
|
100
|
+
startDate: date,
|
|
101
|
+
endDate: undefined,
|
|
102
|
+
};
|
|
108
103
|
};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {
|
|
3
|
-
SectionListRenderItemInfo,
|
|
4
|
-
SectionList,
|
|
5
3
|
Dimensions,
|
|
4
|
+
SectionList,
|
|
5
|
+
SectionListRenderItemInfo,
|
|
6
6
|
} from 'react-native';
|
|
7
|
-
import Option from './Option';
|
|
8
7
|
import type { SingleSelectProps } from '.';
|
|
8
|
+
import { BaseOptionListProps } from '../BaseOptionList';
|
|
9
|
+
import { deepCompareValue } from '../helpers';
|
|
9
10
|
import type { OptionType, SectionType } from '../types';
|
|
11
|
+
import Option from './Option';
|
|
10
12
|
import { StyledOptionList } from './StyledSingleSelect';
|
|
11
|
-
import { BaseOptionListProps } from '../BaseOptionList';
|
|
12
13
|
|
|
13
14
|
type OptionListProps<V, T extends OptionType<V>> = Pick<
|
|
14
15
|
SingleSelectProps<V, T>,
|
|
@@ -37,7 +38,7 @@ const OptionList = <V, T extends OptionType<V>>({
|
|
|
37
38
|
}: OptionListProps<V, T>) => {
|
|
38
39
|
const renderItem = (info: SectionListRenderItemInfo<T, SectionType>) => {
|
|
39
40
|
const { item } = info;
|
|
40
|
-
const selected = item.value
|
|
41
|
+
const selected = deepCompareValue(item.value, value);
|
|
41
42
|
const onItemPress = () => {
|
|
42
43
|
if (value === item.value) {
|
|
43
44
|
onPress(null);
|
|
@@ -58,4 +58,28 @@ describe('OptionList', () => {
|
|
|
58
58
|
);
|
|
59
59
|
expect(toJSON()).toMatchSnapshot();
|
|
60
60
|
});
|
|
61
|
+
|
|
62
|
+
it('render object value correctly', () => {
|
|
63
|
+
const sectionsWithObjectValue = [
|
|
64
|
+
{
|
|
65
|
+
category: 'A',
|
|
66
|
+
data: [{ text: 'Item 1', value: { id: '1', label: 'Item 1' } }],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
category: 'B',
|
|
70
|
+
data: [{ text: 'Item 2', value: { id: '2', label: 'Item 2' } }],
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
const pressFn = jest.fn();
|
|
74
|
+
const { toJSON, getByText } = renderWithTheme(
|
|
75
|
+
<OptionList
|
|
76
|
+
sections={sectionsWithObjectValue}
|
|
77
|
+
value={sectionsWithObjectValue[0].data[0].value}
|
|
78
|
+
onPress={pressFn}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
expect(toJSON()).toMatchSnapshot();
|
|
82
|
+
expect(getByText('Item 1')).toBeTruthy();
|
|
83
|
+
expect(getByText('Item 2')).toBeTruthy();
|
|
84
|
+
});
|
|
61
85
|
});
|