-
Notifications
You must be signed in to change notification settings - Fork 88
Open
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Request
Note
This feature builds on top of the file listing UI added in #1292
Enable the TreeSelect search input with auto-expand behavior. Currently, PathsSelectFormItem has showSearch={false}, disabling the search box entirely.
Proposed behaviour:
- Enable "search" so users may manually input a single path per selection
- When the user types a path ending with
/, automatically load and expand to that directory. For example:
/logs/→ loads children of/logs/logs/prod/→ loads children of both/logsand/logs/prod
This allows users to quickly navigate to deep paths (e.g., /logs/production/app1/2024/12/08/) without clicking through each level.
Possible implementation
- Change
showSearch={false}toshowSearch={true}in the TreeSelect props - Add an
onSearchhandler:
const handleSearch = useCallback(async (value: string) => {
const trimmed = value.trim();
if (!trimmed.startsWith(ROOT)) {
return;
}
setIsLoading(true);
try {
const ancestors = getAncestorPaths(trimmed);
for (const p of ancestors.slice(0, -1)) {
await loadPath(p);
}
if (value.endsWith(ROOT) && 1 < trimmed.length) {
await loadPath(trimmed.slice(0, -1));
}
setExpandedKeys((prev) => [...new Set([...prev, ...ancestors])]);
} catch (e) {
console.error("Failed to search:", e);
message.error(e instanceof Error ? e.message : "Failed to search for path");
} finally {
setIsLoading(false);
}
}, [loadPath]);
const getAncestorPaths = (path: string): string[] => {
const segments = path.split(ROOT).filter(Boolean);
const paths = [ROOT];
let current = ROOT;
for (const seg of segments) {
current = joinPath(current, seg);
paths.push(current);
}
return paths;
};Considerations
- Antd TreeSelect's
loadData()is now not triggered when searching in the latest versions. See https://ant.design/components/tree-select#faq-load-data-expand for details / mitigations - Sequential loading may be slow for deep paths; consider debouncing
- Errors in loading any parent directory should halt expansion gracefully
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request