Skip to content
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

Merged
merged 3 commits into from
Apr 22, 2017
Merged

Add UI option for omitting field label #558

merged 3 commits into from
Apr 22, 2017

Conversation

cowbellerina
Copy link
Contributor

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 within ui:options. Setting the label to false will omit the label. The option won't have any effect on fields where the label is omitted already, even if it's set to true.

const schema = {type: "string"};
const uiSchema = {
  "ui:options": {
    label: false
  }
};

I'm not sure if ui:options -> label is the best place put this under. Instead of ui:showLabel or ui:hideLabel I went with this solution to potentially support other than boolean values. For example, some label value could support rendering the label for screenreaders only.

After making the change, I noticed this subject has been discussed before in #51

Checklist

  • I'm updating documentation
    • I've checked the rendering of the Markdown text I've added
    • If I'm adding a new section, I've updated the Table of Content
  • I'm adding or updating code
    • I've added and/or updated tests
    • I've updated docs if needed
    • I've run npm run cs-format on my branch to conform my code to prettier coding style
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

Copy link
Collaborator

@n1k0 n1k0 left a 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.

@@ -149,7 +150,8 @@ function SchemaFieldRender(props) {
return <div />;
}

let displayLabel = true;
const uiOptions = getUiOptions(uiSchema);
let { label: displayLabel } = uiOptions;
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@n1k0 n1k0 merged commit 84960ef into rjsf-team:master Apr 22, 2017
@n1k0
Copy link
Collaborator

n1k0 commented Apr 22, 2017

Thank you 👍

@cowbellerina cowbellerina deleted the optional-field-label branch April 22, 2017 14:03
n1k0 added a commit that referenced this pull request Apr 25, 2017
* Make the base input widget customizable. (#547)
* Add UI option for omitting field label (#558)
* add prop-types package and add respective imports b/c it was deprecated (#549)
@n1k0
Copy link
Collaborator

n1k0 commented Apr 25, 2017

Released in v0.47.0.

eeinowski pushed a commit to eeinowski/react-jsonschema-form that referenced this pull request May 23, 2017
* Make field label optional via UI options
eeinowski pushed a commit to eeinowski/react-jsonschema-form that referenced this pull request May 23, 2017
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants