Skip to content

Commit a968cc3

Browse files
authored
Merge pull request #615 from psv2522/change-select-to-dropdown
fix: Use Dropdown instead of select in settings for more UI consistency
2 parents 7669477 + 7e38e50 commit a968cc3

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

webview-ui/src/components/settings/ApiConfigManager.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { VSCodeButton, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
22
import { memo, useEffect, useRef, useState } from "react"
33
import { ApiConfigMeta } from "../../../../src/shared/ExtensionMessage"
4+
import { Dropdown } from "vscrui"
5+
import type { DropdownOption } from "vscrui"
46

57
interface ApiConfigManagerProps {
68
currentApiConfigName?: string
@@ -133,28 +135,21 @@ const ApiConfigManager = ({
133135
) : (
134136
<>
135137
<div style={{ display: "flex", gap: "4px", alignItems: "center" }}>
136-
<select
138+
<Dropdown
137139
id="config-profile"
138140
value={currentApiConfigName}
139-
onChange={(e) => onSelectConfig(e.target.value)}
141+
onChange={(value: unknown) => {
142+
onSelectConfig((value as DropdownOption).value)
143+
}}
140144
style={{
141-
flexGrow: 1,
142-
padding: "4px 8px",
143-
paddingRight: "24px",
144-
backgroundColor: "var(--vscode-dropdown-background)",
145-
color: "var(--vscode-dropdown-foreground)",
146-
border: "1px solid var(--vscode-dropdown-border)",
147-
borderRadius: "2px",
148-
height: "28px",
149-
cursor: "pointer",
150-
outline: "none",
151-
}}>
152-
{listApiConfigMeta?.map((config) => (
153-
<option key={config.name} value={config.name}>
154-
{config.name}
155-
</option>
156-
))}
157-
</select>
145+
minWidth: 130,
146+
}}
147+
role="combobox"
148+
options={listApiConfigMeta.map((config) => ({
149+
value: config.name,
150+
label: config.name,
151+
}))}
152+
/>
158153
<VSCodeButton
159154
appearance="icon"
160155
onClick={handleAdd}

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import ApiOptions from "./ApiOptions"
77
import ExperimentalFeature from "./ExperimentalFeature"
88
import { EXPERIMENT_IDS, experimentConfigsMap } from "../../../../src/shared/experiments"
99
import ApiConfigManager from "./ApiConfigManager"
10+
import { Dropdown } from "vscrui"
11+
import type { DropdownOption } from "vscrui"
1012

1113
type SettingsViewProps = {
1214
onDone: () => void
@@ -451,23 +453,21 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
451453
<h3 style={{ color: "var(--vscode-foreground)", margin: "0 0 15px 0" }}>Browser Settings</h3>
452454
<div style={{ marginBottom: 15 }}>
453455
<label style={{ fontWeight: "500", display: "block", marginBottom: 5 }}>Viewport size</label>
454-
<select
455-
value={browserViewportSize}
456-
onChange={(e) => setBrowserViewportSize(e.target.value)}
457-
style={{
458-
width: "100%",
459-
padding: "4px 8px",
460-
backgroundColor: "var(--vscode-input-background)",
461-
color: "var(--vscode-input-foreground)",
462-
border: "1px solid var(--vscode-input-border)",
463-
borderRadius: "2px",
464-
height: "28px",
465-
}}>
466-
<option value="1280x800">Large Desktop (1280x800)</option>
467-
<option value="900x600">Small Desktop (900x600)</option>
468-
<option value="768x1024">Tablet (768x1024)</option>
469-
<option value="360x640">Mobile (360x640)</option>
470-
</select>
456+
<div className="dropdown-container">
457+
<Dropdown
458+
value={browserViewportSize}
459+
onChange={(value: unknown) => {
460+
setBrowserViewportSize((value as DropdownOption).value)
461+
}}
462+
style={{ width: "100%" }}
463+
options={[
464+
{ value: "1280x800", label: "Large Desktop (1280x800)" },
465+
{ value: "900x600", label: "Small Desktop (900x600)" },
466+
{ value: "768x1024", label: "Tablet (768x1024)" },
467+
{ value: "360x640", label: "Mobile (360x640)" },
468+
]}
469+
/>
470+
</div>
471471
<p
472472
style={{
473473
fontSize: "12px",

webview-ui/src/components/settings/__tests__/ApiConfigManager.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ jest.mock("@vscode/webview-ui-toolkit/react", () => ({
1919
),
2020
}))
2121

22+
jest.mock("vscrui", () => ({
23+
Dropdown: ({ id, value, onChange, options, role }: any) => (
24+
<div data-testid={`mock-dropdown-${id}`}>
25+
<select value={value} onChange={(e) => onChange({ value: e.target.value })} data-testid={id} role={role}>
26+
{options.map((opt: any) => (
27+
<option key={opt.value} value={opt.value}>
28+
{opt.label}
29+
</option>
30+
))}
31+
</select>
32+
</div>
33+
),
34+
}))
35+
2236
describe("ApiConfigManager", () => {
2337
const mockOnSelectConfig = jest.fn()
2438
const mockOnDeleteConfig = jest.fn()

0 commit comments

Comments
 (0)