@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.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;
@@ -1124,17 +1127,17 @@ padding-inline-start: 25px;
1124
1127
  flex: 0 1 auto;
1125
1128
  min-width: fit-content;
1126
1129
  }
1127
- .MobileShow{
1130
+ .sw-container .MobileShow{
1128
1131
  display: none;
1129
1132
  }
1130
- .MobileHide{
1133
+ .sw-container .MobileHide{
1131
1134
  display: block;
1132
1135
  }
1133
1136
  @media screen and (max-width: 768px) {
1134
- .MobileShow{
1137
+ .sw-container .MobileShow{
1135
1138
  display: block;
1136
1139
  }
1137
- .MobileHide{
1140
+ .sw-container .MobileHide{
1138
1141
  display: none;
1139
1142
  }
1140
1143
  .sw-container{
@@ -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;
@@ -1314,6 +1319,9 @@ padding-inline-start: 25px;
1314
1319
  .sw-fsrh-chk-main{
1315
1320
  flex-wrap: wrap;
1316
1321
  }
1322
+ .sw-custom-dropdown-trigger{
1323
+ pointer-events: none;
1324
+ }
1317
1325
  }
1318
1326
  `;
1319
1327
 
@@ -1619,6 +1627,23 @@ function FlightSearchWidget({
1619
1627
  [segmentIndex]: { ...prev[segmentIndex] ?? {}, [dropdownType]: false }
1620
1628
  }));
1621
1629
  closeAirportDropdown(dropdownType, segmentIndex);
1630
+ setValidationErrors((prev) => {
1631
+ const next = { ...prev };
1632
+ const clearForSegment = (segIndex, type) => {
1633
+ const segErr = next[segIndex];
1634
+ if (!segErr) return;
1635
+ const updatedSegErr = { ...segErr };
1636
+ if (type === "origin") delete updatedSegErr.origin;
1637
+ else delete updatedSegErr.destination;
1638
+ if (Object.keys(updatedSegErr).length === 0) delete next[segIndex];
1639
+ else next[segIndex] = updatedSegErr;
1640
+ };
1641
+ clearForSegment(segmentIndex, dropdownType);
1642
+ if ((tripType === "multi-city" || tripType === "custom-search") && dropdownType === "destination") {
1643
+ clearForSegment(segmentIndex + 1, "origin");
1644
+ }
1645
+ return next;
1646
+ });
1622
1647
  }, [closeAirportDropdown, tripType]);
1623
1648
  const updateSelectedIndex = useCallback((segmentIndex, dropdownType, newIndex) => {
1624
1649
  setPredictiveSearchList((prev) => {
@@ -1852,19 +1877,6 @@ function FlightSearchWidget({
1852
1877
  }
1853
1878
  return updated;
1854
1879
  });
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
1880
  };
1869
1881
  const handleTravellerChange = (field, value) => {
1870
1882
  setSegments((prev) => {
@@ -1875,13 +1887,25 @@ function FlightSearchWidget({
1875
1887
  });
1876
1888
  };
1877
1889
  const toggleSegmentDropdown = (index, field) => {
1878
- setSegmentDropdowns((prev) => ({
1879
- ...prev,
1880
- [index]: {
1881
- ...prev[index] || { origin: false, destination: false },
1882
- [field]: !prev[index]?.[field]
1890
+ setSegmentDropdowns((prev) => {
1891
+ const shouldOpen = !prev[index]?.[field];
1892
+ if (!shouldOpen) {
1893
+ return {
1894
+ ...prev,
1895
+ [index]: {
1896
+ ...prev[index] || { origin: false, destination: false },
1897
+ [field]: false
1898
+ }
1899
+ };
1883
1900
  }
1884
- }));
1901
+ const next = {};
1902
+ Object.keys(prev).forEach((key) => {
1903
+ const idx = Number.parseInt(key, 10);
1904
+ next[idx] = { origin: false, destination: false };
1905
+ });
1906
+ next[index] = { origin: false, destination: false, [field]: true };
1907
+ return next;
1908
+ });
1885
1909
  };
1886
1910
  const swapSegmentLocations = (index) => {
1887
1911
  setSegments((prev) => {
@@ -2110,7 +2134,29 @@ function FlightSearchWidget({
2110
2134
  {
2111
2135
  type: "text",
2112
2136
  id: `${dropdownType}-${segmentIndex}`,
2113
- className: `sw-custom-dropdown-trigger ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2137
+ className: `sw-custom-dropdown-trigger MobileHide ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2138
+ value: value === placeholder ? "" : value ?? "",
2139
+ placeholder,
2140
+ onFocus: (e) => {
2141
+ onOpen();
2142
+ e.currentTarget.select();
2143
+ },
2144
+ onClick: (e) => e.currentTarget.select(),
2145
+ onChange: (e) => {
2146
+ const val = e.target.value;
2147
+ handleSegmentFieldChange(segmentIndex, dropdownType, val);
2148
+ triggerSearchAirport(segmentIndex, dropdownType, val);
2149
+ },
2150
+ onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
2151
+ }
2152
+ ),
2153
+ /* @__PURE__ */ jsx(
2154
+ "input",
2155
+ {
2156
+ type: "text",
2157
+ readOnly: true,
2158
+ id: `${dropdownType}-${segmentIndex}`,
2159
+ className: `sw-custom-dropdown-trigger MobileShow ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2114
2160
  value: value === placeholder ? "" : value ?? "",
2115
2161
  placeholder,
2116
2162
  onFocus: (e) => {
@@ -2134,7 +2180,7 @@ function FlightSearchWidget({
2134
2180
  ] }) }),
2135
2181
  /* @__PURE__ */ jsx("h4", { children: isOrigin ? "Origin" : "Destination" })
2136
2182
  ] }),
