@travelswitchhq/flight-search-react 1.1.2 → 1.1.4

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
@@ -121,6 +121,9 @@ var flightSearchWidgetStyles = `
121
121
  .sw-container h5 {
122
122
  font-size: 14px;
123
123
  }
124
+ .sw-container .font14 {
125
+ font-size: 14px;
126
+ }
124
127
  .sw-container h6,
125
128
  .sw-container small {
126
129
  font-size: 12px;
@@ -868,6 +871,7 @@ padding-inline-start: 25px;
868
871
  flex: 1 1 50%;
869
872
  min-width: 0;
870
873
  justify-content: center;
874
+ border: 1px solid transparent;
871
875
  }
872
876
  .sw-add-return-label label {
873
877
  color: var(--primary) !important;
@@ -1345,8 +1349,8 @@ padding-inline-start: 25px;
1345
1349
  .sw-fsrh-chk-main{
1346
1350
  flex-wrap: wrap;
1347
1351
  }
1348
- .sw-custom-dropdown-trigger{
1349
- pointer-events: none;
1352
+ .mobiBox{
1353
+ flex-direction: row;
1350
1354
  }
1351
1355
  }
1352
1356
  `;
@@ -1491,7 +1495,9 @@ function FlightSearchWidget({
1491
1495
  const urls = API_URLS[env];
1492
1496
  const airportSearchApiBaseUrl = urls.airport;
1493
1497
  const airlineSearchApiBaseUrl = urls.airline;
1494
- const langCode = "en";
1498
+ const countryCodeConfig = (config?.countryCode ?? "").trim();
1499
+ const languageCodeConfig = (config?.languageCode ?? "").trim();
1500
+ const langCode = languageCodeConfig || "en";
1495
1501
  const [airlineQuery, setAirlineQuery] = (0, import_react.useState)("");
1496
1502
  const [airlineSuggestions, setAirlineSuggestions] = (0, import_react.useState)([]);
1497
1503
  const [selectedAirlines, setSelectedAirlines] = (0, import_react.useState)([]);
@@ -1537,6 +1543,7 @@ function FlightSearchWidget({
1537
1543
  const [isDestinationDropdownOpen, setIsDestinationDropdownOpen] = (0, import_react.useState)(false);
1538
1544
  const [isRoomsGuestsMenuOpen, setIsRoomsGuestsMenuOpen] = (0, import_react.useState)(false);
1539
1545
  const originDropdownRef = (0, import_react.useRef)(null);
1546
+ const firstOriginDesktopInputRef = (0, import_react.useRef)(null);
1540
1547
  const destinationDropdownRef = (0, import_react.useRef)(null);
1541
1548
  const roomsGuestsMenuRef = (0, import_react.useRef)(null);
1542
1549
  const dateRangeCalendarRef = (0, import_react.useRef)(null);
@@ -1767,6 +1774,21 @@ function FlightSearchWidget({
1767
1774
  ensureStylesInjected();
1768
1775
  ensurePrimeIconsLoaded();
1769
1776
  }, []);
1777
+ (0, import_react.useEffect)(() => {
1778
+ if (typeof window === "undefined") return;
1779
+ const focusFirstOrigin = () => {
1780
+ const desktop = firstOriginDesktopInputRef.current;
1781
+ desktop?.focus({ preventScroll: true });
1782
+ };
1783
+ let innerRaf = 0;
1784
+ const outerRaf = window.requestAnimationFrame(() => {
1785
+ innerRaf = window.requestAnimationFrame(focusFirstOrigin);
1786
+ });
1787
+ return () => {
1788
+ window.cancelAnimationFrame(outerRaf);
1789
+ if (innerRaf) window.cancelAnimationFrame(innerRaf);
1790
+ };
1791
+ }, []);
1770
1792
  (0, import_react.useEffect)(() => {
1771
1793
  const handleClickOutside = (event) => {
1772
1794
  const target = event.target;
@@ -2120,7 +2142,8 @@ function FlightSearchWidget({
2120
2142
  console.log("Query String:", queryString);
2121
2143
  const base = getNormalizedRedirectionBase();
2122
2144
  if (base) {
2123
- const url = `${base}/flight/listing?${queryString}`;
2145
+ const listingPath = countryCodeConfig.length > 0 ? `/${countryCodeConfig.toUpperCase()}-${languageCodeConfig ? languageCodeConfig.toUpperCase() : "EN"}/flight/listing` : "/flight/listing";
2146
+ const url = `${base}${listingPath}?${queryString}`;
2124
2147
  window.location.href = url;
2125
2148
  }
2126
2149
  };
@@ -2152,6 +2175,7 @@ function FlightSearchWidget({
2152
2175
  const label = isOrigin ? "From" : "To";
2153
2176
  const list = isOrigin ? getPredictiveState(segmentIndex).fromAirport : getPredictiveState(segmentIndex).toAirport;
2154
2177
  const selectedIndex = isOrigin ? getPredictiveState(segmentIndex).selectedFromIndex : getPredictiveState(segmentIndex).selectedToIndex;
2178
+ const isFirstOrigin = segmentIndex === 0 && isOrigin;
2155
2179
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `sw-form-field sw-pos-rel${isOrigin ? " br-left" : ""} ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-is-invalid" : ""}`, children: [
2156
2180
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${dropdownType}-${segmentIndex}`, children: label }),
2157
2181
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `sw-custom-dropdown ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-has-error" : ""}`, ref: dropdownRef, children: [
@@ -2159,8 +2183,9 @@ function FlightSearchWidget({
2159
2183
  "input",
2160
2184
  {
2161
2185
  type: "text",
2186
+ readOnly: true,
2162
2187
  id: `${dropdownType}-${segmentIndex}`,
2163
- className: `sw-custom-dropdown-trigger MobileHide ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2188
+ className: `sw-custom-dropdown-trigger MobileShow ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2164
2189
  value: value === placeholder ? "" : value ?? "",
2165
2190
  placeholder,
2166
2191
  onFocus: (e) => {
@@ -2180,9 +2205,9 @@ function FlightSearchWidget({
2180
2205
  "input",
2181
2206
  {
2182
2207
  type: "text",
2183
- readOnly: true,
2184
2208
  id: `${dropdownType}-${segmentIndex}`,
2185
- className: `sw-custom-dropdown-trigger MobileShow ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2209
+ ref: isFirstOrigin ? firstOriginDesktopInputRef : void 0,
2210
+ className: `sw-custom-dropdown-trigger MobileHide ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2186
2211
  value: value === placeholder ? "" : value ?? "",
2187
2212
  placeholder,
2188
2213
  onFocus: (e) => {
@@ -2260,7 +2285,7 @@ function FlightSearchWidget({
2260
2285
  renderAirportDropdown(index, "destination", destinationDropdownRef || destinationRef, isDestOpen, () => toggleSegmentDropdown(index, "destination"))
2261
2286
  ] }, index),
2262
2287
  isMultiCityOrCustom && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "sw-srh-wrap sw-pos-rel", children: [
2263
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "sw-form-field sw-com-cal", children: [
2288
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "sw-form-field sw-com-cal ", children: [
2264
2289
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `departure-${index}`, children: "Departure" }),
2265
2290
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2266
2291
  import_calendar.Calendar,
@@ -2379,7 +2404,7 @@ function FlightSearchWidget({
2379
2404
  ),
2380
2405
  renderAirportDropdown(0, "destination", destinationDropdownRef, isDestinationDropdownOpen, () => setIsDestinationDropdownOpen(true))
2381
2406
  ] }),
2382
- (tripType === "round-trip" || tripType === "one-way") && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "sw-srh-wrap sw-pos-rel ", children: tripType === "round-trip" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
2407
+ (tripType === "round-trip" || tripType === "one-way") && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "sw-srh-wrap sw-pos-rel mobiBox", children: tripType === "round-trip" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
2383
2408
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { cursor: "pointer" }, onClick: () => {
2384
2409
  dateRangeCalendarRef.current?.show?.();
2385
2410
  mobileDateRangeCalendarRef.current?.show?.();
@@ -2564,7 +2589,7 @@ function FlightSearchWidget({
2564
2589
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "sw-form-field sw-pos-rel sw-com-cal sw-add-return-label", style: { cursor: "pointer" }, onClick: () => {
2565
2590
  setTripType("round-trip");
2566
2591
  setTimeout(() => document.getElementById("dateRange")?.querySelector("input")?.focus?.(), 100);
2567
- }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: "Add return" }) })
2592
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { className: "font14", children: "Add return" }) })
2568
2593
  ] }) }),
2569
2594
  (tripType === "multi-city" || tripType === "custom-search") && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "sw-srh-mc-foot", children: segments.length < getMaxSegments() && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", className: "sw-srh-add-btn", onClick: addFlightSegment, children: [
2570
2595
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "14", height: "14", viewBox: "0 0 16 16", xmlns: "http://www.w3.org/2000/svg", children: [