@snapdragonsnursery/react-components 1.17.7 → 1.17.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snapdragonsnursery/react-components",
3
- "version": "1.17.7",
3
+ "version": "1.17.9",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -26,12 +26,17 @@
26
26
  // - showSiteName?: boolean // show site below name (default: true)
27
27
  // - showEmployeeId?: boolean // show employee ID below name (default: false)
28
28
  // - showEmail?: boolean // show email below name (default: false)
29
- // - placeholder?: string
29
+ // - placeholder?: string // select trigger placeholder (default: 'Select employee…')
30
+ // - searchPlaceholder?: string // search input placeholder (default: 'Search employees...')
30
31
  // - disabled?: boolean
31
32
  // - className?: string
32
33
  // - allowAll?: boolean // include "All employees" option
33
34
  // - allLabel?: string // custom label for all option
34
35
  // - maxHeight?: string // max height for dropdown (default: '160px')
36
+ // - enableServerSearch?: boolean // enable server-side search (default: false)
37
+ // - onSearchChange?: (query: string) => void // callback for search query changes
38
+ // - searchResults?: Array<employee> // search results from server
39
+ // - isSearching?: boolean // loading state for server search
35
40
 
36
41
  import React from "react";
37
42
  import { Users, Search } from "lucide-react";
@@ -56,6 +61,7 @@ export const EmployeeSelect = ({
56
61
  showEmployeeId = false,
57
62
  showEmail = false,
58
63
  placeholder = "Select employee…",
64
+ searchPlaceholder = "Search employees...",
59
65
  disabled = false,
60
66
  className,
61
67
  allowAll = false,
@@ -70,6 +76,7 @@ export const EmployeeSelect = ({
70
76
  const [searchTerm, setSearchTerm] = React.useState("");
71
77
  const [isOpen, setIsOpen] = React.useState(false);
72
78
  const [debouncedSearchTerm, setDebouncedSearchTerm] = React.useState("");
79
+ const searchInputRef = React.useRef(null);
73
80
 
74
81
  // Debounce search term for server-side search
75
82
  React.useEffect(() => {
@@ -83,6 +90,16 @@ export const EmployeeSelect = ({
83
90
  return () => clearTimeout(timer);
84
91
  }, [searchTerm, enableServerSearch, onSearchChange]);
85
92
 
93
+ // Maintain focus on search input when server results update
94
+ React.useEffect(() => {
95
+ if (enableServerSearch && isOpen && searchInputRef.current && document.activeElement !== searchInputRef.current) {
96
+ // Only refocus if we previously had focus (i.e., user was typing)
97
+ if (searchTerm && !isSearching) {
98
+ searchInputRef.current.focus();
99
+ }
100
+ }
101
+ }, [searchResults, enableServerSearch, isOpen, searchTerm, isSearching]);
102
+
86
103
  // Helper function to generate initials from full name
87
104
  const getInitials = (name) => {
88
105
  if (!name) return "??";
@@ -239,8 +256,9 @@ export const EmployeeSelect = ({
239
256
  <div className="relative">
240
257
  <Search className="absolute left-2 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
241
258
  <input
259
+ ref={searchInputRef}
242
260
  type="text"
243
- placeholder={enableServerSearch ? "Search employees..." : "Search employees..."}
261
+ placeholder={searchPlaceholder}
244
262
  value={searchTerm}
245
263
  onChange={(e) => setSearchTerm(e.target.value)}
246
264
  className="w-full pl-8 pr-3 py-2 text-sm border rounded-md focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 bg-background"