Skip to content

Commit 28cd2a2

Browse files
fix: revert boolean field from Switch back to native checkbox
The PR had swapped the boolean <Input type="checkbox"> for a shadcn <Switch>, which dropped the `required` attribute (Switch had none) and added a capitalized "True"/"False" label. Revert to the native checkbox that the Inspector used previously: it natively supports `required` (restoring parity with every other field) and removes the label, so the control is consistent with the rest of the form again. Reverts the boolean test assertions from role="switch"/aria-checked back to role="checkbox" in both component test files. Addresses review items modelcontextprotocol#3 (required dropped) and modelcontextprotocol#5 (True/False label) on modelcontextprotocol#1258 by removing the Switch change that introduced them. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1 parent df40cf6 commit 28cd2a2

3 files changed

Lines changed: 23 additions & 28 deletions

File tree

‎client/src/components/DynamicJsonForm.tsx‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import { Button } from "@/components/ui/button";
1010
import { Input } from "@/components/ui/input";
1111
import { Textarea } from "@/components/ui/textarea";
12-
import { Switch } from "@/components/ui/switch";
1312
import JsonEditor from "./JsonEditor";
1413
import { updateValueAtPath } from "@/utils/jsonUtils";
1514
import { generateDefaultValue, normalizeUnionType } from "@/utils/schemaUtils";
@@ -571,23 +570,19 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(
571570

572571
case "boolean":
573572
return (
574-
<div className="space-y-1">
573+
<div className="space-y-2">
575574
{propSchema.description && (
576-
<p className="text-xs text-gray-500 dark:text-gray-400">
575+
<p className="text-sm text-gray-600">
577576
{propSchema.description}
578577
</p>
579578
)}
580-
<div className="flex items-center gap-3 py-1">
581-
<Switch
582-
checked={(currentValue as boolean) ?? false}
583-
onCheckedChange={(checked) =>
584-
handleFieldChange(path, checked)
585-
}
586-
/>
587-
<span className="text-sm text-gray-600 dark:text-gray-400">
588-
{(currentValue as boolean) ? "True" : "False"}
589-
</span>
590-
</div>
579+
<Input
580+
type="checkbox"
581+
checked={(currentValue as boolean) ?? false}
582+
onChange={(e) => handleFieldChange(path, e.target.checked)}
583+
className="w-4 h-4"
584+
required={isRequired}
585+
/>
591586
</div>
592587
);
593588
case "null":

‎client/src/components/__tests__/DynamicJsonForm.array.test.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ describe("DynamicJsonForm Array Fields", () => {
205205
};
206206
renderSimpleArrayForm({ schema, value: [true, false] });
207207

208-
// Should render Switch toggles (role="switch") for boolean items
209-
const switches = screen.getAllByRole("switch");
210-
expect(switches).toHaveLength(2);
208+
// Should render form fields (checkboxes)
209+
const checkboxes = screen.getAllByRole("checkbox");
210+
expect(checkboxes).toHaveLength(2);
211211
});
212212

213213
it("should detect simple object arrays as simple", () => {
@@ -332,10 +332,10 @@ describe("DynamicJsonForm Array Fields", () => {
332332
const onChange = jest.fn();
333333
renderSimpleArrayForm({ schema, value: [true, false], onChange });
334334

335-
const switches = screen.getAllByRole("switch");
336-
expect(switches).toHaveLength(2);
337-
expect(switches[0]).toHaveAttribute("aria-checked", "true");
338-
expect(switches[1]).toHaveAttribute("aria-checked", "false");
335+
const checkboxes = screen.getAllByRole("checkbox");
336+
expect(checkboxes).toHaveLength(2);
337+
expect(checkboxes[0]).toHaveProperty("checked", true);
338+
expect(checkboxes[1]).toHaveProperty("checked", false);
339339

340340
// Test adding new boolean item
341341
const addButton = screen.getByText("Add Item");

‎client/src/components/__tests__/DynamicJsonForm.test.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ describe("DynamicJsonForm Number Fields", () => {
434434

435435
describe("DynamicJsonForm Boolean Fields", () => {
436436
describe("Basic Operations", () => {
437-
it("should render switch for boolean type", () => {
437+
it("should render checkbox for boolean type", () => {
438438
const schema: JsonSchemaType = {
439439
type: "boolean",
440440
description: "Enable notifications",
@@ -443,8 +443,8 @@ describe("DynamicJsonForm Boolean Fields", () => {
443443
<DynamicJsonForm schema={schema} value={false} onChange={jest.fn()} />,
444444
);
445445

446-
const toggle = screen.getByRole("switch");
447-
expect(toggle).toHaveAttribute("aria-checked", "false");
446+
const checkbox = screen.getByRole("checkbox");
447+
expect(checkbox).toHaveProperty("type", "checkbox");
448448
});
449449

450450
it("should call onChange with boolean value", () => {
@@ -457,8 +457,8 @@ describe("DynamicJsonForm Boolean Fields", () => {
457457
<DynamicJsonForm schema={schema} value={false} onChange={onChange} />,
458458
);
459459

460-
const toggle = screen.getByRole("switch");
461-
fireEvent.click(toggle);
460+
const checkbox = screen.getByRole("checkbox");
461+
fireEvent.click(checkbox);
462462

463463
expect(onChange).toHaveBeenCalledWith(true);
464464
});
@@ -472,8 +472,8 @@ describe("DynamicJsonForm Boolean Fields", () => {
472472
<DynamicJsonForm schema={schema} value={false} onChange={jest.fn()} />,
473473
);
474474

475-
const toggle = screen.getByRole("switch");
476-
expect(toggle).toHaveAttribute("aria-checked", "false");
475+
const checkbox = screen.getByRole("checkbox");
476+
expect(checkbox).toHaveProperty("checked", false);
477477
});
478478
});
479479
});

0 commit comments

Comments
 (0)