Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): unify builder field accessibility and DOM identity (#12844)

djpjronline-netizen72d498a7e2b6
diff --git a/autogpt_platform/frontend/src/components/atoms/DateInput/DateInput.tsx b/autogpt_platform/frontend/src/components/atoms/DateInput/DateInput.tsx
index 58ba1b2f95..a3555e1b9a 100644
--- a/autogpt_platform/frontend/src/components/atoms/DateInput/DateInput.tsx
+++ b/autogpt_platform/frontend/src/components/atoms/DateInput/DateInput.tsx
@@ -41,6 +41,9 @@ export interface DateInputProps {
error?: string;
id?: string;
size?: "default" | "small";
+ "aria-label"?: string;
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
}
export const DateInput = ({
@@ -56,6 +59,9 @@ export const DateInput = ({
error,
id,
size = "default",
+ "aria-label": ariaLabel,
+ "aria-labelledby": ariaLabelledBy,
+ "aria-describedby": ariaDescribedBy,
}: DateInputProps) => {
const selected = React.useMemo(() => parseISODateString(value), [value]);
const [open, setOpen] = React.useState(false);
@@ -116,7 +122,9 @@ export const DateInput = ({
disabled={isDisabled}
autoFocus={autoFocus}
id={id}
- {...(hideLabel && label ? { "aria-label": label } : {})}
+ aria-label={ariaLabel ?? (hideLabel && label ? label : undefined)}
+ aria-labelledby={ariaLabelledBy}
+ aria-describedby={ariaDescribedBy}
>
<CalendarIcon
className={cn("mr-2", size === "default" ? "h-4 w-4" : "h-3 w-3")}
diff --git a/autogpt_platform/frontend/src/components/atoms/DateTimeInput/DateTimeInput.tsx b/autogpt_platform/frontend/src/components/atoms/DateTimeInput/DateTimeInput.tsx
index 53e3853c77..f3c6e9fe4f 100644
--- a/autogpt_platform/frontend/src/components/atoms/DateTimeInput/DateTimeInput.tsx
+++ b/autogpt_platform/frontend/src/components/atoms/DateTimeInput/DateTimeInput.tsx
@@ -45,6 +45,9 @@ export interface DateTimeInputProps {
id?: string;
size?: "default" | "small";
wrapperClassName?: string;
+ "aria-label"?: string;
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
}
export const DateTimeInput = ({
@@ -62,10 +65,14 @@ export const DateTimeInput = ({
id,
size = "default",
wrapperClassName,
+ "aria-label": ariaLabel,
+ "aria-labelledby": ariaLabelledBy,
+ "aria-describedby": ariaDescribedBy,
}: DateTimeInputProps) => {
const selected = React.useMemo(() => parseISODateTimeString(value), [value]);
const [open, setOpen] = React.useState(false);
const [timeValue, setTimeValue] = React.useState("");
+ const timeInputId = React.useId();
// Update time value when selected date changes
React.useEffect(() => {
@@ -180,7 +187,9 @@ export const DateTimeInput = ({
disabled={isDisabled}
autoFocus={autoFocus}
id={id}
- {...(hideLabel && label ? { "aria-label": label } : {})}
+ aria-label={ariaLabel ?? (hideLabel && label ? label : undefined)}
+ aria-labelledby={ariaLabelledBy}
+ aria-describedby={ariaDescribedBy}
>
<CalendarIcon
className={cn("mr-2", size === "default" ? "h-4 w-4" : "h-3 w-3")}
@@ -203,10 +212,14 @@ export const DateTimeInput = ({
}}
/>
<div className="mt-3 border-t pt-3">
- <label className="mb-2 block text-sm font-medium text-gray-700">
+ <label
+ htmlFor={timeInputId}
+ className="mb-2 block text-sm font-medium text-gray-700"
+ >
Time
</label>
<input
+ id={timeInputId}
type="time"
value={timeValue}
onChange={(e) => handleTimeChange(e.target.value)}
diff --git a/autogpt_platform/frontend/src/components/atoms/Input/Input.tsx b/autogpt_platform/frontend/src/components/atoms/Input/Input.tsx
index a3f9f27dc0..bbe49c9a90 100644
--- a/autogpt_platform/frontend/src/components/atoms/Input/Input.tsx
+++ b/autogpt_platform/frontend/src/components/atoms/Input/Input.tsx
@@ -137,7 +137,11 @@ export const Input = forwardRef<InputElement, TextFieldProps>(function Input(
onChange={handleTextareaChange}
onKeyDown={guardedOnKeyDown}
rows={props.rows || 3}
- {...(hideLabel ? { "aria-label": label } : {})}
+ aria-label={
+ props["aria-label"] ?? (hideLabel && label ? label : undefined)
+ }
+ aria-labelledby={props["aria-labelledby"]}
+ aria-describedby={props["aria-describedby"]}
id={inputId}
disabled={props.disabled}
value={props.value}
@@ -176,7 +180,11 @@ export const Input = forwardRef<InputElement, TextFieldProps>(function Input(
groupSeparator=","
decimalSeparator="."
allowNegativeValue
- {...(hideLabel ? { "aria-label": label } : {})}
+ aria-label={
+ props["aria-label"] ?? (hideLabel && label ? label : undefined)
+ }
+ aria-labelledby={props["aria-labelledby"]}
+ aria-describedby={props["aria-describedby"]}
// Pass through common handlers
onBlur={props.onBlur as any}
onFocus={props.onFocus as any}
@@ -209,7 +217,7 @@ export const Input = forwardRef<InputElement, TextFieldProps>(function Input(
)}
placeholder={placeholder || label}
onChange={handleInputChange}
- {...(hideLabel ? { "aria-label": label } : {})}
+ {...(hideLabel && label ? { "aria-label": label } : {})}
{...props}
id={inputId}
onKeyDown={guardedOnKeyDown}
diff --git a/autogpt_platform/frontend/src/components/atoms/Select/Select.tsx b/autogpt_platform/frontend/src/components/atoms/Select/Select.tsx
index c5c2ae30e8..6ac1a5e64a 100644
--- a/autogpt_platform/frontend/src/components/atoms/Select/Select.tsx
+++ b/autogpt_platform/frontend/src/components/atoms/Select/Select.tsx
@@ -42,6 +42,9 @@ export interface SelectFieldProps {
labelTooltip?: string;
renderItem?: (option: SelectOption) => React.ReactNode;
wrapperClassName?: string;
+ "aria-label"?: string;
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
}
export function Select({
@@ -62,6 +65,9 @@ export function Select({
labelTooltip,
renderItem,
wrapperClassName,
+ "aria-label": ariaLabel,
+ "aria-labelledby": ariaLabelledBy,
+ "aria-describedby": ariaDescribedBy,
}: SelectFieldProps) {
const triggerStyles = cn(
// Base styles matching Input
@@ -90,7 +96,9 @@ export function Select({
<BaseSelect value={value} onValueChange={onValueChange} disabled={disabled}>
<SelectTrigger
className={triggerStyles}
- {...(hideLabel ? { "aria-label": label } : {})}
+ aria-label={ariaLabel ?? (hideLabel && label ? label : undefined)}
+ aria-labelledby={ariaLabelledBy}
+ aria-describedby={ariaDescribedBy}
id={id}
>
<SelectValue placeholder={placeholder || label} />
diff --git a/autogpt_platform/frontend/src/components/atoms/TimeInput/TimeInput.tsx b/autogpt_platform/frontend/src/components/atoms/TimeInput/TimeInput.tsx
index 2b03c4e660..eb5f02288a 100644
--- a/autogpt_platform/frontend/src/components/atoms/TimeInput/TimeInput.tsx
+++ b/autogpt_platform/frontend/src/components/atoms/TimeInput/TimeInput.tsx
@@ -15,6 +15,9 @@ interface TimeInputProps {
hint?: ReactNode;
size?: "small" | "medium";
wrapperClassName?: string;
+ "aria-label"?: string;
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
}
export const TimeInput: React.FC<TimeInputProps> = ({
@@ -30,6 +33,9 @@ export const TimeInput: React.FC<TimeInputProps> = ({
hint,
size = "medium",
wrapperClassName,
+ "aria-label": ariaLabel,
+ "aria-labelledby": ariaLabelledBy,
+ "aria-describedby": ariaDescribedBy,
}) => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange?.(e.target.value);
@@ -71,7 +77,9 @@ export const TimeInput: React.FC<TimeInputProps> = ({
)}
disabled={disabled}
placeholder={placeholder || label}
- {...(hideLabel ? { "aria-label": label } : {})}
+ aria-label={ariaLabel ?? (hideLabel && label ? label : undefined)}
+ aria-labelledby={ariaLabelledBy}
+ aria-describedby={ariaDescribedBy}
id={id}
/>
</div>
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/FormRenderer.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/FormRenderer.tsx
index 96f3e91634..422b781062 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/FormRenderer.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/FormRenderer.tsx
@@ -1,6 +1,6 @@
import { cn } from "@/lib/utils";
import { RJSFSchema } from "@rjsf/utils";
-import { useMemo } from "react";
+import { useId, useMemo } from "react";
import Form from "./registry";
import { ExtendedFormContextType } from "./types";
import { customValidator } from "./utils/custom-validator";
@@ -24,6 +24,7 @@ export function FormRenderer({
formContext,
className,
}: FormRendererProps) {
+ const domIdPrefix = `${useId()}-`;
const preprocessedSchema = useMemo(() => {
return preprocessInputSchema(jsonSchema);
}, [jsonSchema]);
@@ -36,7 +37,7 @@ export function FormRenderer({
return (
<div className={cn("mt-4", className)} data-tutorial-id="input-handles">
<Form
- formContext={formContext}
+ formContext={{ ...formContext, domIdPrefix }}
idPrefix="agpt"
idSeparator="_%_"
schema={preprocessedSchema}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/CodeGenerationTransport.test.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/CodeGenerationTransport.test.tsx
index f2d6ffaa13..f6d5e3b6b7 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/CodeGenerationTransport.test.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/CodeGenerationTransport.test.tsx
@@ -17,18 +17,27 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
vi.mock("@/components/atoms/Select/Select", () => {
function Select({
id,
+ label,
+ "aria-labelledby": labelledBy,
+ "aria-describedby": describedBy,
value,
onValueChange,
options,
}: {
id: string;
+ label: string;
+ "aria-labelledby"?: string;
+ "aria-describedby"?: string;
value?: string;
onValueChange?: (value: string) => void;
options: { value: string; label: string }[];
}) {
return (
<select
- aria-label={id}
+ id={id}
+ aria-label={label}
+ aria-labelledby={labelledBy}
+ aria-describedby={describedBy}
value={value ?? ""}
onChange={(event) => onValueChange?.(event.target.value)}
>
@@ -186,7 +195,7 @@ describe("Code Generation transport fields", () => {
expect(screen.queryByText("System Prompt")).toBeNull();
expect(screen.queryByText("Reasoning Effort")).toBeNull();
- fireEvent.change(screen.getByLabelText("agpt_%_transport"), {
+ fireEvent.change(screen.getByLabelText("Transport"), {
target: { value: "1" },
});
@@ -225,7 +234,7 @@ function renderTransport(
}
function transportOptionLabels() {
- const select = screen.getByLabelText("agpt_%_transport");
+ const select = screen.getByLabelText("Transport");
return Array.from(select.querySelectorAll("option")).map(
(option) => option.textContent,
);
@@ -370,7 +379,7 @@ describe("Transport options gated by provider entitlement", () => {
it("does not touch the model dropdown, which no credential discriminates on", () => {
renderTransport({ openai: makeProvider("openai", "OpenAI", []) });
- const model = screen.getByLabelText("agpt_%_model");
+ const model = screen.getByLabelText("Codex Model");
expect(
Array.from(model.querySelectorAll("option")).map((o) => o.textContent),
).toEqual(["gpt-5.3-codex", "gpt-5.1-codex"]);
@@ -444,7 +453,7 @@ describe("An optional discriminator is still gated", () => {
</CredentialsProvidersContext.Provider>,
);
- const select = screen.getByLabelText("agpt_%_transport");
+ const select = screen.getByLabelText("Transport");
const labels = Array.from(select.querySelectorAll("option")).map(
(o) => o.textContent,
);
@@ -485,7 +494,7 @@ describe("An optional discriminator is still gated", () => {
</CredentialsProvidersContext.Provider>,
);
- const select = screen.getByLabelText("agpt_%_transport");
+ const select = screen.getByLabelText("Transport");
const platform = Array.from(select.querySelectorAll("option")).find(
(option) => option.textContent === "AutoGPT Platform",
);
@@ -572,7 +581,7 @@ describe("LLM blocks keep every model option", () => {
</CredentialsProvidersContext.Provider>,
);
- const model = screen.getByLabelText("agpt_%_model");
+ const model = screen.getByLabelText("Model");
expect(
Array.from(model.querySelectorAll("option")).map((o) => o.textContent),
).toEqual(["gpt-4o", "claude-opus-4-5-20251101", "llama3.3"]);
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/DictionaryValues.test.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/DictionaryValues.test.tsx
index 5505e56071..04ecaad9e7 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/DictionaryValues.test.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/DictionaryValues.test.tsx
@@ -107,7 +107,7 @@ describe("Dictionary input preservation", () => {
it("removes an entry only through its remove action", async () => {
render(<DictionaryForm values={{ title: "Remove this value" }} />);
- fireEvent.click(screen.getByRole("button", { name: /remove item/i }));
+ fireEvent.click(screen.getByRole("button", { name: /^remove$/i }));
await waitFor(() => {
expect(readDictionary()).toEqual({});
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/FieldAccessibility.test.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/FieldAccessibility.test.tsx
new file mode 100644
index 0000000000..a8142c491e
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/__tests__/FieldAccessibility.test.tsx
@@ -0,0 +1,351 @@
+import type { RJSFSchema } from "@rjsf/utils";
+import { getTestRegistry } from "@rjsf/core";
+import type { CustomNode } from "@/app/(platform)/build/components/FlowEditor/nodes/CustomNode/CustomNode";
+import { BlockUIType } from "@/app/(platform)/build/components/types";
+import { useNodeStore } from "@/app/(platform)/build/stores/nodeStore";
+import { render } from "@/tests/integrations/test-utils";
+import { act, fireEvent, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { FormRenderer } from "../FormRenderer";
+import Form from "../registry";
+import { customValidator } from "../utils/custom-validator";
+import { DateTimeInput } from "@/components/atoms/DateTimeInput/DateTimeInput";
+import {
+ MoveDownButton,
+ MoveUpButton,
+} from "../base/standard/buttons/IconButton";
+
+function node(id: string, error: string): CustomNode {
+ return {
+ id,
+ type: "custom",
+ position: { x: 0, y: 0 },
+ data: {
+ title: id,
+ description: "",
+ hardcodedValues: {},
+ inputSchema: {},
+ outputSchema: {},
+ uiType: BlockUIType.STANDARD,
+ block_id: "test-block",
+ costs: [],
+ categories: [],
+ errors: { field: error },
+ },
+ };
+}
+
+function form(
+ id: string,
+ property: RJSFSchema,
+ onChange = vi.fn(),
+ value?: unknown,
+) {
+ return (
+ <FormRenderer
+ jsonSchema={{
+ type: "object",
+ properties: {
+ field: {
+ ...property,
+ title: "Field",
+ description: "Helpful description",
+ },
+ },
+ }}
+ handleChange={onChange}
+ uiSchema={{
+ field: { "ui:options": { orderable: true, copyable: true } },
+ }}
+ initialValues={
+ value !== undefined
+ ? { field: value }
+ : property.type === "object"
+ ? { field: {} }
+ : property.type === "array"
+ ? { field: [] }
+ : {}
+ }
+ formContext={{
+ nodeId: id,
+ uiType: BlockUIType.STANDARD,
+ showHandles: false,
+ size: "small",
+ }}
+ />
+ );
+}
+
+afterEach(() => {
+ useNodeStore.setState({ nodes: [], nodeAdvancedStates: {} });
+});
+
+describe("field accessibility", () => {
+ it.each([
+ ["text", { type: "string" }],
+ ["number", { type: "number" }],
+ ["boolean", { type: "boolean" }],
+ ["select", { type: "string", enum: ["one", "two"] }],
+ ["date", { type: "string", format: "date" }],
+ ["datetime", { type: "string", format: "date-time" }],
+ ["time", { type: "string", format: "time" }],
+ [
+ "multiselect",
+ {
+ type: "array",
+ uniqueItems: true,
+ items: { type: "string", enum: ["one", "two"] },
+ },
+ ],
+ ] satisfies [string, RJSFSchema][])(
+ "associates the visible label with the %s control",
+ (_name, schema) => {
+ render(form("one", schema));
+ const control = screen.getByLabelText("Field");
+ const labelId = control.getAttribute("aria-labelledby");
+ expect(labelId).toBeTruthy();
+ expect(document.getElementById(labelId!)?.textContent).toBe("Field");
+ const descriptionIds =
+ control.getAttribute("aria-describedby")?.split(" ") ?? [];
+ expect(descriptionIds.length).toBeGreaterThan(0);
+ expect(descriptionIds.every((id) => document.getElementById(id))).toBe(
+ true,
+ );
+ },
+ );
+
+ it("keeps repeated node IDs unique and announces only each node's own error", () => {
+ useNodeStore.setState({
+ nodes: [node("one", "First error"), node("two", "Second error")],
+ });
+ const { container } = render(
+ <>
+ {form("one", { type: "string" })}
+ {form("two", { type: "string" })}
+ </>,
+ );
+ const ids = Array.from(container.querySelectorAll("[id]")).map(
+ (element) => element.id,
+ );
+ expect(new Set(ids).size).toBe(ids.length);
+ const controls = screen.getAllByLabelText("Field");
+ for (const [index, control] of controls.entries()) {
+ const description = control
+ .getAttribute("aria-describedby")
+ ?.split(" ")
+ .map((id) => document.getElementById(id)?.textContent)
+ .join(" ");
+ expect(description).toContain(
+ index === 0 ? "First error" : "Second error",
+ );
+ expect(description).not.toContain(
+ index === 0 ? "Second error" : "First error",
+ );
+ }
+ act(() => {
+ useNodeStore.setState({
+ nodes: [node("one", ""), node("two", "New error")],
+ });
+ });
+ const errorId = controls[1]
+ .getAttribute("aria-describedby")!
+ .split(" ")
+ .find(
+ (id) =>
+ document.getElementById(id)?.getAttribute("aria-live") === "polite",
+ );
+ expect(document.getElementById(errorId!)?.textContent).toBe("New error");
+ });
+
+ it("does not put the DOM namespace into stored field names", () => {
+ const onChange = vi.fn();
+ render(form("one", { type: "string" }, onChange));
+ fireEvent.change(screen.getByLabelText("Field"), {
+ target: { value: "saved value" },
+ });
+ expect(onChange.mock.calls.at(-1)?.[0].formData).toEqual({
+ field: "saved value",
+ });
+ });
+});
+
+it.each([
+ ["anyOf", { anyOf: [{ type: "string" }, { type: "integer" }] }],
+ [
+ "oneOf",
+ {
+ oneOf: [
+ { type: "string", title: "Text" },
+ { type: "number", title: "Number" },
+ ],
+ },
+ ],
+ ["array", { type: "array", items: { type: "string" } }],
+ ["dictionary", { type: "object", additionalProperties: { type: "string" } }],
+] satisfies [string, RJSFSchema][])(
+ "keeps IDs unique across repeated %s fields",
+ (_kind, schema) => {
+ const { container } = render(
+ <>
+ {form("one", schema)}
+ {form("two", schema)}
+ </>,
+ );
+ const ids = Array.from(container.querySelectorAll("[id]")).map(
+ (element) => element.id,
+ );
+ expect(ids.filter((id, index) => ids.indexOf(id) !== index)).toEqual([]);
+ },
+);
+
+it("labels nested JSON and links its own validation error", () => {
+ const jsonNode = node("one", "");
+ jsonNode.data.errors = { "field.payload": "Invalid payload" };
+ useNodeStore.setState({ nodes: [jsonNode] });
+ render(
+ form("one", {
+ type: "object",
+ properties: {
+ payload: {
+ type: "object",
+ title: "Payload",
+ description: "Structured payload",
+ },
+ },
+ }),
+ );
+ const input = screen.getByLabelText("payload");
+ const described = input
+ .getAttribute("aria-describedby")!
+ .split(" ")
+ .map((id) => document.getElementById(id)?.textContent)
+ .join(" ");
+ expect(described).toContain("Invalid payload");
+ expect(
+ screen.getByRole("button", { name: "Expand JSON input" }),
+ ).not.toBeNull();
+});
+
+it("labels the native time control inside a datetime popover", () => {
+ render(
+ <DateTimeInput id="meeting" label="Meeting" value="2026-09-22T09:00:00" />,
+ );
+ fireEvent.click(screen.getByRole("button", { name: /meeting/i }));
+ expect(screen.getByLabelText("Time").getAttribute("type")).toBe("time");
+});
+
+it("describes JSON fields once when the schema retains its description", () => {
+ render(
+ <Form
+ schema={{
+ type: "object",
+ properties: {
+ payload: {
+ type: "object",
+ title: "Payload",
+ description: "Structured payload",
+ },
+ },
+ }}
+ uiSchema={{ payload: { "ui:field": "custom/json_text_field" } }}
+ validator={customValidator}
+ formContext={{
+ nodeId: "one",
+ domIdPrefix: "description-",
+ showHandles: false,
+ uiType: BlockUIType.STANDARD,
+ }}
+ />,
+ );
+ const described = screen
+ .getByLabelText("Payload")
+ .getAttribute("aria-describedby")!
+ .split(" ")
+ .map((id) => document.getElementById(id)?.textContent)
+ .join(" ");
+ expect(described.match(/Structured payload/g)).toHaveLength(1);
+});
+
+it("names array actions for what they do and preserves their behavior", () => {
+ const onChange = vi.fn();
+ render(
+ form("one", { type: "array", items: { type: "string" } }, onChange, [
+ "first",
+ "second",
+ ]),
+ );
+ fireEvent.click(screen.getAllByRole("button", { name: /^copy$/i })[0]);
+ expect(onChange.mock.calls.at(-1)?.[0].formData.field).toEqual([
+ "first",
+ "first",
+ "second",
+ ]);
+ fireEvent.click(screen.getAllByRole("button", { name: /^remove$/i })[0]);
+ expect(onChange.mock.calls.at(-1)?.[0].formData.field).toEqual([
+ "first",
+ "second",
+ ]);
+});
+
+it.each([
+ ["Move up", MoveUpButton],
+ ["Move down", MoveDownButton],
+])("uses the same visible and accessible %s label", (label, Component) => {
+ const onClick = vi.fn();
+ render(<Component registry={getTestRegistry({})} onClick={onClick} />);
+ const button = screen.getByRole("button", { name: label });
+ expect(button.textContent?.trim()).toBe(label);
+ fireEvent.click(button);
+ expect(onClick).toHaveBeenCalledOnce();
+});
+
+it("keeps prefix-sharing and dollar keys independent of DOM IDs", () => {
+ const onChange = vi.fn();
+ const { container } = render(
+ form(
+ "one",
+ { type: "object", additionalProperties: { type: "string" } },
+ onChange,
+ { "cost$&": "first", "cost$&-test": "second" },
+ ),
+ );
+ const ids = Array.from(container.querySelectorAll("[id]")).map(
+ (element) => element.id,
+ );
+ expect(ids.filter((id, index) => ids.indexOf(id) !== index)).toEqual([]);
+ expect(screen.getByLabelText("cost$& key")).not.toBeNull();
+ expect(screen.getByLabelText("cost$&-test key")).not.toBeNull();
+ fireEvent.change(screen.getByDisplayValue("first"), {
+ target: { value: "changed" },
+ });
+ expect(onChange.mock.calls.at(-1)?.[0].formData.field).toEqual({
+ "cost$&": "changed",
+ "cost$&-test": "second",
+ });
+});
+
+it("names the expanded input and clipboard action", async () => {
+ const descriptor = Object.getOwnPropertyDescriptor(navigator, "clipboard");
+ const writeText = vi.fn().mockResolvedValue(undefined);
+ Object.defineProperty(navigator, "clipboard", {
+ configurable: true,
+ value: { writeText },
+ });
+ try {
+ render(form("one", { type: "string" }, vi.fn(), "copy this"));
+ fireEvent.click(screen.getByRole("button", { name: "Expand input" }));
+ expect(screen.getByRole("textbox", { name: "Field" })).not.toBeNull();
+ await act(async () => {
+ fireEvent.click(
+ screen.getByRole("button", { name: "Copy to clipboard" }),
+ );
+ });
+ expect(writeText).toHaveBeenCalledWith("copy this");
+ expect(
+ screen.getByRole("button", { name: "Copied to clipboard" }),
+ ).not.toBeNull();
+ } finally {
+ if (descriptor) Object.defineProperty(navigator, "clipboard", descriptor);
+ else Reflect.deleteProperty(navigator, "clipboard");
+ }
+});
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/anyof/AnyOfField.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/anyof/AnyOfField.tsx
index 0340ff03da..329e7eaabd 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/anyof/AnyOfField.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/anyof/AnyOfField.tsx
@@ -1,3 +1,4 @@
+import { useFieldAccessibilityContext } from "../../field-accessibility";
import { FieldProps, getUiOptions, getWidget } from "@rjsf/utils";
import { AnyOfFieldTitle } from "./components/AnyOfFieldTitle";
import isEmpty from "lodash/isEmpty";
@@ -23,6 +24,7 @@ export const AnyOfField = (props: FieldProps) => {
field_id,
} = useAnyOfField(props);
+ const accessibility = useFieldAccessibilityContext(field_id);
const isInputBroken = useNodeStore((state) => state.isInputBroken);
const parentCustomFieldId = findCustomFieldId(schema);
@@ -70,7 +72,12 @@ export const AnyOfField = (props: FieldProps) => {
const selector = (
<Widget
- id={field_id}
+ id={`${field_id}-variant`}
+ aria-describedby={
+ [accessibility?.descriptionId, accessibility?.errorId]
+ .filter(Boolean)
+ .join(" ") || undefined
+ }
name={`${props.name}${schema.oneOf ? "__oneof_select" : "__anyof_select"}`}
schema={{ type: "number", default: 0 }}
onChange={handleOptionChange}
@@ -89,7 +96,7 @@ export const AnyOfField = (props: FieldProps) => {
"border-red-500 bg-red-100 text-red-600 line-through",
)}
autofocus={props.autofocus}
- label=""
+ label={schema.title ? `${schema.title} — variant` : "Variant selector"}
hideLabel={true}
readonly={props.readonly}
/>
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/object/OptionalDataControlsTemplate.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/object/OptionalDataControlsTemplate.tsx
index dc53c6ce5b..0ac4de6d8b 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/object/OptionalDataControlsTemplate.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/object/OptionalDataControlsTemplate.tsx
@@ -1,3 +1,4 @@
+import { getFieldDomId } from "../../field-accessibility";
import { OptionalDataControlsTemplateProps } from "@rjsf/utils";
import { PlusCircle } from "lucide-react";
@@ -31,5 +32,5 @@ export default function OptionalDataControlsTemplate(
/>
);
}
- return <em id={id}>{label}</em>;
+ return <em id={getFieldDomId(id, registry.formContext)}>{label}</em>;
}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/object/WrapIfAdditionalTemplate.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/object/WrapIfAdditionalTemplate.tsx
index 0c38c63fd2..7a6671478f 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/object/WrapIfAdditionalTemplate.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/object/WrapIfAdditionalTemplate.tsx
@@ -1,3 +1,7 @@
+import {
+ getFieldDomId,
+ useFieldAccessibility,
+} from "../../field-accessibility";
import {
ADDITIONAL_PROPERTY_FLAG,
buttonId,
@@ -37,6 +41,11 @@ export default function WrapIfAdditionalTemplate(
const additional = ADDITIONAL_PROPERTY_FLAG in schema;
const { nodeId } = formContext;
const handleId = uiOptions.handleId;
+ const accessibility = useFieldAccessibility(
+ id,
+ `${label || "Property"} key`,
+ formContext,
+ );
const TitleFieldTemplate = getTemplate(
"TitleFieldTemplate",
@@ -53,10 +62,6 @@ export default function WrapIfAdditionalTemplate(
}
const keyId = `${id}-key`;
- const generateObjectPropertyTitleId = (id: string, label: string) => {
- return id.replace(`_${label}`, `_#_${label}`);
- };
- const title_id = generateObjectPropertyTitleId(id, label);
function handleBlur(e: React.FocusEvent<HTMLInputElement>) {
if (e.currentTarget.value === "") {
@@ -72,7 +77,7 @@ export default function WrapIfAdditionalTemplate(
<>
<div className={`mb-4 flex flex-col gap-1`} style={style}>
<TitleFieldTemplate
- id={titleId(title_id)}
+ id={titleId(id)}
title={`#${label}`}
required={required}
schema={schema}
@@ -82,12 +87,13 @@ export default function WrapIfAdditionalTemplate(
{!isHandleConnected && (
<div className="nodrag flex flex-1 items-center gap-2">
<Input
- label={""}
+ label={`${label || "Property"} key`}
hideLabel={true}
required={required}
defaultValue={label}
disabled={disabled || readonly}
- id={keyId}
+ id={getFieldDomId(keyId, formContext)}
+ aria-describedby={accessibility["aria-describedby"]}
wrapperClassName="mb-2 w-30"
name={keyId}
onBlur={!readonly ? handleBlur : undefined}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/oneof/OneOfField.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/oneof/OneOfField.tsx
index 9d96038453..2afe0f25ca 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/oneof/OneOfField.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/oneof/OneOfField.tsx
@@ -1,3 +1,7 @@
+import {
+ getFieldDomId,
+ useFieldAccessibilityContext,
+} from "../../field-accessibility";
import {
descriptionId,
FieldProps,
@@ -77,6 +81,7 @@ function DiscriminatedUnionField({
}
const [selectedIndex, setSelectedIndex] = useState(getInitialIndex);
+ const accessibility = useFieldAccessibilityContext(field_id);
// Generate handleId for sub-fields (same convention as AnyOfField)
const uiOptions = getUiOptions(props.uiSchema, props.globalUiOptions);
@@ -186,7 +191,12 @@ function DiscriminatedUnionField({
const selector = (
<Widget
- id={field_id}
+ id={`${field_id}-variant`}
+ aria-describedby={
+ [accessibility?.descriptionId, accessibility?.errorId]
+ .filter(Boolean)
+ .join(" ") || undefined
+ }
name={`${name}__oneof_select`}
schema={{ type: "number", default: 0 }}
onChange={handleVariantChange}
@@ -201,7 +211,7 @@ function DiscriminatedUnionField({
autocomplete={props.autocomplete}
className={cn("-ml-1 h-[22px] w-fit gap-1 px-1 pl-2 text-xs font-medium")}
autofocus={props.autofocus}
- label=""
+ label={schema.title ? `${schema.title} — variant` : "Variant selector"}
hideLabel={true}
readonly={props.readonly}
/>
@@ -217,7 +227,11 @@ function DiscriminatedUnionField({
return (
<div>
<div className="flex items-center gap-2">
- <Text variant="body" className="line-clamp-1">
+ <Text
+ id={getFieldDomId(`${field_id}__title`, registry.formContext)}
+ variant="body"
+ className="line-clamp-1"
+ >
{schema.title || name}
</Text>
<Text variant="small" className="mr-1 text-red-500">
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/DescriptionField.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/DescriptionField.tsx
index 455d6304db..c4cb6dee43 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/DescriptionField.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/DescriptionField.tsx
@@ -7,6 +7,7 @@ import {
} from "@/components/atoms/Tooltip/BaseTooltip";
import { InformationCircleIcon } from "@hugeicons/core-free-icons";
import { Icon } from "@/components/atoms/Icon/Icon";
+import { getFieldDomId } from "../../field-accessibility";
export default function DescriptionField(props: DescriptionFieldProps) {
const { id, description, registry, uiSchema } = props;
@@ -15,7 +16,10 @@ export default function DescriptionField(props: DescriptionFieldProps) {
}
return (
- <div id={id} className="0 inline w-fit">
+ <div
+ id={getFieldDomId(id, registry.formContext)}
+ className="0 inline w-fit"
+ >
<Tooltip>
<TooltipTrigger asChild>
<Icon
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/FieldError.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/FieldError.tsx
index e25a9bc80f..b38ce8b64b 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/FieldError.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/FieldError.tsx
@@ -4,9 +4,11 @@ import { Text } from "@/components/atoms/Text/Text";
export const FieldError = ({
nodeId,
fieldId,
+ id,
}: {
nodeId: string;
fieldId: string;
+ id?: string;
}) => {
const nodeErrors = useNodeStore((state) => {
const node = state.nodes.find((n) => n.id === nodeId);
@@ -16,7 +18,7 @@ export const FieldError = ({
nodeErrors?.[fieldId] || nodeErrors?.[fieldId.replace(/_%_/g, ".")] || null;
return (
- <div>
+ <div id={id} aria-live="polite" aria-atomic="true">
{fieldError && (
<Text variant="small" className="mt-1 pl-4 !text-red-600">
{fieldError}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/FieldTemplate.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/FieldTemplate.tsx
index 605d3ed7dc..4946b93100 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/FieldTemplate.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/FieldTemplate.tsx
@@ -22,6 +22,11 @@ import { useNodeStore } from "@/app/(platform)/build/stores/nodeStore";
import { useEdgeStore } from "@/app/(platform)/build/stores/edgeStore";
import { FieldError } from "./FieldError";
import { BlockUIType } from "@/app/(platform)/build/components/types";
+import {
+ FieldAccessibilityProvider,
+ getFieldDomId,
+ useFieldAccessibilityContext,
+} from "../../field-accessibility";
export default function FieldTemplate(props: FieldTemplateProps) {
const {
@@ -45,6 +50,7 @@ export default function FieldTemplate(props: FieldTemplateProps) {
readonly,
} = props;
const { nodeId, uiType } = registry.formContext;
+ const parentAccessibility = useFieldAccessibilityContext(id);
const { isInputConnected } = useEdgeStore();
const showAdvanced = useNodeStore(
@@ -101,45 +107,75 @@ export default function FieldTemplate(props: FieldTemplateProps) {
}
const marginBottom = isPartOfAnyOf({ uiOptions }) || isUnionSchema ? 0 : 16;
+ const domId = getFieldDomId(id, registry.formContext);
+ const accessibleDescriptionId =
+ parentAccessibility?.descriptionId ??
+ (rawDescription ? `${domId}-description` : undefined);
+ const errorId = parentAccessibility?.errorId ?? `${domId}-error`;
return (
- <WrapIfAdditionalTemplate
- classNames={classNames}
- style={style}
- disabled={disabled}
- id={id}
- label={label}
- displayLabel={displayLabel}
- onKeyRename={onKeyRename}
- onKeyRenameBlur={onKeyRenameBlur}
- onRemoveProperty={onRemoveProperty}
- rawDescription={rawDescription}
- readonly={readonly}
- required={required}
- schema={schema}
- uiSchema={updatedUiSchema}
- registry={registry}
+ <FieldAccessibilityProvider
+ value={{
+ fieldId: id,
+ labelId:
+ (shouldShowTitleSection && shouldDisplayLabel) || isUnionSchema
+ ? getFieldDomId(titleId(id), registry.formContext)
+ : parentAccessibility?.labelId,
+ descriptionId: accessibleDescriptionId,
+ errorId,
+ }}
>
- <div className="flex flex-col gap-2" style={{ marginBottom }}>
- {shouldShowTitleSection && (
- <div className="flex items-center gap-2">
- {shouldDisplayLabel && (
- <TitleFieldTemplate
- id={titleId(id)}
- title={label}
- required={required}
- schema={schema}
- uiSchema={updatedUiSchema}
- registry={registry}
- />
- )}
- {shouldDisplayLabel && rawDescription && <span>{description}</span>}
- </div>
- )}
- {shouldShowChildren && children}
+ <WrapIfAdditionalTemplate
+ classNames={classNames}
+ style={style}
+ disabled={disabled}
+ id={id}
+ label={label}
+ displayLabel={displayLabel}
+ onKeyRename={onKeyRename}
+ onKeyRenameBlur={onKeyRenameBlur}
+ onRemoveProperty={onRemoveProperty}
+ rawDescription={rawDescription}
+ readonly={readonly}
+ required={required}
+ schema={schema}
+ uiSchema={updatedUiSchema}
+ registry={registry}
+ >
+ <div className="flex flex-col gap-2" style={{ marginBottom }}>
+ {shouldShowTitleSection && (
+ <div className="flex items-center gap-2">
+ {shouldDisplayLabel && (
+ <TitleFieldTemplate
+ id={titleId(id)}
+ title={label}
+ required={required}
+ schema={schema}
+ uiSchema={updatedUiSchema}
+ registry={registry}
+ />
+ )}
+ {shouldDisplayLabel && rawDescription && (
+ <span>{description}</span>
+ )}
+ </div>
+ )}
+ {shouldShowChildren && children}
- <FieldError nodeId={nodeId} fieldId={cleanUpHandleId(id)} />
- </div>
- </WrapIfAdditionalTemplate>
+ {rawDescription && !parentAccessibility?.descriptionId && (
+ <span id={accessibleDescriptionId} className="sr-only">
+ {rawDescription}
+ </span>
+ )}
+ {!parentAccessibility && (
+ <FieldError
+ nodeId={nodeId}
+ fieldId={cleanUpHandleId(id)}
+ id={errorId}
+ />
+ )}
+ </div>
+ </WrapIfAdditionalTemplate>
+ </FieldAccessibilityProvider>
);
}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/TitleField.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/TitleField.tsx
index 196338041d..98621ce0b7 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/TitleField.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/TitleField.tsx
@@ -12,6 +12,7 @@ import { cn } from "@/lib/utils";
import { cleanUpHandleId, isArrayItem } from "../../helpers";
import { InputNodeHandle } from "@/app/(platform)/build/components/FlowEditor/handlers/NodeHandle";
import { useNodeStore } from "@/app/(platform)/build/stores/nodeStore";
+import { getFieldDomId } from "../../field-accessibility";
export default function TitleField(props: TitleFieldProps) {
const { id, title, required, schema, registry, uiSchema } = props;
@@ -41,7 +42,7 @@ export default function TitleField(props: TitleFieldProps) {
)}
<Text
variant={isArrayItemFlag ? "small" : "body"}
- id={id}
+ id={getFieldDomId(id, registry.formContext)}
className={cn(
"line-clamp-1",
smallText && "text-sm text-zinc-700",
@@ -57,7 +58,7 @@ export default function TitleField(props: TitleFieldProps) {
<Text
variant="small"
className={cn("ml-2", isInputBroken && "line-through", colorClass)}
- id={description_id}
+ id={getFieldDomId(description_id, registry.formContext)}
>
({displayType})
</Text>
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/buttons/AddButton.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/buttons/AddButton.tsx
index 38078b9922..a25b622f71 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/buttons/AddButton.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/buttons/AddButton.tsx
@@ -1,3 +1,4 @@
+import { getFieldDomId } from "../../../field-accessibility";
import { IconButtonProps, TranslatableString } from "@rjsf/utils";
import { cn } from "@/lib/utils";
import { Button } from "@/components/atoms/Button/Button";
@@ -7,6 +8,7 @@ import { Icon } from "@/components/atoms/Icon/Icon";
export default function AddButton({
registry,
className,
+ id,
uiSchema: _uiSchema,
...props
}: IconButtonProps) {
@@ -15,6 +17,7 @@ export default function AddButton({
<div className="m-0 w-full p-0">
<Button
{...props}
+ id={id ? getFieldDomId(id, registry.formContext) : undefined}
size="small"
className={cn("w-full gap-4", className)}
variant="secondary"
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/buttons/IconButton.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/buttons/IconButton.tsx
index 4f05e8e8bf..1f1b333d28 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/buttons/IconButton.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/buttons/IconButton.tsx
@@ -1,3 +1,4 @@
+import { getFieldDomId } from "../../../field-accessibility";
import {
FormContextType,
IconButtonProps,
@@ -26,7 +27,9 @@ export default function IconButton(props: AutogptIconButtonProps) {
icon,
className,
uiSchema: _uiSchema,
- registry: _registry,
+ registry,
+ id,
+ title,
iconType: _iconType,
...otherProps
} = props;
@@ -37,12 +40,14 @@ export default function IconButton(props: AutogptIconButtonProps) {
variant="secondary"
className={cn(className, "w-fit border border-zinc-200 p-1.5 px-4")}
{...otherProps}
+ id={id ? getFieldDomId(id, registry.formContext) : undefined}
+ title={title}
+ aria-label={title}
type="button"
>
{icon}
<Text variant="body" className="ml-2">
- {" "}
- Remove Item{" "}
+ {title}
</Text>
</Button>
);
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/CheckboxInput/CheckBoxWidget.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/CheckboxInput/CheckBoxWidget.tsx
index ff93528492..9e861c7b51 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/CheckboxInput/CheckBoxWidget.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/CheckboxInput/CheckBoxWidget.tsx
@@ -1,12 +1,29 @@
+import { useFieldAccessibility } from "../../../../field-accessibility";
import { WidgetProps } from "@rjsf/utils";
import { Switch } from "@/components/atoms/Switch/Switch";
export function CheckboxWidget(props: WidgetProps) {
- const { value = false, onChange, disabled, readonly, autofocus, id } = props;
+ const {
+ value = false,
+ onChange,
+ disabled,
+ readonly,
+ autofocus,
+ id,
+ schema,
+ label,
+ } = props;
+ const accessibleLabel = schema.title || label;
+ const accessibility = useFieldAccessibility(
+ id,
+ accessibleLabel,
+ props.formContext ?? props.registry?.formContext,
+ props["aria-describedby"],
+ );
return (
<Switch
- id={id}
+ {...accessibility}
checked={Boolean(value)}
onCheckedChange={(checked) => onChange(checked)}
disabled={disabled || readonly}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/DateInput/DateWidget.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/DateInput/DateWidget.tsx
index 1a861821e5..1db79b88f4 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/DateInput/DateWidget.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/DateInput/DateWidget.tsx
@@ -1,3 +1,4 @@
+import { useFieldAccessibility } from "../../../../field-accessibility";
import { WidgetProps } from "@rjsf/utils";
import { DateInput } from "@/components/atoms/DateInput/DateInput";
@@ -11,8 +12,16 @@ export const DateWidget = (props: WidgetProps) => {
autofocus,
id,
formContext,
+ schema,
+ label,
} = props;
const { size = "small" } = formContext || {};
+ const accessibility = useFieldAccessibility(
+ id,
+ schema.title || label,
+ formContext ?? props.registry?.formContext,
+ props["aria-describedby"],
+ );
// Determine input size based on context
const inputSize = size === "large" ? "default" : "small";
@@ -20,9 +29,9 @@ export const DateWidget = (props: WidgetProps) => {
return (
<DateInput
size={inputSize as any}
- id={id}
+ {...accessibility}
hideLabel={true}
- label={""}
+ label={schema.title || label || ""}
value={value}
onChange={onChange}
placeholder={placeholder}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/DateTimeInput/DateTimeWidget.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/DateTimeInput/DateTimeWidget.tsx
index 50f6e378fb..43f00ee545 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/DateTimeInput/DateTimeWidget.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/DateTimeInput/DateTimeWidget.tsx
@@ -1,3 +1,4 @@
+import { useFieldAccessibility } from "../../../../field-accessibility";
import { WidgetProps } from "@rjsf/utils";
import { DateTimeInput } from "@/components/atoms/DateTimeInput/DateTimeInput";
@@ -11,8 +12,16 @@ export const DateTimeWidget = (props: WidgetProps) => {
autofocus,
id,
formContext,
+ schema,
+ label,
} = props;
const { size = "small" } = formContext || {};
+ const accessibility = useFieldAccessibility(
+ id,
+ schema.title || label,
+ formContext ?? props.registry?.formContext,
+ props["aria-describedby"],
+ );
// Determine input size based on context
const inputSize = size === "large" ? "medium" : "small";
@@ -20,9 +29,9 @@ export const DateTimeWidget = (props: WidgetProps) => {
return (
<DateTimeInput
size={inputSize as any}
- id={id}
+ {...accessibility}
hideLabel={true}
- label={""}
+ label={schema.title || label || ""}
value={value}
onChange={onChange}
placeholder={placeholder}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/SelectInput/SelectWidget.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/SelectInput/SelectWidget.tsx
index 3b7bd403fd..dc26ae8239 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/SelectInput/SelectWidget.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/SelectInput/SelectWidget.tsx
@@ -1,3 +1,4 @@
+import { useFieldAccessibility } from "../../../../field-accessibility";
import {
enumOptionsIndexForValue,
enumOptionsValueForIndex,
@@ -62,6 +63,12 @@ export function SelectWidget(props: WidgetProps) {
: typeof fieldSchema.title === "string"
? fieldSchema.title
: label;
+ const accessibility = useFieldAccessibility(
+ id,
+ resolvedLabel,
+ formContext ?? props.registry?.formContext,
+ props["aria-describedby"],
+ );
const schemaPlaceholder =
typeof fieldSchema.placeholder === "string"
? fieldSchema.placeholder
@@ -116,6 +123,7 @@ export function SelectWidget(props: WidgetProps) {
return (
<MultiSelector
+ label={resolvedLabel}
values={selectedValues}
onValuesChange={(newValues) => {
const selectedOptionIndexes: string[] = [];
@@ -132,7 +140,10 @@ export function SelectWidget(props: WidgetProps) {
className="w-full"
>
<MultiSelectorTrigger>
- <MultiSelectorInput placeholder="Select options..." />
+ <MultiSelectorInput
+ aria-describedby={accessibility["aria-describedby"]}
+ placeholder="Select options..."
+ />
</MultiSelectorTrigger>
<MultiSelectorContent>
<MultiSelectorList>
@@ -156,7 +167,7 @@ export function SelectWidget(props: WidgetProps) {
<Select
label={resolvedLabel}
placeholder={placeholder || schemaPlaceholder || "Select an option"}
- id={id}
+ {...accessibility}
hideLabel={true}
disabled={disabled || readonly}
size={selectSize}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TextInput/TextInputExpanderModal.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TextInput/TextInputExpanderModal.tsx
index ab4f224194..7f7aeab074 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TextInput/TextInputExpanderModal.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TextInput/TextInputExpanderModal.tsx
@@ -1,6 +1,6 @@
"use client";
-import React, { FC, useEffect, useState } from "react";
+import React, { FC, useEffect, useId, useState } from "react";
import { Button } from "@/components/atoms/Button/Button";
import { Text } from "@/components/atoms/Text/Text";
import { useToast } from "@/components/molecules/Toast/use-toast";
@@ -31,6 +31,7 @@ export const InputExpanderModal: FC<InputExpanderModalProps> = ({
placeholder,
inputType = "text",
}) => {
+ const inputId = useId();
const [tempValue, setTempValue] = useState(defaultValue);
const [isCopied, setIsCopied] = useState(false);
const { toast } = useToast();
@@ -75,9 +76,9 @@ export const InputExpanderModal: FC<InputExpanderModalProps> = ({
<Text variant="body">{description}</Text>
<Input
type="textarea"
- label=""
+ label={title || "Edit value"}
hideLabel
- id="input-expander-modal"
+ id={inputId}
value={tempValue}
className={cn(
"!min-h-[300px] rounded-2xlarge",
@@ -93,6 +94,9 @@ export const InputExpanderModal: FC<InputExpanderModalProps> = ({
variant="secondary"
size="small"
onClick={copyValue}
+ aria-label={
+ isCopied ? "Copied to clipboard" : "Copy to clipboard"
+ }
className={cn(
"h-fit min-w-0 gap-1.5 border border-zinc-200 p-2 text-black hover:text-slate-900",
isCopied &&
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TextInput/TextWidget.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TextInput/TextWidget.tsx
index 80df5f6ad5..c4bb4c974d 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TextInput/TextWidget.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TextInput/TextWidget.tsx
@@ -1,5 +1,7 @@
"use client";
+import { useFieldAccessibility } from "../../../../field-accessibility";
+
import { useState } from "react";
import { WidgetProps } from "@rjsf/utils";
import {
@@ -21,6 +23,12 @@ import { Icon } from "@/components/atoms/Icon/Icon";
export default function TextWidget(props: WidgetProps) {
const { schema, placeholder, registry } = props;
const { size, uiType } = registry.formContext;
+ const accessibility = useFieldAccessibility(
+ props.id,
+ schema.title || props.label,
+ registry.formContext,
+ props["aria-describedby"],
+ );
const [isModalOpen, setIsModalOpen] = useState(false);
@@ -105,10 +113,10 @@ export default function TextWidget(props: WidgetProps) {
if (uiType === BlockUIType.NOTE) {
return (
<Input
- id={props.id}
+ {...accessibility}
hideLabel={true}
type={"textarea"}
- label={""}
+ label={schema.title || props.label || "Note"}
size="small"
wrapperClassName="mb-0"
value={displayValue}
@@ -125,10 +133,10 @@ export default function TextWidget(props: WidgetProps) {
<>
<div className="nodrag relative flex items-center gap-2">
<Input
- id={props.id}
+ {...accessibility}
hideLabel={true}
type={config.htmlType as any}
- label={""}
+ label={schema.title || props.label || ""}
size={inputSize as any}
wrapperClassName="mb-0 flex-1"
value={displayValue}
@@ -147,6 +155,7 @@ export default function TextWidget(props: WidgetProps) {
onClick={handleModalOpen}
type="button"
className="p-1"
+ aria-label="Expand input"
>
<Icon icon={ArrowExpandIcon} className="size-4" />
</Button>
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TimeInput/TimeWidget.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TimeInput/TimeWidget.tsx
index 152aae7298..936f022d1d 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TimeInput/TimeWidget.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/base/standard/widgets/TimeInput/TimeWidget.tsx
@@ -1,10 +1,26 @@
+import { useFieldAccessibility } from "../../../../field-accessibility";
import { WidgetProps } from "@rjsf/utils";
import { TimeInput } from "@/components/atoms/TimeInput/TimeInput";
export const TimeWidget = (props: WidgetProps) => {
- const { value, onChange, disabled, readonly, placeholder, id, formContext } =
- props;
+ const {
+ value,
+ onChange,
+ disabled,
+ readonly,
+ placeholder,
+ id,
+ formContext,
+ schema,
+ label,
+ } = props;
const { size = "small" } = formContext || {};
+ const accessibility = useFieldAccessibility(
+ id,
+ schema.title || label,
+ formContext ?? props.registry?.formContext,
+ props["aria-describedby"],
+ );
// Determine input size based on context
const inputSize = size === "large" ? "medium" : "small";
@@ -14,8 +30,8 @@ export const TimeWidget = (props: WidgetProps) => {
value={value}
onChange={onChange}
className="w-full"
- label={""}
- id={id}
+ label={schema.title || label || ""}
+ {...accessibility}
hideLabel={true}
size={inputSize as any}
wrapperClassName="!mb-0 "
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/CredentialField/CredentialField.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/CredentialField/CredentialField.tsx
index 91f743c1f4..2628efe71e 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/CredentialField/CredentialField.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/CredentialField/CredentialField.tsx
@@ -1,3 +1,4 @@
+import { getFieldDomId } from "../../field-accessibility";
import { useNodeStore } from "@/app/(platform)/build/stores/nodeStore";
import { Switch } from "@/components/atoms/Switch/Switch";
import { CredentialsInput } from "@/components/contextual/CredentialsInput/CredentialsInput";
@@ -130,7 +131,14 @@ export const CredentialsField = (props: FieldProps) => {
// Ties the explanation to the control for assistive tech: dropping the
// required marker also removes the only programmatic cue that a visible
// field cannot be filled.
- const unavailableNoteId = `${fieldPathId?.$id ?? "credentials"}-unavailable`;
+ const unavailableNoteId = getFieldDomId(
+ `${fieldPathId?.$id ?? "credentials"}-unavailable`,
+ formContext,
+ );
+ const optionalToggleId = getFieldDomId(
+ `credentials-optional-${nodeId}`,
+ formContext,
+ );
return (
<div
@@ -179,14 +187,14 @@ export const CredentialsField = (props: FieldProps) => {
formContext?.showOptionalToggle !== false && (
<div className="mt-1 flex items-center gap-2">
<Switch
- id={`credentials-optional-${nodeId}`}
+ id={optionalToggleId}
checked={credentialsOptional}
onCheckedChange={(checked) =>
setCredentialsOptional(nodeId, checked)
}
/>
<label
- htmlFor={`credentials-optional-${nodeId}`}
+ htmlFor={optionalToggleId}
className="cursor-pointer text-xs text-gray-500"
>
Optional - skip block if not configured
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/JsonTextField/JsonTextField.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/JsonTextField/JsonTextField.tsx
index 5dca779156..6584038778 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/JsonTextField/JsonTextField.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/custom/JsonTextField/JsonTextField.tsx
@@ -1,6 +1,12 @@
"use client";
-import { FieldProps, getTemplate, getUiOptions } from "@rjsf/utils";
+import {
+ getFieldDomId,
+ useFieldAccessibilityContext,
+} from "../../field-accessibility";
+import { FieldError } from "../../base/standard/FieldError";
+
+import { FieldProps, getTemplate, getUiOptions, titleId } from "@rjsf/utils";
import { Input } from "@/components/atoms/Input/Input";
import { Button } from "@/components/atoms/Button/Button";
import {
@@ -9,7 +15,7 @@ import {
TooltipTrigger,
} from "@/components/atoms/Tooltip/BaseTooltip";
import { InputExpanderModal } from "../../base/standard/widgets/TextInput/TextInputExpanderModal";
-import { getHandleId, updateUiOption } from "../../helpers";
+import { getHandleId, updateUiOption, cleanUpHandleId } from "../../helpers";
import { useJsonTextField } from "./useJsonTextField";
import { getPlaceholder } from "./helpers";
import { ArrowExpandIcon } from "@hugeicons/core-free-icons";
@@ -62,11 +68,18 @@ export const JsonTextField = (props: FieldProps) => {
const placeholder = getPlaceholder(schema);
const title = schema.title || name || "JSON Value";
+ const domId = getFieldDomId(fieldId, registry.formContext);
+ const fieldAccessibility = useFieldAccessibilityContext(fieldId);
+ const labelId = getFieldDomId(titleId(fieldId), registry.formContext);
+ const errorId = fieldAccessibility?.errorId ?? `${domId}-error`;
+ const descriptionId = schema.description
+ ? `${domId}-json-description`
+ : undefined;
return (
<div className="flex flex-col gap-2">
<TitleFieldTemplate
- id={fieldId}
+ id={titleId(fieldId)}
title={title}
required={required}
schema={schema}
@@ -75,10 +88,17 @@ export const JsonTextField = (props: FieldProps) => {
/>
<div className="nodrag relative flex items-center gap-2">
<Input
- id={fieldId}
+ id={domId}
+ aria-labelledby={labelId}
+ aria-describedby={[
+ descriptionId ?? fieldAccessibility?.descriptionId,
+ errorId,
+ ]
+ .filter(Boolean)
+ .join(" ")}
hideLabel={true}
type="textarea"
- label=""
+ label={title}
size="small"
wrapperClassName="mb-0 flex-1 "
value={textValue}
@@ -97,6 +117,7 @@ export const JsonTextField = (props: FieldProps) => {
onClick={handleModalOpen}
type="button"
className="p-1"
+ aria-label="Expand JSON input"
>
<Icon icon={ArrowExpandIcon} className="size-4" />
</Button>
@@ -105,9 +126,18 @@ export const JsonTextField = (props: FieldProps) => {
</Tooltip>
</div>
{schema.description && (
- <span className="text-xs text-gray-500">{schema.description}</span>
+ <span id={descriptionId} className="text-xs text-gray-500">
+ {schema.description}
+ </span>
)}
+ {!fieldAccessibility && (
+ <FieldError
+ nodeId={registry.formContext.nodeId}
+ fieldId={cleanUpHandleId(fieldId)}
+ id={errorId}
+ />
+ )}
<InputExpanderModal
isOpen={isModalOpen}
onClose={handleModalClose}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/field-accessibility.tsx b/autogpt_platform/frontend/src/components/renderers/InputRenderer/field-accessibility.tsx
new file mode 100644
index 0000000000..f444146f9b
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/field-accessibility.tsx
@@ -0,0 +1,59 @@
+import { createContext, ReactNode, useContext } from "react";
+import { ExtendedFormContextType } from "./types";
+
+interface FieldAccessibility {
+ fieldId: string;
+ labelId?: string;
+ descriptionId?: string;
+ errorId: string;
+}
+
+const FieldAccessibilityContext = createContext<FieldAccessibility | null>(
+ null,
+);
+
+interface Props {
+ value: FieldAccessibility;
+ children: ReactNode;
+}
+
+export function FieldAccessibilityProvider({ value, children }: Props) {
+ return (
+ <FieldAccessibilityContext.Provider value={value}>
+ {children}
+ </FieldAccessibilityContext.Provider>
+ );
+}
+
+export function getFieldDomId(
+ id: string,
+ formContext?: ExtendedFormContextType,
+) {
+ return `${formContext?.domIdPrefix ?? ""}${id}`;
+}
+
+export function useFieldAccessibility(
+ id: string,
+ label: string | undefined,
+ formContext?: ExtendedFormContextType,
+ describedBy?: string,
+) {
+ const field = useFieldAccessibilityContext(id);
+ const descriptions = [describedBy, field?.descriptionId, field?.errorId]
+ .filter(Boolean)
+ .join(" ")
+ .split(/\s+/)
+ .filter(Boolean);
+
+ return {
+ id: getFieldDomId(id, formContext),
+ "aria-labelledby": field?.labelId,
+ "aria-label": field?.labelId ? undefined : label || undefined,
+ "aria-describedby": [...new Set(descriptions)].join(" ") || undefined,
+ };
+}
+
+export function useFieldAccessibilityContext(id: string) {
+ const context = useContext(FieldAccessibilityContext);
+ return context?.fieldId === id ? context : null;
+}
diff --git a/autogpt_platform/frontend/src/components/renderers/InputRenderer/types.ts b/autogpt_platform/frontend/src/components/renderers/InputRenderer/types.ts
index e667e27e2d..aab3b9d807 100644
--- a/autogpt_platform/frontend/src/components/renderers/InputRenderer/types.ts
+++ b/autogpt_platform/frontend/src/components/renderers/InputRenderer/types.ts
@@ -7,6 +7,7 @@ export interface ExtendedFormContextType extends FormContextType {
showHandles?: boolean;
size?: "small" | "medium" | "large";
showOptionalToggle?: boolean;
+ domIdPrefix?: string;
}
export type PathSegment = {