@snapdragonsnursery/react-components 1.17.7 → 1.17.8
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
|
@@ -70,6 +70,7 @@ export const EmployeeSelect = ({
|
|
|
70
70
|
const [searchTerm, setSearchTerm] = React.useState("");
|
|
71
71
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
72
72
|
const [debouncedSearchTerm, setDebouncedSearchTerm] = React.useState("");
|
|
73
|
+
const searchInputRef = React.useRef(null);
|
|
73
74
|
|
|
74
75
|
// Debounce search term for server-side search
|
|
75
76
|
React.useEffect(() => {
|
|
@@ -83,6 +84,16 @@ export const EmployeeSelect = ({
|
|
|
83
84
|
return () => clearTimeout(timer);
|
|
84
85
|
}, [searchTerm, enableServerSearch, onSearchChange]);
|
|
85
86
|
|
|
87
|
+
// Maintain focus on search input when server results update
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
if (enableServerSearch && isOpen && searchInputRef.current && document.activeElement !== searchInputRef.current) {
|
|
90
|
+
// Only refocus if we previously had focus (i.e., user was typing)
|
|
91
|
+
if (searchTerm && !isSearching) {
|
|
92
|
+
searchInputRef.current.focus();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}, [searchResults, enableServerSearch, isOpen, searchTerm, isSearching]);
|
|
96
|
+
|
|
86
97
|
// Helper function to generate initials from full name
|
|
87
98
|
const getInitials = (name) => {
|
|
88
99
|
if (!name) return "??";
|
|
@@ -239,6 +250,7 @@ export const EmployeeSelect = ({
|
|
|
239
250
|
<div className="relative">
|
|
240
251
|
<Search className="absolute left-2 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
|
|
241
252
|
<input
|
|
253
|
+
ref={searchInputRef}
|
|
242
254
|
type="text"
|
|
243
255
|
placeholder={enableServerSearch ? "Search employees..." : "Search employees..."}
|
|
244
256
|
value={searchTerm}
|