@travelswitchhq/flight-search-react 1.1.3 → 1.1.5

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
@@ -303,9 +303,11 @@ padding-inline-start: 25px;
303
303
  visibility: visible;
304
304
  opacity: 1;
305
305
  }
306
+ .sw-dropdown{
307
+ width: 380px;
308
+ }
306
309
  .sw-dropdown,
307
310
  .p-autocomplete-panel {
308
- width: 380px;
309
311
  max-height: 310px;
310
312
  margin: 0;
311
313
  padding: 0;
@@ -319,9 +321,16 @@ padding-inline-start: 25px;
319
321
  .sw-dropdown::-webkit-scrollbar {
320
322
  display: none;
321
323
  }
322
- .sw-dropdown-list-card,
323
- .sw-dropdown-list-box,
324
324
  .p-autocomplete-item {
325
+ display: flex;
326
+ align-items: center;
327
+ gap: 15px;
328
+ padding: 10px 20px;
329
+ cursor: pointer;
330
+ font-family: var(--sw-font-family);
331
+ }
332
+ .sw-dropdown-list-card,
333
+ .sw-dropdown-list-box {
325
334
  display: flex;
326
335
  align-items: center;
327
336
  gap: 15px;
@@ -1495,7 +1504,9 @@ function FlightSearchWidget({
1495
1504
  const urls = API_URLS[env];
1496
1505
  const airportSearchApiBaseUrl = urls.airport;
1497
1506
  const airlineSearchApiBaseUrl = urls.airline;
1498
- const langCode = "en";
1507
+ const countryCodeConfig = (config?.countryCode ?? "").trim();
1508
+ const languageCodeConfig = (config?.languageCode ?? "").trim();
1509
+ const langCode = languageCodeConfig || "en";
1499
1510
  const [airlineQuery, setAirlineQuery] = (0, import_react.useState)("");
1500
1511
  const [airlineSuggestions, setAirlineSuggestions] = (0, import_react.useState)([]);
1501
1512
  const [selectedAirlines, setSelectedAirlines] = (0, import_react.useState)([]);
@@ -1541,6 +1552,7 @@ function FlightSearchWidget({
1541
1552
  const [isDestinationDropdownOpen, setIsDestinationDropdownOpen] = (0, import_react.useState)(false);
1542
1553
  const [isRoomsGuestsMenuOpen, setIsRoomsGuestsMenuOpen] = (0, import_react.useState)(false);
1543
1554
  const originDropdownRef = (0, import_react.useRef)(null);
1555
+ const firstOriginDesktopInputRef = (0, import_react.useRef)(null);
1544
1556
  const destinationDropdownRef = (0, import_react.useRef)(null);
1545
1557
  const roomsGuestsMenuRef = (0, import_react.useRef)(null);
1546
1558
  const dateRangeCalendarRef = (0, import_react.useRef)(null);
@@ -1771,10 +1783,27 @@ function FlightSearchWidget({
1771
1783
  ensureStylesInjected();
1772
1784
  ensurePrimeIconsLoaded();
1773
1785
  }, []);
1786
+ (0, import_react.useEffect)(() => {
1787
+ if (typeof window === "undefined") return;
1788
+ const focusFirstOrigin = () => {
1789
+ const desktop = firstOriginDesktopInputRef.current;
1790
+ desktop?.focus({ preventScroll: true });
1791
+ };
1792
+ let innerRaf = 0;
1793
+ const outerRaf = window.requestAnimationFrame(() => {
1794
+ innerRaf = window.requestAnimationFrame(focusFirstOrigin);
1795
+ });
1796
+ return () => {
1797
+ window.cancelAnimationFrame(outerRaf);
1798
+ if (innerRaf) window.cancelAnimationFrame(innerRaf);
1799
+ };
1800
+ }, []);
1774
1801
  (0, import_react.useEffect)(() => {
1775
1802
  const handleClickOutside = (event) => {
1776
1803
  const target = event.target;
1777
- const isInsidePrimeDropdown = target.closest(".p-dropdown-panel") !== null || target.closest(".p-dropdown-items-wrapper") !== null || target.closest(".p-dropdown-item") !== null || target.closest(".p-component")?.classList.contains("p-dropdown") !== false || target.closest('[data-pc-section="panel"]') !== null || target.closest('[data-pc-name="dropdown"]') !== null;
1804
+ const isInsidePrimeDropdown = Boolean(
1805
+ target.closest(".p-dropdown-panel") || target.closest(".p-dropdown-items-wrapper") || target.closest(".p-dropdown-item") || target.closest('[data-pc-section="panel"]') || target.closest('[data-pc-name="dropdown"]')
1806
+ );
1778
1807
  if (originDropdownRef.current && !originDropdownRef.current.contains(target)) {
1779
1808
  setIsOriginDropdownOpen(false);
1780
1809
  }
@@ -2124,7 +2153,8 @@ function FlightSearchWidget({
2124
2153
  console.log("Query String:", queryString);
2125
2154
  const base = getNormalizedRedirectionBase();
2126
2155
  if (base) {
2127
- const url = `${base}/flight/listing?${queryString}`;
2156
+ const listingPath = countryCodeConfig.length > 0 ? `/${countryCodeConfig.toUpperCase()}-${languageCodeConfig ? languageCodeConfig.toUpperCase() : "EN"}/flight/listing` : "/flight/listing";
2157
+ const url = `${base}${listingPath}?${queryString}`;
2128
2158
  window.location.href = url;
2129
2159
  }
2130
2160
  };
@@ -2156,6 +2186,7 @@ function FlightSearchWidget({
2156
2186
  const label = isOrigin ? "From" : "To";
2157
2187
  const list = isOrigin ? getPredictiveState(segmentIndex).fromAirport : getPredictiveState(segmentIndex).toAirport;
2158
2188
  const selectedIndex = isOrigin ? getPredictiveState(segmentIndex).selectedFromIndex : getPredictiveState(segmentIndex).selectedToIndex;
2189
+ const isFirstOrigin = segmentIndex === 0 && isOrigin;
2159
2190
  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: [
2160
2191
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${dropdownType}-${segmentIndex}`, children: label }),
2161
2192
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `sw-custom-dropdown ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-has-error" : ""}`, ref: dropdownRef, children: [
@@ -2186,6 +2217,7 @@ function FlightSearchWidget({
2186
2217
  {
2187
2218
  type: "text",
2188
2219
  id: `${dropdownType}-${segmentIndex}`,
2220
+ ref: isFirstOrigin ? firstOriginDesktopInputRef : void 0,
2189
2221
  className: `sw-custom-dropdown-trigger MobileHide ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2190
2222
  value: value === placeholder ? "" : value ?? "",
2191
2223
  placeholder,
@@ -2760,6 +2792,7 @@ function FlightSearchWidget({
2760
2792
  preferredAirlineList: next.map((item) => item.airline_code)
2761
2793
  }));
2762
2794
  },
2795
+ appendTo: "self",
2763
2796
  field: "airline_name",
2764
2797
  multiple: true,
2765
2798
  forceSelection: true,