Skip to content

Commit

Permalink
Help elements need a predictable ID (#2360)
Browse files Browse the repository at this point in the history
* Help elements need a predictable ID

* Updated help id in semantic-ui theme

Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
  • Loading branch information
bradhugh and epicfaace authored May 19, 2021
1 parent effe15d commit 9e119fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions packages/core/src/components/fields/SchemaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,22 @@ function LabelInput(props) {
}

function Help(props) {
const { help } = props;
const { id, help } = props;
if (!help) {
return null;
}
if (typeof help === "string") {
return <p className="help-block">{help}</p>;
return (
<p id={id} className="help-block">
{help}
</p>
);
}
return <div className="help-block">{help}</div>;
return (
<div id={id} className="help-block">
{help}
</div>
);
}

function ErrorList(props) {
Expand Down Expand Up @@ -316,7 +324,7 @@ function SchemaFieldRender(props) {
/>
),
rawDescription: description,
help: <Help help={help} />,
help: <Help id={id + "__help"} help={help} />,
rawHelp: typeof help === "string" ? help : undefined,
errors: <ErrorList errors={errors} />,
rawErrors: errors,
Expand Down
2 changes: 1 addition & 1 deletion packages/semantic-ui/src/FieldTemplate/FieldTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function FieldTemplate({
)}
</MaybeWrap>
)}
<HelpField helpText={rawHelp} id={id} />
<HelpField helpText={rawHelp} id={id + "__help"} />
<RawErrors errors={rawErrors} options={errorOptions} />
</MaybeWrap>
</Form.Group>
Expand Down

0 comments on commit 9e119fc

Please sign in to comment.