Skip to content

Commit

Permalink
FieldBlock: render 'required' and 'aria-describedby' attributes when …
Browse files Browse the repository at this point in the history
…appropriate

ref: wagtail#10300
  • Loading branch information
Stormheg committed Jul 20, 2023
1 parent 1dd6dc3 commit 5ab482b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client/src/components/StreamField/blocks/FieldBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,25 @@ export class FieldBlock {

this.prefix = prefix;

const extraAttributes = {};

// If the block has help text, we should associate this with the input rendered by the widget.
// To accomplish this, we must tell the widget to render an aria-describedby attribute referring in its HTML.
if (this.blockDef.meta.helpText) {
extraAttributes["aria-describedby"] = `${prefix}-helptext`;
}
// If the block is required, we must tell the widget to render a required attribute in its HTML.
if (this.blockDef.meta.required) {
extraAttributes.required = "";
}

try {
this.widget = this.blockDef.widget.render(
widgetElement,
prefix,
prefix,
initialState,
extraAttributes,
this.parentCapabilities,
);
} catch (e) {
Expand Down

0 comments on commit 5ab482b

Please sign in to comment.