@travelswitchhq/flight-search-react 1.1.0 → 1.1.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.
package/dist/index.mjs CHANGED
@@ -1087,6 +1087,9 @@ padding-inline-start: 25px;
1087
1087
  font-size: 14px;
1088
1088
  line-height: 1;
1089
1089
  }
1090
+ .sw-container .sw-is-invalid{
1091
+ border: 1px solid var(--sw-error);
1092
+ }
1090
1093
  .sw-checkbox-wrap .sw-star-checkbox {
1091
1094
  display: flex;
1092
1095
  align-items: center;
@@ -1157,6 +1160,7 @@ padding-inline-start: 25px;
1157
1160
  display: none;
1158
1161
  }
1159
1162
  }
1163
+
1160
1164
  .sw-container .sw-form-field {
1161
1165
  border-radius: var(--sw-radius);
1162
1166
  }
@@ -1226,6 +1230,7 @@ padding-inline-start: 25px;
1226
1230
  width: 100%;
1227
1231
  max-height: 100vh;
1228
1232
  overflow: auto;
1233
+ display: block !important;
1229
1234
  -webkit-overflow-scrolling: touch;
1230
1235
  scroll-behavior: smooth;
1231
1236
  padding: 0 !important;
@@ -1619,6 +1624,23 @@ function FlightSearchWidget({
1619
1624
  [segmentIndex]: { ...prev[segmentIndex] ?? {}, [dropdownType]: false }
1620
1625
  }));
1621
1626
  closeAirportDropdown(dropdownType, segmentIndex);
1627
+ setValidationErrors((prev) => {
1628
+ const next = { ...prev };
1629
+ const clearForSegment = (segIndex, type) => {
1630
+ const segErr = next[segIndex];
1631
+ if (!segErr) return;
1632
+ const updatedSegErr = { ...segErr };
1633
+ if (type === "origin") delete updatedSegErr.origin;
1634
+ else delete updatedSegErr.destination;
1635
+ if (Object.keys(updatedSegErr).length === 0) delete next[segIndex];
1636
+ else next[segIndex] = updatedSegErr;
1637
+ };
1638
+ clearForSegment(segmentIndex, dropdownType);
1639
+ if ((tripType === "multi-city" || tripType === "custom-search") && dropdownType === "destination") {
1640
+ clearForSegment(segmentIndex + 1, "origin");
1641
+ }
1642
+ return next;
1643
+ });
1622
1644
  }, [closeAirportDropdown, tripType]);
