Skip to content

feat: Add visibility toggle for API key inputs #6114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions webview-ui/src/components/common/ApiKeyInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useState } from "react"
import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react"

type ApiKeyInputProps = {
value: string
onInput: (event: Event | React.FormEvent<HTMLElement>) => void
placeholder: string
label: string
className?: string
name?: string
children?: React.ReactNode
}

export const ApiKeyInput = ({ value, onInput, placeholder, label, className, name, children }: ApiKeyInputProps) => {
const [showApiKey, setShowApiKey] = useState(false)

return (
<div className={`relative w-full ${className || ""}`}>
<VSCodeTextField
name={name}
value={value}
type={showApiKey ? "text" : "password"}
onInput={onInput}
placeholder={placeholder}
className="w-full pr-10">
<label className="block font-medium mb-1">{label}</label>
{children}
</VSCodeTextField>
<div
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider replacing the clickable

used for toggling API key visibility with a element that includes an appropriate aria-label for better accessibility.

className="absolute inset-y-0 right-0 flex items-center pr-3 cursor-pointer"
style={{ top: "1.5rem" }}
onClick={() => setShowApiKey(!showApiKey)}>
{showApiKey ? (
<span className="codicon codicon-eye"></span>
) : (
<span className="codicon codicon-eye-closed"></span>
)}
</div>
</div>
)
}
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/Anthropic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ProviderSettings } from "@roo-code/types"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform, noTransform } from "../transforms"

Expand All @@ -32,14 +33,12 @@ export const Anthropic = ({ apiConfiguration, setApiConfigurationField }: Anthro

return (
<>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.apiKey || ""}
type="password"
onInput={handleInputChange("apiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.anthropicApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.anthropicApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
25 changes: 10 additions & 15 deletions webview-ui/src/components/settings/providers/Bedrock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type ProviderSettings, type ModelInfo, BEDROCK_REGIONS } from "@roo-cod

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, StandardTooltip } from "@src/components/ui"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform, noTransform } from "../transforms"

Expand Down Expand Up @@ -59,30 +60,24 @@ export const Bedrock = ({ apiConfiguration, setApiConfigurationField, selectedMo
</VSCodeTextField>
) : (
<>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.awsAccessKey || ""}
type="password"
onInput={handleInputChange("awsAccessKey")}
placeholder={t("settings:placeholders.accessKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.awsAccessKey")}</label>
</VSCodeTextField>
<VSCodeTextField
label={t("settings:providers.awsAccessKey")}
/>
<ApiKeyInput
value={apiConfiguration?.awsSecretKey || ""}
type="password"
onInput={handleInputChange("awsSecretKey")}
placeholder={t("settings:placeholders.secretKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.awsSecretKey")}</label>
</VSCodeTextField>
<VSCodeTextField
label={t("settings:providers.awsSecretKey")}
/>
<ApiKeyInput
value={apiConfiguration?.awsSessionToken || ""}
type="password"
onInput={handleInputChange("awsSessionToken")}
placeholder={t("settings:placeholders.sessionToken")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.awsSessionToken")}</label>
</VSCodeTextField>
label={t("settings:providers.awsSessionToken")}
/>
</>
)}
<div>
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/Chutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ProviderSettings } from "@roo-code/types"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"

