@travelswitchhq/flight-search-react 1.1.0 → 1.1.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/dist/index.cjs CHANGED
@@ -1113,6 +1113,9 @@ padding-inline-start: 25px;
1113
1113
  font-size: 14px;
1114
1114
  line-height: 1;
1115
1115
  }
1116
+ .sw-container .sw-is-invalid{
1117
+ border: 1px solid var(--sw-error);
1118
+ }
1116
1119
  .sw-checkbox-wrap .sw-star-checkbox {
1117
1120
  display: flex;
1118
1121
  align-items: center;
@@ -1150,17 +1153,17 @@ padding-inline-start: 25px;
1150
1153
  flex: 0 1 auto;
1151
1154
  min-width: fit-content;
1152
1155
  }
1153
- .MobileShow{
1156
+ .sw-container .MobileShow{
1154
1157
  display: none;
1155
1158
  }
1156
- .MobileHide{
1159
+ .sw-container .MobileHide{
1157
1160
  display: block;
1158
1161
  }
1159
1162
  @media screen and (max-width: 768px) {
1160
- .MobileShow{
1163
+ .sw-container .MobileShow{
1161
1164
  display: block;
1162
1165
  }
1163
- .MobileHide{
1166
+ .sw-container .MobileHide{
1164
1167
  display: none;
1165
1168
  }
1166
1169
  .sw-container{
@@ -1183,6 +1186,7 @@ padding-inline-start: 25px;
1183
1186
  display: none;
1184
1187
  }
1185
1188
  }
1189
+
1186
1190
  .sw-container .sw-form-field {
1187
1191
  border-radius: var(--sw-radius);
1188
1192
  }
@@ -1252,6 +1256,7 @@ padding-inline-start: 25px;
1252
1256
  width: 100%;
1253
1257
  max-height: 100vh;
1254
1258
  overflow: auto;
1259
+ display: block !important;
1255
1260
  -webkit-overflow-scrolling: touch;
1256
1261
  scroll-behavior: smooth;
1257
1262
  padding: 0 !important;
@@ -1340,6 +1345,9 @@ padding-inline-start: 25px;
1340
1345
  .sw-fsrh-chk-main{
1341
1346
  flex-wrap: wrap;
1342
1347
  }
1348
+ .sw-custom-dropdown-trigger{
1349
+ pointer-events: none;
1350
+ }
1343
1351
  }
1344
1352
  `;
1345
1353
 
@@ -1645,6 +1653,23 @@ function FlightSearchWidget({
1645
1653
  [segmentIndex]: { ...prev[segmentIndex] ?? {}, [dropdownType]: false }
1646
1654
  }));
1647
1655
  closeAirportDropdown(dropdownType, segmentIndex);
1656
+ setValidationErrors((prev) => {
1657
+ const next = { ...prev };
1658
+ const clearForSegment = (segIndex, type) => {
1659
+ const segErr = next[segIndex];
1660
+ if (!segErr) return;
1661
+ const updatedSegErr = { ...segErr };
1662
+ if (type === "origin") delete updatedSegErr.origin;
1663
+ else delete updatedSegErr.destination;
1664
+ if (Object.keys(updatedSegErr).length === 0) delete next[segIndex];
1665
+ else next[segIndex] = updatedSegErr;
1666
+ };
1667
+ clearForSegment(segmentIndex, dropdownType);
1668
+ if ((tripType === "multi-city" || tripType === "custom-search") && dropdownType === "destination") {
1669
+ clearForSegment(segmentIndex + 1, "origin");
1670
+ }
1671
+ return next;
1672
+ });
1648
1673
  }, [closeAirportDropdown, tripType]);
1649
1674
  const updateSelectedIndex = (0, import_react.useCallback)((segmentIndex, dropdownType, newIndex) => {
1650
1675
  setPredictiveSearchList((prev) => {
@@ -1878,19 +1903,6 @@ function FlightSearchWidget({
1878
1903
  }
1879
1904
  return updated;
1880
1905
  });
1881
- if (field === "origin" || field === "destination") {
1882
- setSegmentDropdowns((prev) => ({
1883
- ...prev,
1884
- [index]: { ...prev[index], [field]: false }
1885
- }));
1886
- const placeholder = field === "origin" ? "Origin" : "Destination";
1887
- if (isValidLocationValue(value, placeholder)) {
1888
- setValidationErrors((prev) => ({
1889
- ...prev,
1890
- [index]: { ...prev[index] ?? {}, [field]: false }
1891
- }));
1892
- }
1893
- }
1894
1906
  };
1895
1907
  const handleTravellerChange = (field, value) => {
1896
1908
  setSegments((prev) => {
@@ -1901,13 +1913,25 @@ function FlightSearchWidget({
1901
1913
  });
1902
1914
  };
1903
1915
  const toggleSegmentDropdown = (index, field) => {
1904
- setSegmentDropdowns((prev) => ({
1905
- ...prev,
1906
- [index]: {
1907
- ...prev[index] || { origin: false, destination: false },
1908
- [field]: !prev[index]?.[field]
1916
+ setSegmentDropdowns((prev) => {
1917
+ const shouldOpen = !prev[index]?.[field];
1918
+ if (!shouldOpen) {
1919
+ return {
1920
+ ...prev,
1921
+ [index]: {
1922
+ ...prev[index] || { origin: false, destination: false },
1923
+ [field]: false
1924
+ }
1925
+ };
1909
1926
  }
1910
- }));
1927
+ const next = {};
1928
+ Object.keys(prev).forEach((key) => {
1929
+ const idx = Number.parseInt(key, 10);
1930
+ next[idx] = { origin: false, destination: false };
1931
+ });
1932
+ next[index] = { origin: false, destination: false, [field]: true };
1933
+ return next;
1934
+ });
1911
1935
  };
1912
1936
  const swapSegmentLocations = (index) => {
1913
1937
  setSegments((prev) => {
@@ -2136,7 +2160,29 @@ function FlightSearchWidget({
2136
2160
  {
2137
2161
  type: "text",
2138
2162
  id: `${dropdownType}-${segmentIndex}`,
2139
- className: `sw-custom-dropdown-trigger ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2163
+ className: `sw-custom-dropdown-trigger MobileHide ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2164
+ value: value === placeholder ? "" : value ?? "",
2165
+ placeholder,
2166
+ onFocus: (e) => {
2167
+ onOpen();
2168
+ e.currentTarget.select();
2169
+ },
2170
+ onClick: (e) => e.currentTarget.select(),
2171
+ onChange: (e) => {
2172
+ const val = e.target.value;
2173
+ handleSegmentFieldChange(segmentIndex, dropdownType, val);
2174
+ triggerSearchAirport(segmentIndex, dropdownType, val);
2175
+ },
2176
+ onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
2177
+ }
2178
+ ),
2179
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2180
+ "input",
2181
+ {
2182
+ type: "text",
2183
+ readOnly: true,
2184
+ id: `${dropdownType}-${segmentIndex}`,
2185
+ className: `sw-custom-dropdown-trigger MobileShow ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2140
2186
  value: value === placeholder ? "" : value ?? "",
2141
2187
  placeholder,
2142
2188
  onFocus: (e) => {
@@ -2160,7 +2206,7 @@ function FlightSearchWidget({
2160
2206
  ] }) }),
2161
2207
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { children: isOrigin ? "Origin" : "Destination" })
2162
2208
  ] }),
