A `oneOf`/`anyOf` option selector has no accessible name: nothing renders a label for the id `MultiSchemaField` gives it
Prerequisites
- I have searched the existing issues
- I understand that providing a SSCCE example is tremendously useful to the maintainers.
- I have read the documentation
What theme are you using?
core, and every theme — the option selector is rendered by MultiSchemaField
Version
7.x (v7 branch)
Current Behavior
MultiSchemaField renders its option selector under an id of its own:
// packages/core/src/components/fields/MultiSchemaField.tsx:123-124
const selectSuffix = xxxOfKey === ANY_OF_KEY ? '__anyof_select' : '__oneof_select';
const fieldId = `${id}${selectSuffix}`;and hands the widget that id along with label={title ?? name} and hideLabel={!displayLabel}. Nothing renders a label for it. FieldTemplate's label targets the field's own id, and no theme's MultiSchemaFieldTemplate renders a <label> at all — I checked all eight (core, antd, chakra-ui, daisyui, fluentui-rc, mui, react-bootstrap, shadcn): zero <label> elements between them. MultiSchemaFieldTemplateProps.id (added in #5332) is the field's id, not the selector's, and the props carry no label text either, so a theme has nothing to render one from.
Measured in @rjsf/core for { pick: { title: 'Pick', anyOf: [{type:'string',enum:['a','b']}, {type:'number'}] } }:
selector=SELECT label[for=root_pick__anyof_select]=NONE aria-label=none aria-labelledby=noneSo the control that chooses which shape the field takes is announced as an unnamed combobox, and "Pick" is never read with it.
There is a second consequence for any theme that names a widget by reference, which a group of controls must be, since <label for> reaches a single control rather than a wrapper. The widget is handed a non-empty label, so it believes a label exists and points at the id one would have. With ui:widget: 'radio' on the schema above, @rjsf/daisyui renders:
<div id="root_pick__anyof_select" role="radiogroup" aria-labelledby="root_pick__anyof_select__label">with no such element in the document. A reference to a missing id contributes nothing, so the group is left unnamed rather than misnamed — no worse than before, but a role with no accessible name, and the theme cannot avoid it without rebuilding __anyof_select itself, which is a theme guessing at an id @rjsf/core owns.
Expected Behavior
A theme can name the selector. Either:
MultiSchemaFieldtells its template about the selector — pass the selector's id, and the label text it already computed, throughMultiSchemaFieldTemplateProps, so a theme renders<label htmlFor={selectorId}>beside it (visually hidden wherehideLabel); or@rjsf/utilsexports the id builder thatMultiSchemaField.tsx:123-124inlines, so a theme can derive the same id from the field's and render the label itself. The template already receivesschemaanduiSchema, so it can compute the title.
(1) is the smaller ask of themes; (2) is the smaller ask of core, and would also let a theme's own group widget point at a label it rendered.
Whichever way, the selector should end up with the field's title as its accessible name, and label/hideLabel handed to that widget should describe something that exists.
Steps To Reproduce
- Render
{ type: 'object', properties: { pick: { title: 'Pick', anyOf: [{ type: 'string', enum: ['a','b'] }, { type: 'number' }] } } }in any theme. screen.getByRole('combobox', { name: /Pick/ })finds nothing; the selector has no accessible name.- With
uiSchema={{ pick: { 'ui:widget': 'radio' } }}in@rjsf/daisyui, inspect therole="radiogroup"wrapper: itsaria-labelledbynames an id that is not in the document.
Environment
- OS: any
- Node: any
- npm: anyAnything else?
Found while reviewing #5356, which documents the daisyui half of this in hasLabelToReference()'s doc comment rather than guessing at core's id suffix.
Neighbouring but distinct: #5358 is the selected option's field rendering a second label for the field's own control; this is about the selector having none. #5394 is why the widget cannot tell — it is handed a label computed separately from the one a template renders.
Source: rjsf-team/react-jsonschema-form