daisyUI field labels, group roles and checkbox markup changed
Detect
- Snapshot tests of
@rjsf/daisyuiforms. - CSS or tests that find a daisyUI field by its
<label>, by a group's role, or by an input'srequiredattribute. - A hidden
additionalPropertiesentry, or fields hidden bydeprecatedHandling: 'hide', in a daisyUI form.
Change
@rjsf/daisyui rendered its field label from the schema type instead of from the widget, and rendered it whether or not the field had a title (#5318). The theme's API only gained exports; the markup changed as follows.
Labels:
- A field with no title renders no
<label>at all, where an empty one used to take up space. That covers every root field and array item, along with the lone required*on an untitled array item. - A
booleanrendered through anything other than a checkbox or toggle now has a label. Those two widgets render their own after the input, and so does the description. - Which widget renders the label is decided from the registry, so a widget you register as
CheckboxWidgetortoggle, wrapping the theme's own or replacing it, is the one that renders it. A widget registered under any other key gets the template's label as well as its own. ToggleWidgetrenders the field's label beside the switch. It renderedui:options.label, a flag, so that label was always empty.BaseInputTemplateno longer renders a second,display: nonelabel for its input.
Groups and hidden fields:
- A widget rendering a group of controls marks it with
role='radiogroup'orrole='group', carries the field'sid, and names itself from the label througharia-labelledby, with a__labelid suffix, sinceTitleFieldTemplateclaimstitleId(). - A
hiddenfield renders only its children, as in@rjsf/core. AnadditionalPropertiesentry hidden withui:widget: 'hidden'therefore loses its key input and remove button, and a field hidden bydeprecatedHandling: 'hide'is hidden instead of rendered in full.
Checkboxes:
ToggleWidgetshares one input component withCheckboxWidget. It wraps the input in a<span>where both used a<div>, which a<label>does not permit, and makes the checkbox honorui:autofocus.- Both take the input's
requiredattribute fromschemaRequiresTrueValue(), as the*beside it already did. A boolean a parent merely lists asrequiredcould not be submitted at all, since the browser refused the unchecked box before RJSF validated it or calledonSubmitoronError. CheckboxesWidgetno longer putsrequiredon every option box, which HTML5 constraint validation read as "check all of them" and which blocked the submit of a required array.RadioWidgetkeeps the attribute, since the browser reads same-named inputs as one group.CheckboxWidgetandToggleWidgetsetaria-describedby, so the description, errors and help around them are announced with the control.CheckboxWidgetandToggleWidgetrender the*for a required field whose schema is not aboolean, whichui:widget: 'toggle'can be pointed at. The template's label used to carry that marker, and the widget draws one of its own only for abooleanthat has to betrue.
Update snapshots and selectors. Find a group widget by its role and the field's label, such as getByRole('radiogroup', { name: 'Color' }).
Object and array containers also became named groups; see Object and array containers are named groups carrying the field's id. The date widgets' triggers changed too; see daisyUI's date pickers open from a combobox button into one popup element.
Verify
- Untitled fields render no empty label, and every titled field has exactly one.
- A form with an optional
booleanlisted in a parent'srequiredsubmits with the box unchecked. - A required checkboxes field submits once the schema's own rules are met.
Also read: