feat: add AskUserDialog for UI component of AskUser tool (#17344)

Co-authored-by: jacob314 <jacob314@gmail.com>
This commit is contained in:
Jack Wotherspoon
2026-01-23 15:42:48 -05:00
committed by GitHub
parent 25c0802b52
commit 2c0cc7b9a5
10 changed files with 3009 additions and 1 deletions
@@ -13,6 +13,7 @@ export interface SelectionListItem<T> {
key: string;
value: T;
disabled?: boolean;
hideNumber?: boolean;
}
interface BaseSelectionItem {
@@ -28,6 +29,7 @@ export interface UseSelectionListOptions<T> {
isFocused?: boolean;
showNumbers?: boolean;
wrapAround?: boolean;
focusKey?: string;
}
export interface UseSelectionListResult {
@@ -285,6 +287,7 @@ export function useSelectionList<T>({
isFocused = true,
showNumbers = false,
wrapAround = true,
focusKey,
}: UseSelectionListOptions<T>): UseSelectionListResult {
const baseItems = toBaseItems(items);
@@ -302,6 +305,25 @@ export function useSelectionList<T>({
const prevBaseItemsRef = useRef(baseItems);
const prevInitialIndexRef = useRef(initialIndex);
const prevWrapAroundRef = useRef(wrapAround);
const lastProcessedFocusKeyRef = useRef<string | undefined>(undefined);
// Handle programmatic focus changes via focusKey
useEffect(() => {
if (focusKey === undefined) {
lastProcessedFocusKeyRef.current = undefined;
return;
}
if (focusKey === lastProcessedFocusKeyRef.current) return;
const index = items.findIndex(
(item) => item.key === focusKey && !item.disabled,
);
if (index !== -1) {
lastProcessedFocusKeyRef.current = focusKey;
dispatch({ type: 'SET_ACTIVE_INDEX', payload: { index } });
}
}, [focusKey, items]);
// Initialize/synchronize state when initialIndex or items change
useEffect(() => {