-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UI option for omitting field label #558
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a pending question though.
src/components/fields/SchemaField.js
Outdated
@@ -149,7 +150,8 @@ function SchemaFieldRender(props) { | |||
return <div />; | |||
} | |||
|
|||
let displayLabel = true; | |||
const uiOptions = getUiOptions(uiSchema); | |||
let { label: displayLabel } = uiOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this works without a default value set to true; hint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it did work because the default value is set in DefaultTemplate.defaultProps
.
Anyways, it's clearer for the reader if the default value is also set here. I made the necessary changes to the code.
Thank you 👍 |
Released in v0.47.0. |
* Make field label optional via UI options
* Make the base input widget customizable. (rjsf-team#547) * Add UI option for omitting field label (rjsf-team#558) * add prop-types package and add respective imports b/c it was deprecated (rjsf-team#549)
Reasons for making this change
Sometimes you may want to render fields without label associated with them.
While it's possible to control the rendering of the field by creating a custom field template, or by hiding the label using CSS, they both feel non-ideal for basic use cases where you simply want to get rid of the label.
This PR introduces a new
label
option withinui:options
. Setting thelabel
tofalse
will omit the label. The option won't have any effect on fields where the label is omitted already, even if it's set totrue
.I'm not sure if
ui:options
->label
is the best place put this under. Instead ofui:showLabel
orui:hideLabel
I went with this solution to potentially support other than boolean values. For example, somelabel
value could support rendering the label for screenreaders only.After making the change, I noticed this subject has been discussed before in #51
Checklist
npm run cs-format
on my branch to conform my code to prettier coding style