Title and label ids move to a span, and radio, checkbox, rating and date groups lose their label's for
Detect
legend#root__title(any__titleid on a<legend>) in your CSS or tests, or a customTitleFieldTemplatethat puts itsidon the<legend>or on an element holding more than the title's text.label[for="root_color"](any field id) in your CSS or tests, for a field rendered byRadioWidget,CheckboxesWidget,AltDateWidgetorAltDateTimeWidget, or for ananyOf/oneOffield.input#root_rating(any field id) in your CSS or tests, for a field rendered byRatingWidget.#root_color__labelused to reach antd's<label>element.- Assertions on
aria-describedby,aria-invalidoraria-labelledbyin your tests, or snapshots that hold them.
Change
@rjsf/core's TitleFieldTemplate puts the titleId() it is handed on a <span> around the title's text instead of on its <legend>. An object's option selector is named by that id and would otherwise take the * and the optional data control's button into its name. A custom TitleFieldTemplate puts its id on the title's text alone:
- legend#root__title { … }
+ legend #root__title { … }
- <legend id={id}>
- {title}
- {required && '*'}
- </legend>
+ <legend>
+ <span id={id}>{title}</span>
+ {required && '*'}
+ </legend>
@rjsf/core's FieldTemplate draws the label of a RadioWidget or CheckboxesWidget with no for, which named the group's wrapper <div>, an element a for can't label. The group is named by the label's fieldLabelId() through aria-labelledby. That id is on a <span> around the label's text, as a heading's id is, so a group named by it takes no *, and label:has(#root_color__label) matches the label itself:
- label[for="root_color"] { … }
+ #root_color__label { … }
-
RatingWidgetrenders its stars as aradiogroupon the wrapper<div>, named the same way, where its label'sfornamed its hidden<input>. The wrapper carries the field's id in that<input>'s place, so a selector aimed atinput#root_ratingaims at#root_rating. -
AltDateWidget, and soAltDateTimeWidget, wraps its list of date parts in agroup<div>carrying the field's id, named the same way, around the<ul>, which keeps its list role. Its label'sfornamed an id no date part carried, so a selector aimed atlabel[for="root_when"]aims at#root_when__label. -
An
anyOf/oneOffield's label has noforwhile the option it shows renders no control at the field's id, such as an object, an array of items or anull, renders a group such asAltDateWidget's, or renders options of its own, whose option shown may be an object. The field is then named by the label througharia-labelledby, as the option selector is whatever option is shown, so a selector aimed atlabel[for="root_pet"]aims at#root_pet__label. While it shows an option rendering a single control, such as a string's input or an array's multi-select or file input, the label keeps thefor. While it shows no option, as after its selector's empty choice is picked, the label has noforwhatever its options are, since nothing renders at the field's id. -
Where
AnyOfFieldorOneOfFieldis declaredlabelledBy: 'aria-labelledby', the label has noforwhatever option shows, and a single control is named by it througharia-labelledby. An option given aui:fieldcounts as rendering a single control, so one wrapping an object keeps thefor; to draw none, register the field under a key and declarelabelledBy: 'aria-labelledby'for that key.<Form presentation={{ fields: { OneOfField: { labelledBy: 'aria-labelledby' } } }} /> -
Under
@rjsf/antd,#root_color__labelis likewise on a<span>around the label's text, which also carries the label'stitle, solabel:has(#root_color__label)matches the label.
A control's aria-describedby names only elements that render, an AltDateWidget's parts included. A control is aria-invalid while it has errors, except a radio, whose radiogroup is instead. The template's label carries fieldLabelId() on its text, and a group of radios or checkboxes is labelled by that label through aria-labelledby. Update snapshots and assertions to match.
A widget of your own registered under one of these keys takes the same declaration; see A widget registered under a built-in key takes that key's presentation declaration.
Verify
#root__titlematches a<span>holding only the title's text, and an object's option selector's accessible name has no*.getByRole('radiogroup', { name: 'Color' })orgetByRole('group', { name: 'Colors' })finds the group.#root_pet__labelmatches ananyOf/oneOffield's label text in every option.- Every id in a control's
aria-describedbyexists in the page, and an invalid control hasaria-invalid="true".
Also read:
- A custom FieldTemplate, ObjectFieldTemplate or ArrayFieldTemplate draws what the plan hands it
- A widget registered under a built-in key such as RadioWidget or RatingWidget takes that key's presentation declaration
- An anyOf or oneOf field is labelled once by its own template whichever option is selected