Expand All @@ -29,14 +30,12 @@ export const Chutes = ({ apiConfiguration, setApiConfigurationField }: ChutesPro

return (
<>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.chutesApiKey || ""}
type="password"
onInput={handleInputChange("chutesApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.chutesApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.chutesApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/DeepSeek.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ProviderSettings } from "@roo-code/types"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"

Expand All @@ -29,14 +30,12 @@ export const DeepSeek = ({ apiConfiguration, setApiConfigurationField }: DeepSee

return (
<>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.deepSeekApiKey || ""}
type="password"
onInput={handleInputChange("deepSeekApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.deepSeekApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.deepSeekApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/Gemini.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ProviderSettings } from "@roo-code/types"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"

Expand Down Expand Up @@ -34,14 +35,12 @@ export const Gemini = ({ apiConfiguration, setApiConfigurationField }: GeminiPro

return (
<>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.geminiApiKey || ""}
type="password"
onInput={handleInputChange("geminiApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.geminiApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.geminiApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/Glama.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { RouterModels } from "@roo/api"
import { useAppTranslation } from "@src/i18n/TranslationContext"
import { getGlamaAuthUrl } from "@src/oauth/urls"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"
import { ModelPicker } from "../ModelPicker"
Expand Down Expand Up @@ -44,14 +45,12 @@ export const Glama = ({

return (
<>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.glamaApiKey || ""}
type="password"
onInput={handleInputChange("glamaApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.glamaApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.glamaApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/Groq.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ProviderSettings } from "@roo-code/types"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"

Expand All @@ -29,14 +30,12 @@ export const Groq = ({ apiConfiguration, setApiConfigurationField }: GroqProps)

return (
<>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.groqApiKey || ""}
type="password"
onInput={handleInputChange("groqApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.groqApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.groqApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/LiteLLM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { vscode } from "@src/utils/vscode"
import { useExtensionState } from "@src/context/ExtensionStateContext"
import { useAppTranslation } from "@src/i18n/TranslationContext"
import { Button } from "@src/components/ui"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"
import { ModelPicker } from "../ModelPicker"
Expand Down Expand Up @@ -98,14 +99,12 @@ export const LiteLLM = ({
<label className="block font-medium mb-1">{t("settings:providers.litellmBaseUrl")}</label>
</VSCodeTextField>

<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.litellmApiKey || ""}
type="password"
onInput={handleInputChange("litellmApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.litellmApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.litellmApiKey")}
/>

<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/Mistral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { RouterModels } from "@roo/api"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"

Expand All @@ -32,14 +33,12 @@ export const Mistral = ({ apiConfiguration, setApiConfigurationField }: MistralP

return (
<>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.mistralApiKey || ""}
type="password"
onInput={handleInputChange("mistralApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<span className="font-medium">{t("settings:providers.mistralApiKey")}</span>
</VSCodeTextField>
label={t("settings:providers.mistralApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/Moonshot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ProviderSettings } from "@roo-code/types"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"
import { cn } from "@/lib/utils"
Expand Down Expand Up @@ -45,14 +46,12 @@ export const Moonshot = ({ apiConfiguration, setApiConfigurationField }: Moonsho
</VSCodeDropdown>
</div>
<div>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.moonshotApiKey || ""}
type="password"
onInput={handleInputChange("moonshotApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.moonshotApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.moonshotApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
9 changes: 4 additions & 5 deletions webview-ui/src/components/settings/providers/OpenAI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ProviderSettings } from "@roo-code/types"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { VSCodeButtonLink } from "@src/components/common/VSCodeButtonLink"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { inputEventTransform } from "../transforms"

Expand Down Expand Up @@ -56,14 +57,12 @@ export const OpenAI = ({ apiConfiguration, setApiConfigurationField }: OpenAIPro
/>
</>
)}
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.openAiNativeApiKey || ""}
type="password"
onInput={handleInputChange("openAiNativeApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.openAiApiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.openAiApiKey")}
/>
<div className="text-sm text-vscode-descriptionForeground -mt-2">
{t("settings:providers.apiKeyStorageNotice")}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ExtensionMessage } from "@roo/ExtensionMessage"

import { useAppTranslation } from "@src/i18n/TranslationContext"
import { Button, StandardTooltip } from "@src/components/ui"
import { ApiKeyInput } from "@src/components/common/ApiKeyInput"

import { convertHeadersToObject } from "../utils/headers"
import { inputEventTransform, noTransform } from "../transforms"
Expand Down Expand Up @@ -129,14 +130,12 @@ export const OpenAICompatible = ({
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.openAiBaseUrl")}</label>
</VSCodeTextField>
<VSCodeTextField
<ApiKeyInput
value={apiConfiguration?.openAiApiKey || ""}
type="password"
onInput={handleInputChange("openAiApiKey")}
placeholder={t("settings:placeholders.apiKey")}
className="w-full">
<label className="block font-medium mb-1">{t("settings:providers.apiKey")}</label>
</VSCodeTextField>
label={t("settings:providers.apiKey")}
/>
<ModelPicker
apiConfiguration={apiConfiguration}
setApiConfigurationField={setApiConfigurationField}
Expand Down
Loading
Loading