Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: expose readable labels for date widgets (#11067)

Shahmir Varqha6ce24953b051
diff --git a/frontend/src/plugins/impl/CheckboxPlugin.tsx b/frontend/src/plugins/impl/CheckboxPlugin.tsx
index b491c1b566..70a3009000 100644
--- a/frontend/src/plugins/impl/CheckboxPlugin.tsx
+++ b/frontend/src/plugins/impl/CheckboxPlugin.tsx
@@ -46,7 +46,7 @@ const CheckboxComponent = ({
const id = useId();
return (
- <Labeled label={data.label} align="right" id={id}>
+ <Labeled label={data.label} align="right" controlId={id}>
<Checkbox
data-testid="marimo-plugin-checkbox"
checked={value}
diff --git a/frontend/src/plugins/impl/DatePickerPlugin.tsx b/frontend/src/plugins/impl/DatePickerPlugin.tsx
index 5ddb6bde61..9b003754b7 100644
--- a/frontend/src/plugins/impl/DatePickerPlugin.tsx
+++ b/frontend/src/plugins/impl/DatePickerPlugin.tsx
@@ -1,7 +1,7 @@
/* Copyright 2026 Marimo. All rights reserved. */
import { type CalendarDate, parseDate } from "@internationalized/date";
-import type { JSX } from "react";
+import { type JSX, useId } from "react";
import { z } from "zod";
import { DatePicker } from "@/components/ui/date-picker";
import type { IPlugin, IPluginProps, Setter } from "../types";
@@ -49,6 +49,7 @@ interface DatePickerProps extends Data {
}
const DatePickerComponent = (props: DatePickerProps): JSX.Element => {
+ const labelId = useId();
const handleInput = (valueAsDate: CalendarDate | null) => {
if (!valueAsDate) {
return;
@@ -59,12 +60,13 @@ const DatePickerComponent = (props: DatePickerProps): JSX.Element => {
};
return (
- <Labeled label={props.label} fullWidth={props.fullWidth}>
+ <Labeled labelId={labelId} label={props.label} fullWidth={props.fullWidth}>
<DatePicker
granularity="day"
value={parseDate(props.value)}
onChange={handleInput}
- aria-label={props.label ?? "date picker"}
+ aria-labelledby={props.label ? labelId : undefined}
+ aria-label={props.label ? undefined : "date picker"}
minValue={parseDate(props.start)}
maxValue={parseDate(props.stop)}
isDisabled={props.disabled}
diff --git a/frontend/src/plugins/impl/DateRangePlugin.tsx b/frontend/src/plugins/impl/DateRangePlugin.tsx
index 66101387b3..1c989f012c 100644
--- a/frontend/src/plugins/impl/DateRangePlugin.tsx
+++ b/frontend/src/plugins/impl/DateRangePlugin.tsx
@@ -1,7 +1,7 @@
/* Copyright 2026 Marimo. All rights reserved. */
import { type CalendarDate, parseDate } from "@internationalized/date";
-import type { JSX } from "react";
+import { type JSX, useId } from "react";
import { z } from "zod";
import { DateRangePicker } from "@/components/ui/date-picker";
import type { IPlugin, IPluginProps, Setter } from "../types";
@@ -48,6 +48,7 @@ interface DateRangePickerProps extends Data {
}
const DateRangePickerComponent = (props: DateRangePickerProps): JSX.Element => {
+ const labelId = useId();
const handleInput = (
valueAsDateRange: {
start: CalendarDate;
@@ -64,7 +65,7 @@ const DateRangePickerComponent = (props: DateRangePickerProps): JSX.Element => {
};
return (
- <Labeled label={props.label} fullWidth={props.fullWidth}>
+ <Labeled labelId={labelId} label={props.label} fullWidth={props.fullWidth}>
<DateRangePicker
granularity="day"
value={{
@@ -72,7 +73,8 @@ const DateRangePickerComponent = (props: DateRangePickerProps): JSX.Element => {
end: parseDate(props.value[1]),
}}
onChange={handleInput}
- aria-label={props.label ?? "date range picker"}
+ aria-labelledby={props.label ? labelId : undefined}
+ aria-label={props.label ? undefined : "date range picker"}
minValue={parseDate(props.start)}
maxValue={parseDate(props.stop)}
isDisabled={props.disabled}
diff --git a/frontend/src/plugins/impl/DateTimePickerPlugin.tsx b/frontend/src/plugins/impl/DateTimePickerPlugin.tsx
index 076ed9501e..04af550214 100644
--- a/frontend/src/plugins/impl/DateTimePickerPlugin.tsx
+++ b/frontend/src/plugins/impl/DateTimePickerPlugin.tsx
@@ -1,7 +1,7 @@
/* Copyright 2026 Marimo. All rights reserved. */
import { type CalendarDateTime, parseDateTime } from "@internationalized/date";
-import type { JSX } from "react";
+import { type JSX, useId } from "react";
import { z } from "zod";
import { DatePicker } from "@/components/ui/date-picker";
import type { IPlugin, IPluginProps, Setter } from "../types";
@@ -50,6 +50,7 @@ interface DateTimePickerProps extends Data {
}
const DateTimePickerComponent = (props: DateTimePickerProps): JSX.Element => {
+ const labelId = useId();
const handleInput = (valueAsDateTime: CalendarDateTime | null) => {
if (!valueAsDateTime) {
return;
@@ -63,12 +64,13 @@ const DateTimePickerComponent = (props: DateTimePickerProps): JSX.Element => {
const parsedValue = props.value ? parseDateTime(props.value) : undefined;
return (
- <Labeled label={props.label} fullWidth={props.fullWidth}>
+ <Labeled labelId={labelId} label={props.label} fullWidth={props.fullWidth}>
<DatePicker
granularity={props.precision}
value={parsedValue}
onChange={handleInput}
- aria-label={props.label ?? "date time picker"}
+ aria-labelledby={props.label ? labelId : undefined}
+ aria-label={props.label ? undefined : "date time picker"}
minValue={parseDateTime(props.start)}
maxValue={parseDateTime(props.stop)}
isDisabled={props.disabled}
diff --git a/frontend/src/plugins/impl/DropdownPlugin.tsx b/frontend/src/plugins/impl/DropdownPlugin.tsx
index a5d5cba0b8..7b61037f20 100644
--- a/frontend/src/plugins/impl/DropdownPlugin.tsx
+++ b/frontend/src/plugins/impl/DropdownPlugin.tsx
@@ -79,7 +79,7 @@ const Dropdown = (props: DropdownProps): JSX.Element => {
const singleValue = value.length === 0 ? defaultValue : value[0];
return (
- <Labeled label={label} id={id} fullWidth={fullWidth}>
+ <Labeled label={label} controlId={id} fullWidth={fullWidth}>
<NativeSelect
data-testid="marimo-plugin-dropdown"
onChange={(e) => {
diff --git a/frontend/src/plugins/impl/MultiselectPlugin.tsx b/frontend/src/plugins/impl/MultiselectPlugin.tsx
index 760aa7dab1..cb5e09617c 100644
--- a/frontend/src/plugins/impl/MultiselectPlugin.tsx
+++ b/frontend/src/plugins/impl/MultiselectPlugin.tsx
@@ -68,7 +68,7 @@ export const Multiselect = ({
);
return (
- <Labeled label={label} id={id} fullWidth={fullWidth}>
+ <Labeled label={label} controlId={id} fullWidth={fullWidth}>
<SelectList<string>
id={id}
options={items}
diff --git a/frontend/src/plugins/impl/NumberPlugin.tsx b/frontend/src/plugins/impl/NumberPlugin.tsx
index be97750cca..3f8006f53c 100644
--- a/frontend/src/plugins/impl/NumberPlugin.tsx
+++ b/frontend/src/plugins/impl/NumberPlugin.tsx
@@ -70,7 +70,7 @@ const NumberComponent = (props: NumberComponentProps): JSX.Element => {
};
return (
- <Labeled label={props.label} id={id} fullWidth={props.fullWidth}>
+ <Labeled label={props.label} controlId={id} fullWidth={props.fullWidth}>
<NumberField
data-testid="marimo-plugin-number-input"
className={cn("min-w-[3em]", props.fullWidth && "w-full")}
diff --git a/frontend/src/plugins/impl/RadioPlugin.tsx b/frontend/src/plugins/impl/RadioPlugin.tsx
index 51fd5c8b82..7bc3a79307 100644
--- a/frontend/src/plugins/impl/RadioPlugin.tsx
+++ b/frontend/src/plugins/impl/RadioPlugin.tsx
@@ -51,7 +51,11 @@ export const Radio = (props: RadioProps): JSX.Element => {
const id = useId();
return (
- <Labeled label={props.label} id={id} align={props.inline ? "left" : "top"}>
+ <Labeled
+ label={props.label}
+ controlId={id}
+ align={props.inline ? "left" : "top"}
+ >
<RadioGroup
data-testid="marimo-plugin-radio"
value={props.value ?? ""}
diff --git a/frontend/src/plugins/impl/RangeSliderPlugin.tsx b/frontend/src/plugins/impl/RangeSliderPlugin.tsx
index 4d987daa89..538169d45f 100644
--- a/frontend/src/plugins/impl/RangeSliderPlugin.tsx
+++ b/frontend/src/plugins/impl/RangeSliderPlugin.tsx
@@ -98,7 +98,7 @@ const RangeSliderComponent = ({
const sliderElement = (
<Labeled
label={label}
- id={id}
+ controlId={id}
align={orientation === "horizontal" ? "left" : "top"}
className={cn(fullWidth && "my-1 w-full")}
fullWidth={fullWidth}
diff --git a/frontend/src/plugins/impl/SearchableSelect.tsx b/frontend/src/plugins/impl/SearchableSelect.tsx
index 471103e6e2..df01162408 100644
--- a/frontend/src/plugins/impl/SearchableSelect.tsx
+++ b/frontend/src/plugins/impl/SearchableSelect.tsx
@@ -33,7 +33,7 @@ export const SearchableSelect = (props: SearchableSelectProps): JSX.Element => {
);
return (
- <Labeled label={label} id={id} fullWidth={fullWidth}>
+ <Labeled label={label} controlId={id} fullWidth={fullWidth}>
<SelectList<string>
id={id}
options={items}
diff --git a/frontend/src/plugins/impl/SliderPlugin.tsx b/frontend/src/plugins/impl/SliderPlugin.tsx
index b2c834d8ca..83f5fb5a29 100644
--- a/frontend/src/plugins/impl/SliderPlugin.tsx
+++ b/frontend/src/plugins/impl/SliderPlugin.tsx
@@ -224,7 +224,7 @@ const SliderComponent = ({
const sliderElement = (
<Labeled
label={label}
- id={id}
+ controlId={id}
align={orientation === "horizontal" ? "left" : "top"}
fullWidth={fullWidth}
className={cn(fullWidth && "my-1 w-full")}
diff --git a/frontend/src/plugins/impl/SwitchPlugin.tsx b/frontend/src/plugins/impl/SwitchPlugin.tsx
index 0cf31e8073..a94f588db3 100644
--- a/frontend/src/plugins/impl/SwitchPlugin.tsx
+++ b/frontend/src/plugins/impl/SwitchPlugin.tsx
@@ -34,7 +34,12 @@ const SwitchComponent = ({
const id = useId();
return (
- <Labeled label={data.label} align="right" id={id} labelClassName="ml-1">
+ <Labeled
+ label={data.label}
+ align="right"
+ controlId={id}
+ labelClassName="ml-1"
+ >
<Switch
data-testid="marimo-plugin-switch"
checked={value}
diff --git a/frontend/src/plugins/impl/__tests__/widget-labels.test.tsx b/frontend/src/plugins/impl/__tests__/widget-labels.test.tsx
new file mode 100644
index 0000000000..2404fecd3f
--- /dev/null
+++ b/frontend/src/plugins/impl/__tests__/widget-labels.test.tsx
@@ -0,0 +1,122 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { render } from "@testing-library/react";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { initialModeAtom } from "@/core/mode";
+import { store } from "@/core/state/jotai";
+import { DatePickerPlugin } from "../DatePickerPlugin";
+import { DateRangePickerPlugin } from "../DateRangePlugin";
+import { DateTimePickerPlugin } from "../DateTimePickerPlugin";
+
+const sharedProps = () => ({
+ host: document.createElement("div"),
+ setValue: vi.fn(),
+ functions: {},
+});
+
+const widgets = [
+ {
+ name: "date",
+ role: "group",
+ fallback: "date picker",
+ render: (label: string | null, disabled = false) =>
+ new DatePickerPlugin().render({
+ ...sharedProps(),
+ value: "2026-10-02",
+ data: {
+ label,
+ disabled,
+ start: "2026-01-01",
+ stop: "2026-12-31",
+ fullWidth: false,
+ },
+ }),
+ },
+ {
+ name: "datetime",
+ role: "group",
+ fallback: "date time picker",
+ render: (label: string | null, disabled = false) =>
+ new DateTimePickerPlugin().render({
+ ...sharedProps(),
+ value: "2026-10-02T12:00:00",
+ data: {
+ label,
+ disabled,
+ start: "2026-01-01T00:00:00",
+ stop: "2026-12-31T23:59:59",
+ precision: "minute",
+ fullWidth: false,
+ },
+ }),
+ },
+ {
+ name: "date range",
+ role: "group",
+ fallback: "date range picker",
+ render: (label: string | null, disabled = false) =>
+ new DateRangePickerPlugin().render({
+ ...sharedProps(),
+ value: ["2026-10-02", "2026-10-03"],
+ data: {
+ label,
+ disabled,
+ start: "2026-01-01",
+ stop: "2026-12-31",
+ fullWidth: false,
+ },
+ }),
+ },
+];
+
+beforeEach(() => store.set(initialModeAtom, "edit"));
+
+describe.each(widgets)("$name accessible labels", (widget) => {
+ it("uses rendered formatting and decoded entities, and follows label updates", () => {
+ const { getByRole, rerender } = render(
+ widget.render("<span>Visit <strong>date</strong> &amp; time</span>"),
+ );
+ expect(getByRole(widget.role, { name: "Visit date & time" })).toBeTruthy();
+ rerender(widget.render("<span>Updated <em>label</em></span>"));
+ expect(getByRole(widget.role, { name: "Updated label" })).toBeTruthy();
+ rerender(widget.render(null));
+ expect(getByRole(widget.role, { name: widget.fallback })).toBeTruthy();
+ });
+
+ it.each([null, ""])("uses the fallback when label is %s", (label) => {
+ const { getByRole } = render(widget.render(label));
+ expect(getByRole(widget.role, { name: widget.fallback })).toBeTruthy();
+ });
+
+ it("names the calendar button and every editable segment", () => {
+ const { getByRole, getAllByRole } = render(
+ widget.render("<strong>Visit</strong> &amp; time"),
+ );
+ expect(getByRole("button", { name: "Calendar Visit & time" })).toBeTruthy();
+ for (const segment of getAllByRole("spinbutton")) {
+ expect(segment).toHaveAccessibleName(/Visit & time/);
+ }
+ });
+
+ it("preserves disabled controls with a formatted label", () => {
+ const { getByRole, getAllByRole } = render(
+ widget.render("<strong>Visit</strong>", true),
+ );
+ expect(getByRole("button", { name: "Calendar Visit" })).toBeDisabled();
+ for (const segment of getAllByRole("spinbutton")) {
+ expect(segment).toHaveAttribute("aria-disabled", "true");
+ }
+ });
+
+ it("keeps labels distinct for multiple widgets", () => {
+ const { getByRole } = render(
+ <>
+ {widget.render("First")}
+ {widget.render("Second")}
+ </>,
+ );
+ expect(getByRole(widget.role, { name: "First" })).not.toBe(
+ getByRole(widget.role, { name: "Second" }),
+ );
+ });
+});
diff --git a/frontend/src/plugins/impl/common/labeled.tsx b/frontend/src/plugins/impl/common/labeled.tsx
index a469a80f50..319a185cbf 100644
--- a/frontend/src/plugins/impl/common/labeled.tsx
+++ b/frontend/src/plugins/impl/common/labeled.tsx
@@ -9,7 +9,8 @@ interface Props {
label: string | null | undefined;
className?: string;
labelClassName?: string;
- id?: string;
+ labelId?: string;
+ controlId?: string;
fullWidth?: boolean;
/**
* Align the label to the top, left, or right of the component.
@@ -27,8 +28,9 @@ export const Labeled: React.FC<PropsWithChildren<Props>> = ({
align = "left",
className,
labelClassName,
+ labelId,
fullWidth,
- id,
+ controlId,
}) => {
// If fullWidth is true, force align to be "top"
if (fullWidth) {
@@ -45,7 +47,11 @@ export const Labeled: React.FC<PropsWithChildren<Props>> = ({
const labelElement = (
<div part="label" className="inline-flex items-center m-0 p-0">
- <Label htmlFor={id} className={cn("font-prose", labelClassName)}>
+ <Label
+ id={labelId}
+ htmlFor={controlId}
+ className={cn("font-prose", labelClassName)}
+ >
{renderHTML({ html: label })}
</Label>
</div>