1623
1645
  const updateSelectedIndex = useCallback((segmentIndex, dropdownType, newIndex) => {
1624
1646
  setPredictiveSearchList((prev) => {
@@ -1852,19 +1874,6 @@ function FlightSearchWidget({
1852
1874
  }
1853
1875
  return updated;
1854
1876
  });
1855
- if (field === "origin" || field === "destination") {
1856
- setSegmentDropdowns((prev) => ({
1857
- ...prev,
1858
- [index]: { ...prev[index], [field]: false }
1859
- }));
1860
- const placeholder = field === "origin" ? "Origin" : "Destination";
1861
- if (isValidLocationValue(value, placeholder)) {
1862
- setValidationErrors((prev) => ({
1863
- ...prev,
1864
- [index]: { ...prev[index] ?? {}, [field]: false }
1865
- }));
1866
- }
1867
- }
1868
1877
  };
1869
1878
  const handleTravellerChange = (field, value) => {
1870
1879
  setSegments((prev) => {
@@ -1875,13 +1884,25 @@ function FlightSearchWidget({
1875
1884
  });
1876
1885
  };
1877
1886
  const toggleSegmentDropdown = (index, field) => {
1878
- setSegmentDropdowns((prev) => ({
1879
- ...prev,
1880
- [index]: {
1881
- ...prev[index] || { origin: false, destination: false },
1882
- [field]: !prev[index]?.[field]
1887
+ setSegmentDropdowns((prev) => {
1888
+ const shouldOpen = !prev[index]?.[field];
1889
+ if (!shouldOpen) {
1890
+ return {
1891
+ ...prev,
1892
+ [index]: {
1893
+ ...prev[index] || { origin: false, destination: false },
1894
+ [field]: false
1895
+ }
1896
+ };
1883
1897
  }
1884
- }));
1898
+ const next = {};
1899
+ Object.keys(prev).forEach((key) => {
1900
+ const idx = Number.parseInt(key, 10);
1901
+ next[idx] = { origin: false, destination: false };
1902
+ });
1903
+ next[index] = { origin: false, destination: false, [field]: true };
1904
+ return next;
1905
+ });
1885
1906
  };
1886
1907
  const swapSegmentLocations = (index) => {
1887
1908
  setSegments((prev) => {
@@ -2134,7 +2155,7 @@ function FlightSearchWidget({
2134
2155
  ] }) }),
2135
2156
  /* @__PURE__ */ jsx("h4", { children: isOrigin ? "Origin" : "Destination" })
2136
2157
  ] }),
2137
- /* @__PURE__ */ jsx("div", { className: "mobileSrgInput MobileShow", children: /* @__PURE__ */ jsx("input", { type: "text", placeholder: `Search ${isOrigin ? "Origin" : "Destination"}`, value: value ?? "", onChange: (e) => {
2158
+ /* @__PURE__ */ jsx("div", { className: "mobileSrgInput MobileShow", children: /* @__PURE__ */ jsx("input", { type: "search", placeholder: `Search ${isOrigin ? "Origin" : "Destination"}`, value: value ?? "", onChange: (e) => {
2138
2159
  const val = e.target.value;
2139
2160
  handleSegmentFieldChange(segmentIndex, dropdownType, val);
2140
2161
  triggerSearchAirport(segmentIndex, dropdownType, val);
@@ -2196,6 +2217,7 @@ function FlightSearchWidget({
2196
2217
  numberOfMonths: 2,
2197
2218
  id: `departure-${index}`,
2198
2219
  appendTo: "self",
2220
+ readOnlyInput: true,
2199
2221
  value: segment.departureDate ?? null,
2200
2222
  onChange: (e) => {
2201
2223
  const raw = e.value;
@@ -2218,6 +2240,10 @@ function FlightSearchWidget({
2218
2240
  numberOfMonths: 10,
2219
2241
  id: `departure-${index}`,
2220
2242
  appendTo: "self",
2243
+ ref: (el) => {
2244
+ segmentCalendarRefs.current[index] = el;
2245
+ },
2246
+ readOnlyInput: true,
2221
2247
  value: segment.departureDate ?? null,
2222
2248
  onChange: (e) => {
2223
2249
  const raw = e.value;
@@ -2235,7 +2261,7 @@ function FlightSearchWidget({
2235
2261
  headerTemplate: () => /* @__PURE__ */ jsxs("div", { className: "mobileHead MobileShow", children: [
2236
2262
  /* @__PURE__ */ jsx("a", { type: "button", onClick: (e) => {
2237
2263
  e.stopPropagation();
2238
- mobileDateRangeCalendarRef.current?.hide?.();
2264
+ segmentCalendarRefs.current[index]?.hide?.();
2239
2265
  }, children: /* @__PURE__ */ jsxs("svg", { width: "20px", height: "20px", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2240
2266
  /* @__PURE__ */ jsx("path", { d: "M19 5L5 19", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }),
2241
2267
  /* @__PURE__ */ jsx("path", { d: "M5 5L19 19", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
@@ -2249,7 +2275,7 @@ function FlightSearchWidget({
2249
2275
  className: "sw-confirm-btn",
2250
2276
  onClick: (e) => {
2251
2277
  e.stopPropagation();
2252
- mobileDateRangeCalendarRef.current?.hide?.();
2278
+ segmentCalendarRefs.current[index]?.hide?.();
2253
2279
  },
2254
2280
  children: "Confirm"
2255
2281
  }