@foundrykit/components 1.0.23 → 1.1.0

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.js CHANGED
@@ -667,7 +667,6 @@ import { Input as Input3 } from "@foundrykit/primitives";
667
667
  import { Button as Button4 } from "@foundrykit/primitives";
668
668
  import { Separator } from "@foundrykit/primitives";
669
669
  import { Badge } from "@foundrykit/primitives";
670
- import { Card, CardContent } from "@foundrykit/primitives";
671
670
  import { ScrollArea } from "@foundrykit/primitives";
672
671
  import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
673
672
  function AdvancedSearchProvider({
@@ -681,51 +680,71 @@ function AdvancedSearchProvider({
681
680
  styles = {
682
681
  results: {
683
682
  maxHeight: "24rem"
684
- }
683
+ },
684
+ width: "100%"
685
685
  }
686
686
  }) {
687
+ const inputId = React4.useId();
688
+ const resultsId = React4.useId();
687
689
  const [query, setQuery] = React4.useState("");
688
690
  const [isOpen, setIsOpen] = React4.useState(false);
689
691
  const [results, setResults] = React4.useState(initialResults);
690
692
  const [isLoading, setIsLoading] = React4.useState(false);
691
- const debouncedSearch = React4.useCallback(
693
+ const [activeIndex, setActiveIndex] = React4.useState(-1);
694
+ const timeoutRef = React4.useRef(null);
695
+ const requestIdRef = React4.useRef(0);
696
+ React4.useEffect(() => {
697
+ return () => {
698
+ if (timeoutRef.current) {
699
+ clearTimeout(timeoutRef.current);
700
+ }
701
+ };
702
+ }, []);
703
+ const handleSearch = React4.useCallback(
692
704
  (searchQuery) => {
693
- const timeoutId = setTimeout(async () => {
694
- if (searchQuery.length >= minQueryLength && onSearch) {
695
- setIsLoading(true);
696
- try {
697
- const searchResults = await onSearch(searchQuery);
705
+ if (timeoutRef.current) {
706
+ clearTimeout(timeoutRef.current);
707
+ }
708
+ setActiveIndex(-1);
709
+ const trimmedQuery = searchQuery.trim();
710
+ const isEmptyQuery = trimmedQuery.length === 0;
711
+ const isTooShort = trimmedQuery.length < minQueryLength;
712
+ if (isEmptyQuery || isTooShort || !onSearch) {
713
+ requestIdRef.current += 1;
714
+ setIsLoading(false);
715
+ setResults(
716
+ emptyStateBehavior === "show-all-results" && (isEmptyQuery || isTooShort) ? initialResults : []
717
+ );
718
+ return;
719
+ }
720
+ const requestId = requestIdRef.current + 1;
721
+ requestIdRef.current = requestId;
722
+ timeoutRef.current = setTimeout(async () => {
723
+ setIsLoading(true);
724
+ try {
725
+ const searchResults = await onSearch(trimmedQuery);
726
+ if (requestIdRef.current === requestId) {
698
727
  setResults(searchResults);
699
- } catch (error) {
728
+ }
729
+ } catch (error) {
730
+ if (requestIdRef.current === requestId) {
700
731
  console.error("Search error:", error);
701
732
  setResults([]);
702
- } finally {
703
- setIsLoading(false);
704
733
  }
705
- } else {
706
- if (emptyStateBehavior === "show-all-results" && searchQuery.length === 0) {
707
- setResults(initialResults);
708
- } else if (emptyStateBehavior === "show-all-results" && searchQuery.length > 0 && searchQuery.length < minQueryLength) {
709
- setResults(initialResults);
710
- } else {
711
- setResults([]);
734
+ } finally {
735
+ if (requestIdRef.current === requestId) {
736
+ setIsLoading(false);
712
737
  }
713
738
  }
714
739
  }, debounceMs);
715
- return () => clearTimeout(timeoutId);
716
740
  },
717
- [onSearch, debounceMs, minQueryLength, emptyStateBehavior, initialResults]
718
- );
719
- const handleSearch = React4.useCallback(
720
- (searchQuery) => {
721
- debouncedSearch(searchQuery);
722
- },
723
- [debouncedSearch]
741
+ [debounceMs, emptyStateBehavior, initialResults, minQueryLength, onSearch]
724
742
  );
725
743
  const handleResultSelect = React4.useCallback(
726
744
  (result) => {
727
745
  onResultSelect?.(result);
728
746
  setQuery(result.title);
747
+ setActiveIndex(-1);
729
748
  setIsOpen(false);
730
749
  },
731
750
  [onResultSelect]
@@ -736,6 +755,10 @@ function AdvancedSearchProvider({
736
755
  setQuery,
737
756
  isOpen,
738
757
  setIsOpen,
758
+ inputId,
759
+ resultsId,
760
+ activeIndex,
761
+ setActiveIndex,
739
762
  results,
740
763
  setResults,
741
764
  isLoading,
@@ -748,6 +771,9 @@ function AdvancedSearchProvider({
748
771
  [
749
772
  query,
750
773
  isOpen,
774
+ inputId,
775
+ resultsId,
776
+ activeIndex,
751
777
  results,
752
778
  isLoading,
753
779
  handleSearch,
@@ -760,7 +786,8 @@ function AdvancedSearchProvider({
760
786
  "div",
761
787
  {
762
788
  style: {
763
- "--results-max-height": styles.results.maxHeight
789
+ "--results-max-height": styles.results?.maxHeight ?? "24rem",
790
+ width: styles.width
764
791
  },
765
792
  children
766
793
  }
@@ -816,7 +843,14 @@ var SearchInput = React4.forwardRef(
816
843
  query,
817
844
  setQuery,
818
845
  onSearch,
846
+ onResultSelect,
847
+ results,
848
+ isOpen,
819
849
  setIsOpen,
850
+ inputId,
851
+ resultsId,
852
+ activeIndex,
853
+ setActiveIndex,
820
854
  emptyStateBehavior,
821
855
  minQueryLength
822
856
  } = useAdvancedSearch();
@@ -844,11 +878,53 @@ var SearchInput = React4.forwardRef(
844
878
  };
845
879
  const handleClear = () => {
846
880
  setQuery("");
881
+ setActiveIndex(-1);
847
882
  setTimeout(() => {
848
883
  onSearch("");
849
884
  }, 0);
850
885
  onClear?.();
851
886
  };
887
+ const handleKeyDown = (e) => {
888
+ props.onKeyDown?.(e);
889
+ if (e.defaultPrevented) return;
890
+ if (e.key === "Escape") {
891
+ setIsOpen(false);
892
+ setActiveIndex(-1);
893
+ return;
894
+ }
895
+ if (e.key === "ArrowDown") {
896
+ e.preventDefault();
897
+ setIsOpen(true);
898
+ setActiveIndex(
899
+ results.length ? (activeIndex + 1) % results.length : -1
900
+ );
901
+ return;
902
+ }
903
+ if (e.key === "ArrowUp") {
904
+ e.preventDefault();
905
+ setIsOpen(true);
906
+ setActiveIndex(
907
+ results.length ? activeIndex <= 0 ? results.length - 1 : activeIndex - 1 : -1
908
+ );
909
+ return;
910
+ }
911
+ if (e.key === "Home") {
912
+ if (!results.length) return;
913
+ e.preventDefault();
914
+ setActiveIndex(0);
915
+ return;
916
+ }
917
+ if (e.key === "End") {
918
+ if (!results.length) return;
919
+ e.preventDefault();
920
+ setActiveIndex(results.length - 1);
921
+ return;
922
+ }
923
+ if (e.key === "Enter" && activeIndex >= 0 && results[activeIndex]) {
924
+ e.preventDefault();
925
+ onResultSelect(results[activeIndex]);
926
+ }
927
+ };
852
928
  return /* @__PURE__ */ jsxs5(
853
929
  Comp,
854
930
  {
@@ -868,26 +944,35 @@ var SearchInput = React4.forwardRef(
868
944
  Input3,
869
945
  {
870
946
  ref,
871
- type: "text",
947
+ ...props,
948
+ id: inputId,
949
+ type: "search",
950
+ role: "combobox",
872
951
  "aria-label": "Search",
952
+ "aria-autocomplete": "list",
953
+ "aria-expanded": isOpen,
954
+ "aria-controls": resultsId,
955
+ "aria-activedescendant": activeIndex >= 0 && results[activeIndex] ? `${resultsId}-option-${results[activeIndex].id}` : void 0,
873
956
  placeholder,
874
957
  value: query,
875
958
  onChange: handleChange,
876
959
  onFocus: handleFocus,
960
+ onKeyDown: handleKeyDown,
877
961
  className: cn6(
878
962
  "border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0",
879
963
  showSearchIcon && "pl-10",
880
964
  showClearButton && query && "pr-10"
881
965
  ),
882
- size: void 0,
883
- ...props
966
+ size: void 0
884
967
  }
885
968
  ),
886
969
  showClearButton && query && /* @__PURE__ */ jsx6(
887
970
  Button4,
888
971
  {
972
+ type: "button",
889
973
  variant: "ghost",
890
974
  size: "sm",
975
+ "aria-label": "Clear search",
891
976
  className: "absolute right-1 h-6 w-6 p-0",
892
977
  onClick: handleClear,
893
978
  children: /* @__PURE__ */ jsx6(X, { className: "h-3 w-3" })
@@ -899,16 +984,24 @@ var SearchInput = React4.forwardRef(
899
984
  }
900
985
  );
901
986
  SearchInput.displayName = "SearchInput";
902
- var SearchTrigger = React4.forwardRef(({ className, asChild = false, children, ...props }, ref) => {
903
- const { isOpen, setIsOpen } = useAdvancedSearch();
987
+ var SearchTrigger = React4.forwardRef(({ className, asChild = false, children, onClick, ...props }, ref) => {
988
+ const { isOpen, setIsOpen, resultsId } = useAdvancedSearch();
904
989
  const Comp = asChild ? Slot : Button4;
905
990
  return /* @__PURE__ */ jsx6(
906
991
  Comp,
907
992
  {
908
993
  ref,
909
- className: cn6(className),
910
- onClick: () => setIsOpen(!isOpen),
911
994
  ...props,
995
+ type: "button",
996
+ "aria-expanded": isOpen,
997
+ "aria-controls": resultsId,
998
+ className: cn6(className),
999
+ onClick: (event) => {
1000
+ onClick?.(event);
1001
+ if (!event.defaultPrevented) {
1002
+ setIsOpen(!isOpen);
1003
+ }
1004
+ },
912
1005
  children
913
1006
  }
914
1007
  );
@@ -922,6 +1015,8 @@ var SearchResults = React4.forwardRef(
922
1015
  showEmptyState = true,
923
1016
  emptyStateMessage = "No results found",
924
1017
  showLoadingState = true,
1018
+ loadingBehavior = "replace-results",
1019
+ loadingState,
925
1020
  loadingMessage = "Searching...",
926
1021
  ...props
927
1022
  }, ref) => {
@@ -930,38 +1025,48 @@ var SearchResults = React4.forwardRef(
930
1025
  isLoading,
931
1026
  query,
932
1027
  onResultSelect,
1028
+ resultsId,
1029
+ activeIndex,
933
1030
  emptyStateBehavior,
934
1031
  minQueryLength
935
1032
  } = useAdvancedSearch();
936
- if (isLoading && showLoadingState) {
1033
+ const shouldReplaceResultsWithLoading = loadingBehavior === "replace-results" || results.length === 0;
1034
+ if (isLoading && showLoadingState && shouldReplaceResultsWithLoading) {
937
1035
  return /* @__PURE__ */ jsx6(
938
1036
  "div",
939
1037
  {
940
1038
  ref,
1039
+ id: resultsId,
941
1040
  className: cn6(
942
1041
  searchResultsVariants({ size }),
943
1042
  "text-muted-foreground p-4 text-center",
944
1043
  className
945
1044
  ),
1045
+ role: "status",
1046
+ "aria-live": "polite",
946
1047
  ...props,
947
- children: loadingMessage
1048
+ children: loadingState ?? loadingMessage
948
1049
  }
949
1050
  );
950
1051
  }
951
- if (!query || results.length === 0) {
1052
+ const shouldShowEmptyState = results.length === 0 || !query && emptyStateBehavior !== "show-all-results";
1053
+ if (shouldShowEmptyState) {
952
1054
  if (!showEmptyState) return null;
953
- if (emptyStateBehavior === "hide-until-min-chars" && query.length > 0 && query.length < minQueryLength) {
1055
+ if (emptyStateBehavior === "hide-until-min-chars" && query.length < minQueryLength) {
954
1056
  return null;
955
1057
  }
956
1058
  return /* @__PURE__ */ jsx6(
957
1059
  "div",
958
1060
  {
959
1061
  ref,
1062
+ id: resultsId,
960
1063
  className: cn6(
961
1064
  searchResultsVariants({ size }),
962
1065
  "text-muted-foreground p-4 text-center",
963
1066
  className
964
1067
  ),
1068
+ role: "status",
1069
+ "aria-live": "polite",
965
1070
  ...props,
966
1071
  children: emptyStateMessage
967
1072
  }
@@ -978,26 +1083,36 @@ var SearchResults = React4.forwardRef(
978
1083
  "div",
979
1084
  {
980
1085
  ref,
1086
+ id: resultsId,
981
1087
  className: cn6(
982
1088
  searchResultsVariants({ size }),
983
1089
  "max-h-[var(--results-max-height)]",
984
1090
  className
985
1091
  ),
1092
+ role: "listbox",
986
1093
  "aria-label": "Search results",
1094
+ "aria-busy": isLoading || void 0,
987
1095
  ...props,
988
1096
  children: /* @__PURE__ */ jsx6(ScrollArea, { className: "h-fit max-h-[var(--results-max-height)] *:max-h-[var(--results-max-height)]", children: /* @__PURE__ */ jsx6("div", { className: "space-y-4 p-4", children: displaySections.map((section, index) => /* @__PURE__ */ jsxs5("div", { children: [
989
1097
  index > 0 && /* @__PURE__ */ jsx6(Separator, { className: "my-4" }),
990
1098
  /* @__PURE__ */ jsxs5("div", { className: "space-y-2", children: [
991
1099
  /* @__PURE__ */ jsx6("h3", { className: "text-muted-foreground text-sm font-semibold uppercase tracking-wide", children: section.title }),
992
1100
  /* @__PURE__ */ jsxs5("div", { className: "space-y-1", children: [
993
- section.results.map((result) => /* @__PURE__ */ jsx6(
994
- SearchResultItem,
995
- {
996
- result,
997
- onClick: () => onResultSelect(result)
998
- },
999
- result.id
1000
- )),
1101
+ section.results.map((result) => {
1102
+ const resultIndex = results.findIndex(
1103
+ (item) => item.id === result.id
1104
+ );
1105
+ return /* @__PURE__ */ jsx6(
1106
+ SearchResultItem,
1107
+ {
1108
+ id: `${resultsId}-option-${result.id}`,
1109
+ result,
1110
+ isActive: resultIndex === activeIndex,
1111
+ onClick: () => onResultSelect(result)
1112
+ },
1113
+ result.id
1114
+ );
1115
+ }),
1001
1116
  section.showMore && section.onShowMore && /* @__PURE__ */ jsxs5(
1002
1117
  Button4,
1003
1118
  {
@@ -1019,62 +1134,150 @@ var SearchResults = React4.forwardRef(
1019
1134
  }
1020
1135
  );
1021
1136
  SearchResults.displayName = "SearchResults";
1022
- var SearchResultItem = ({ result, onClick }) => {
1137
+ var SearchResultItem = ({
1138
+ id,
1139
+ result,
1140
+ isActive,
1141
+ onClick
1142
+ }) => {
1143
+ const itemClasses = cn6(
1144
+ "hover:bg-accent hover:text-accent-foreground focus-visible:border-ring focus-visible:ring-ring/50 w-full rounded-md text-left transition-colors outline-none focus-visible:ring-[3px]",
1145
+ isActive && "bg-accent text-accent-foreground"
1146
+ );
1023
1147
  if (result.type === "category") {
1024
- return /* @__PURE__ */ jsx6("div", { className: "text-muted-foreground p-2 text-sm font-medium", children: result.title });
1148
+ return /* @__PURE__ */ jsx6(
1149
+ "div",
1150
+ {
1151
+ id,
1152
+ role: "presentation",
1153
+ className: "text-muted-foreground p-2 text-sm font-medium",
1154
+ children: result.title
1155
+ }
1156
+ );
1025
1157
  }
1026
1158
  if (result.type === "suggestion") {
1027
1159
  return /* @__PURE__ */ jsx6(
1028
- Button4,
1160
+ "button",
1161
+ {
1162
+ id,
1163
+ type: "button",
1164
+ role: "option",
1165
+ "aria-selected": isActive,
1166
+ className: cn6(itemClasses, "p-2 text-sm"),
1167
+ onClick,
1168
+ children: result.title
1169
+ }
1170
+ );
1171
+ }
1172
+ const content = /* @__PURE__ */ jsxs5("div", { className: "flex gap-3 p-3", children: [
1173
+ result.image && /* @__PURE__ */ jsx6("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx6(
1174
+ "img",
1175
+ {
1176
+ src: result.image,
1177
+ alt: result.title,
1178
+ className: "h-12 w-12 rounded-md object-cover",
1179
+ loading: "lazy"
1180
+ }
1181
+ ) }),
1182
+ /* @__PURE__ */ jsxs5("div", { className: "min-w-0 flex-1", children: [
1183
+ /* @__PURE__ */ jsxs5("div", { className: "flex items-start justify-between gap-2", children: [
1184
+ /* @__PURE__ */ jsx6("h4", { className: "truncate text-sm font-semibold", children: result.title }),
1185
+ result.badge && /* @__PURE__ */ jsx6(Badge, { variant: "secondary", className: "text-xs", children: result.badge })
1186
+ ] }),
1187
+ result.description && /* @__PURE__ */ jsx6("p", { className: "text-muted-foreground mt-1 line-clamp-2 text-xs", children: result.description })
1188
+ ] })
1189
+ ] });
1190
+ if (result.href) {
1191
+ return /* @__PURE__ */ jsx6(
1192
+ "a",
1029
1193
  {
1030
- variant: "ghost",
1031
- size: "sm",
1032
- className: "h-auto w-full justify-start p-2",
1194
+ id,
1195
+ role: "option",
1196
+ "aria-selected": isActive,
1197
+ href: result.href,
1198
+ className: cn6(itemClasses, "block"),
1033
1199
  onClick,
1034
- children: /* @__PURE__ */ jsx6("span", { className: "text-sm", children: result.title })
1200
+ children: content
1035
1201
  }
1036
1202
  );
1037
1203
  }
1038
1204
  return /* @__PURE__ */ jsx6(
1039
- Card,
1205
+ "button",
1040
1206
  {
1041
- className: "hover:bg-muted/50 w-full cursor-pointer transition-colors",
1207
+ id,
1208
+ type: "button",
1209
+ role: "option",
1210
+ "aria-selected": isActive,
1211
+ className: itemClasses,
1042
1212
  onClick,
1043
- children: /* @__PURE__ */ jsx6(CardContent, { className: "p-3", children: /* @__PURE__ */ jsxs5("div", { className: "flex gap-3", children: [
1044
- result.image && /* @__PURE__ */ jsx6("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx6(
1045
- "img",
1046
- {
1047
- src: result.image,
1048
- alt: result.title,
1049
- className: "h-12 w-12 rounded-md object-cover"
1050
- }
1051
- ) }),
1052
- /* @__PURE__ */ jsxs5("div", { className: "min-w-0 flex-1", children: [
1053
- /* @__PURE__ */ jsxs5("div", { className: "flex items-start justify-between gap-2", children: [
1054
- /* @__PURE__ */ jsx6("h4", { className: "truncate text-sm font-semibold", children: result.title }),
1055
- result.badge && /* @__PURE__ */ jsx6(Badge, { variant: "secondary", className: "text-xs", children: result.badge })
1056
- ] }),
1057
- result.description && /* @__PURE__ */ jsx6("p", { className: "text-muted-foreground mt-1 line-clamp-2 text-xs", children: result.description })
1058
- ] })
1059
- ] }) })
1213
+ children: content
1060
1214
  }
1061
1215
  );
1062
1216
  };
1063
- var AdvancedSearchBar = React4.forwardRef(({ className, children, open, ...props }, ref) => {
1064
- const { isOpen } = useAdvancedSearch();
1217
+ var AdvancedSearchBar = React4.forwardRef(({ className, children, open, onOpenChange, ...props }, ref) => {
1218
+ const { isOpen, setIsOpen, setActiveIndex } = useAdvancedSearch();
1219
+ const rootRef = React4.useRef(null);
1220
+ const previousOpenRef = React4.useRef(isOpen);
1065
1221
  const isControlled = open !== void 0;
1066
1222
  const isOpenState = isControlled ? open : isOpen;
1067
- const childrenArray = React4.Children.toArray(children);
1068
- const inputChild = childrenArray.find(
1069
- (child) => React4.isValidElement(child) && child.type === SearchInput
1223
+ React4.useEffect(() => {
1224
+ if (previousOpenRef.current !== isOpen) {
1225
+ previousOpenRef.current = isOpen;
1226
+ onOpenChange?.(isOpen);
1227
+ }
1228
+ }, [isOpen, onOpenChange]);
1229
+ React4.useEffect(() => {
1230
+ if (!isOpenState) return;
1231
+ const handlePointerDown = (event) => {
1232
+ if (!rootRef.current?.contains(event.target)) {
1233
+ setActiveIndex(-1);
1234
+ setIsOpen(false);
1235
+ onOpenChange?.(false);
1236
+ }
1237
+ };
1238
+ const handleKeyDown = (event) => {
1239
+ if (event.key !== "Escape") return;
1240
+ setActiveIndex(-1);
1241
+ setIsOpen(false);
1242
+ onOpenChange?.(false);
1243
+ const focusTarget = rootRef.current?.querySelector(
1244
+ 'input, button, [href], [tabindex]:not([tabindex="-1"])'
1245
+ );
1246
+ focusTarget?.focus();
1247
+ };
1248
+ document.addEventListener("pointerdown", handlePointerDown);
1249
+ document.addEventListener("keydown", handleKeyDown);
1250
+ return () => {
1251
+ document.removeEventListener("pointerdown", handlePointerDown);
1252
+ document.removeEventListener("keydown", handleKeyDown);
1253
+ };
1254
+ }, [isOpenState, onOpenChange, setActiveIndex, setIsOpen]);
1255
+ const setRefs = React4.useCallback(
1256
+ (node) => {
1257
+ rootRef.current = node;
1258
+ if (typeof ref === "function") {
1259
+ ref(node);
1260
+ } else if (ref) {
1261
+ ref.current = node;
1262
+ }
1263
+ },
1264
+ [ref]
1070
1265
  );
1071
- const resultsChild = childrenArray.find(
1072
- (child) => React4.isValidElement(child) && child.type === SearchResults
1266
+ const isSearchResultsChild = (child) => {
1267
+ if (!React4.isValidElement(child)) return false;
1268
+ const childType = child.type;
1269
+ return child.type === SearchResults || childType.displayName === SearchResults.displayName;
1270
+ };
1271
+ const childrenArray = React4.Children.toArray(children);
1272
+ const resultsChildren = childrenArray.filter(isSearchResultsChild);
1273
+ const triggerChildren = childrenArray.filter(
1274
+ (child) => !isSearchResultsChild(child)
1073
1275
  );
1074
- const triggerElement = inputChild || /* @__PURE__ */ jsx6(SearchInput, {});
1075
- return /* @__PURE__ */ jsxs5("div", { ref, className: cn6("relative", className), ...props, children: [
1276
+ const triggerElement = triggerChildren.length ? triggerChildren : /* @__PURE__ */ jsx6(SearchInput, {});
1277
+ const resultsElement = resultsChildren.length ? resultsChildren : /* @__PURE__ */ jsx6(SearchResults, {});
1278
+ return /* @__PURE__ */ jsxs5("div", { ref: setRefs, className: cn6("relative w-full", className), ...props, children: [
1076
1279
  /* @__PURE__ */ jsx6("div", { className: "w-full", children: triggerElement }),
1077
- isOpenState && /* @__PURE__ */ jsx6("div", { className: "absolute left-0 top-full z-50 mt-1 w-full rounded-md border border-gray-200 bg-white shadow-lg", children: resultsChild || /* @__PURE__ */ jsx6(SearchResults, {}) })
1280
+ isOpenState && /* @__PURE__ */ jsx6("div", { className: "bg-popover text-popover-foreground border-border absolute left-0 top-full z-50 mt-1 max-h-[min(var(--results-max-height),calc(100vh-8rem))] w-full overflow-hidden rounded-md border shadow-lg", children: resultsElement })
1078
1281
  ] });
1079
1282
  });
1080
1283
  AdvancedSearchBar.displayName = "AdvancedSearchBar";
@@ -1099,7 +1302,7 @@ var SearchSection = React4.forwardRef(({ className, title, showMore, onShowMore,
1099
1302
  ] })
1100
1303
  ] });
1101
1304
  });
1102
- SearchSection.displayName = "SearchSection ";
1305
+ SearchSection.displayName = "SearchSection";
1103
1306
  var SearchItem = React4.forwardRef(
1104
1307
  ({ className, result, onClick, children, ...props }, ref) => {
1105
1308
  const { onResultSelect } = useAdvancedSearch();
@@ -1109,13 +1312,22 @@ var SearchItem = React4.forwardRef(
1109
1312
  }
1110
1313
  onClick?.();
1111
1314
  };
1315
+ const handleKeyDown = (event) => {
1316
+ if (event.key === "Enter" || event.key === " ") {
1317
+ event.preventDefault();
1318
+ handleClick();
1319
+ }
1320
+ };
1112
1321
  if (children) {
1113
1322
  return /* @__PURE__ */ jsx6(
1114
1323
  "div",
1115
1324
  {
1116
1325
  ref,
1117
- className: cn6("cursor-pointer", className),
1326
+ role: "button",
1327
+ tabIndex: 0,
1328
+ className: cn6("cursor-pointer outline-none", className),
1118
1329
  onClick: handleClick,
1330
+ onKeyDown: handleKeyDown,
1119
1331
  ...props,
1120
1332
  children
1121
1333
  }
@@ -1127,6 +1339,7 @@ var SearchItem = React4.forwardRef(
1127
1339
  "div",
1128
1340
  {
1129
1341
  ref,
1342
+ role: "presentation",
1130
1343
  className: cn6(
1131
1344
  "text-muted-foreground p-2 text-sm font-medium",
1132
1345
  className
@@ -1151,22 +1364,24 @@ var SearchItem = React4.forwardRef(
1151
1364
  );
1152
1365
  }
1153
1366
  return /* @__PURE__ */ jsx6(
1154
- Card,
1367
+ "button",
1155
1368
  {
1156
1369
  ref,
1370
+ type: "button",
1157
1371
  className: cn6(
1158
- "hover:bg-muted/50 w-full cursor-pointer transition-colors",
1372
+ "hover:bg-accent hover:text-accent-foreground focus-visible:border-ring focus-visible:ring-ring/50 w-full cursor-pointer rounded-md text-left outline-none transition-colors focus-visible:ring-[3px]",
1159
1373
  className
1160
1374
  ),
1161
1375
  onClick: handleClick,
1162
1376
  ...props,
1163
- children: /* @__PURE__ */ jsx6(CardContent, { className: "p-3", children: /* @__PURE__ */ jsxs5("div", { className: "flex gap-3", children: [
1377
+ children: /* @__PURE__ */ jsxs5("div", { className: "flex gap-3 p-3", children: [
1164
1378
  result.image && /* @__PURE__ */ jsx6("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx6(
1165
1379
  "img",
1166
1380
  {
1167
1381
  src: result.image,
1168
1382
  alt: result.title,
1169
- className: "h-12 w-12 rounded-md object-cover"
1383
+ className: "h-12 w-12 rounded-md object-cover",
1384
+ loading: "lazy"
1170
1385
  }
1171
1386
  ) }),
1172
1387
  /* @__PURE__ */ jsxs5("div", { className: "min-w-0 flex-1", children: [
@@ -1176,7 +1391,7 @@ var SearchItem = React4.forwardRef(
1176
1391
  ] }),
1177
1392
  result.description && /* @__PURE__ */ jsx6("p", { className: "text-muted-foreground mt-1 line-clamp-2 text-xs", children: result.description })
1178
1393
  ] })
1179
- ] }) })
1394
+ ] })
1180
1395
  }
1181
1396
  );
1182
1397
  }