Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/cli/src/ui/components/AuthDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export function AuthDialog({

return item.value === AuthType.LOGIN_WITH_GOOGLE;
});
const validInitialAuthIndex = initialAuthIndex >= 0 ? initialAuthIndex : 0;

const handleAuthSelect = (authMethod: AuthType) => {
const error = validateAuthMethod(authMethod);
Expand Down Expand Up @@ -145,7 +146,7 @@ export function AuthDialog({
<Box marginTop={1}>
<RadioButtonSelect
items={items}
initialIndex={initialAuthIndex}
initialIndex={validInitialAuthIndex}
onSelect={handleAuthSelect}
isFocused={true}
/>
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/ui/components/ThemeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function ThemeDialog({
const initialThemeIndex = themeItems.findIndex(
(item) => item.value === (settings.merged.theme || DEFAULT_THEME.name),
);
const validInitialThemeIndex = initialThemeIndex >= 0 ? initialThemeIndex : 0;

const scopeItems = [
{ label: 'User Settings', value: SettingScope.User },
Expand Down Expand Up @@ -198,7 +199,7 @@ export function ThemeDialog({
<RadioButtonSelect
key={selectInputKey}
items={themeItems}
initialIndex={initialThemeIndex}
initialIndex={validInitialThemeIndex}
onSelect={handleThemeSelect}
onHighlight={onHighlight}
isFocused={currenFocusedSection === 'theme'}
Expand Down
15 changes: 11 additions & 4 deletions packages/cli/src/ui/components/shared/RadioButtonSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export function RadioButtonSelect<T>({
showScrollArrows = false,
maxItemsToShow = 10,
}: RadioButtonSelectProps<T>): React.JSX.Element {
const [activeIndex, setActiveIndex] = useState(initialIndex);
const validInitialIndex = items.length > 0 && initialIndex >= 0 && initialIndex < items.length ? initialIndex : 0;
const [activeIndex, setActiveIndex] = useState(validInitialIndex);
const [scrollOffset, setScrollOffset] = useState(0);

useEffect(() => {
Expand All @@ -76,15 +77,21 @@ export function RadioButtonSelect<T>({
if (input === 'k' || key.upArrow) {
const newIndex = activeIndex > 0 ? activeIndex - 1 : items.length - 1;
setActiveIndex(newIndex);
onHighlight?.(items[newIndex]!.value);
if (items[newIndex]) {
onHighlight?.(items[newIndex].value);
}
}
if (input === 'j' || key.downArrow) {
const newIndex = activeIndex < items.length - 1 ? activeIndex + 1 : 0;
setActiveIndex(newIndex);
onHighlight?.(items[newIndex]!.value);
if (items[newIndex]) {
onHighlight?.(items[newIndex].value);
}
}
if (key.return) {
onSelect(items[activeIndex]!.value);
if (items[activeIndex]) {
onSelect(items[activeIndex].value);
}
}

// Enable selection directly from number keys.
Expand Down