2137
- /* @__PURE__ */ jsx("div", { className: "mobileSrgInput MobileShow", children: /* @__PURE__ */ jsx("input", { type: "text", placeholder: `Search ${isOrigin ? "Origin" : "Destination"}`, value: value ?? "", onChange: (e) => {
2183
+ /* @__PURE__ */ jsx("div", { className: "mobileSrgInput MobileShow", children: /* @__PURE__ */ jsx("input", { type: "search", placeholder: `Search ${isOrigin ? "Origin" : "Destination"}`, value: value ?? "", onChange: (e) => {
2138
2184
  const val = e.target.value;
2139
2185
  handleSegmentFieldChange(segmentIndex, dropdownType, val);
2140
2186
  triggerSearchAirport(segmentIndex, dropdownType, val);
@@ -2196,6 +2242,7 @@ function FlightSearchWidget({
2196
2242
  numberOfMonths: 2,
2197
2243
  id: `departure-${index}`,
2198
2244
  appendTo: "self",
2245
+ readOnlyInput: true,
2199
2246
  value: segment.departureDate ?? null,
2200
2247
  onChange: (e) => {
2201
2248
  const raw = e.value;
@@ -2218,6 +2265,10 @@ function FlightSearchWidget({
2218
2265
  numberOfMonths: 10,
2219
2266
  id: `departure-${index}`,
2220
2267
  appendTo: "self",
2268
+ ref: (el) => {
2269
+ segmentCalendarRefs.current[index] = el;
2270
+ },
2271
+ readOnlyInput: true,
2221
2272
  value: segment.departureDate ?? null,
2222
2273
  onChange: (e) => {
2223
2274
  const raw = e.value;
@@ -2235,7 +2286,7 @@ function FlightSearchWidget({
2235
2286
  headerTemplate: () => /* @__PURE__ */ jsxs("div", { className: "mobileHead MobileShow", children: [
2236
2287
  /* @__PURE__ */ jsx("a", { type: "button", onClick: (e) => {
2237
2288
  e.stopPropagation();
2238
- mobileDateRangeCalendarRef.current?.hide?.();
2289
+ segmentCalendarRefs.current[index]?.hide?.();
2239
2290
  }, children: /* @__PURE__ */ jsxs("svg", { width: "20px", height: "20px", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2240
2291
  /* @__PURE__ */ jsx("path", { d: "M19 5L5 19", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }),
2241
2292
  /* @__PURE__ */ jsx("path", { d: "M5 5L19 19", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
@@ -2249,7 +2300,7 @@ function FlightSearchWidget({
2249
2300
  className: "sw-confirm-btn",
2250
2301
  onClick: (e) => {
2251
2302
  e.stopPropagation();
2252
- mobileDateRangeCalendarRef.current?.hide?.();
2303
+ segmentCalendarRefs.current[index]?.hide?.();
2253
2304
  },
2254
2305
  children: "Confirm"
2255
2306
  }