2163
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mobileSrgInput MobileShow", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "text", placeholder: `Search ${isOrigin ? "Origin" : "Destination"}`, value: value ?? "", onChange: (e) => {
2209
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mobileSrgInput MobileShow", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "search", placeholder: `Search ${isOrigin ? "Origin" : "Destination"}`, value: value ?? "", onChange: (e) => {
2164
2210
  const val = e.target.value;
2165
2211
  handleSegmentFieldChange(segmentIndex, dropdownType, val);
2166
2212
  triggerSearchAirport(segmentIndex, dropdownType, val);
@@ -2222,6 +2268,7 @@ function FlightSearchWidget({
2222
2268
  numberOfMonths: 2,
2223
2269
  id: `departure-${index}`,
2224
2270
  appendTo: "self",
2271
+ readOnlyInput: true,
2225
2272
  value: segment.departureDate ?? null,
2226
2273
  onChange: (e) => {
2227
2274
  const raw = e.value;
@@ -2244,6 +2291,10 @@ function FlightSearchWidget({
2244
2291
  numberOfMonths: 10,
2245
2292
  id: `departure-${index}`,
2246
2293
  appendTo: "self",
2294
+ ref: (el) => {
2295
+ segmentCalendarRefs.current[index] = el;
2296
+ },
2297
+ readOnlyInput: true,
2247
2298
  value: segment.departureDate ?? null,
2248
2299
  onChange: (e) => {
2249
2300
  const raw = e.value;
@@ -2261,7 +2312,7 @@ function FlightSearchWidget({
2261
2312
  headerTemplate: () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mobileHead MobileShow", children: [
2262
2313
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { type: "button", onClick: (e) => {
2263
2314
  e.stopPropagation();
2264
- mobileDateRangeCalendarRef.current?.hide?.();
2315
+ segmentCalendarRefs.current[index]?.hide?.();
2265
2316
  }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "20px", height: "20px", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2266
2317
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M19 5L5 19", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }),
2267
2318
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5 5L19 19", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
@@ -2275,7 +2326,7 @@ function FlightSearchWidget({
2275
2326
  className: "sw-confirm-btn",
2276
2327
  onClick: (e) => {
2277
2328
  e.stopPropagation();
2278
- mobileDateRangeCalendarRef.current?.hide?.();
2329
+ segmentCalendarRefs.current[index]?.hide?.();
2279
2330
  },
2280
2331
  children: "Confirm"
2281
2332
  }