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

Hide grid for hidden fields (material-ui, bootstrap-4, fluent-ui); pass hidden prop to ObjectFieldTemplate #2405

Merged
merged 12 commits into from
Jun 15, 2021
Merged

Conversation

Fox32
Copy link
Contributor

@Fox32 Fox32 commented May 27, 2021

Reasons for making this change

hidden fields aren't hidden for material-ui as the grid around them is still displayed. This hides the grid for hidden fields.
Implementations follows the one that already exists for ant design.

Before (note the space before the disabled example)

Bildschirmfoto 2021-05-27 um 11 17 55

After

Bildschirmfoto 2021-05-27 um 11 20 59

Closes #1974
Fixes #1683

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests
    • I've updated docs if needed
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

Deploy preview

Once CI finishes, you should be able to view a deploy preview of the playground from this PR at this link: https://deploy-preview-[PR_NUMBER]--rjsf.netlify.app/

Implementations follows the one that already exists for ant design.

Closes #1974
@Fox32 Fox32 marked this pull request as ready for review May 27, 2021 09:28
@Fox32 Fox32 requested a review from agustin107 as a code owner May 27, 2021 09:28
@Fox32
Copy link
Contributor Author

Fox32 commented Jun 7, 2021

hey @agustin107, can you take a look?

@Morriz
Copy link

Morriz commented Jun 9, 2021

politely bumping @agustin107 ;)

or can other ppl review @Fox32 ?

@Fox32
Copy link
Contributor Author

Fox32 commented Jun 14, 2021

Not sure, @agustin107 is set as a codeowner, maybe @epicfaace can review it too

</Grid>
))}
{properties.map((element: any, index: number) =>
isHidden(element) ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change in ObjectFieldTemplate -- what does it do? Isn't the FieldTemplate change enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here (ObjectFieldTemplate) a <Grid> with a margin is added, which means that a hidden element would still take up space. We have to remove the <Grid> if the field is hidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the code needs a comment to explain this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Instead of doing this, could we check if element.content === null and then remove the grid? I'm asking because it's currently possible to specify widgets in different ways than ui:widget (we can do {'ui:options': {'widget': ...) so it's good not to tie the implementation specifically to ui:widget.

Can you also add a comment describing why we're hiding the grid in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm element.content === null is not true in that case. There is still a field create, just a hidden one. Is there any other way I can use to support both cases without having to hard code it in that spot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point.

I wonder if we could still pass the hidden prop over to ObjectFieldTemplate from @rjsf/core, though, as this would reduce code duplication with checking ui:widget. How feasible / easy do you think that change would be?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this would also help out with #2175! (similar issue with bootstrap-4 theme)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some trouble with nanoid, but I think I got it working now. Still have to postpone it till tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is updated. I couldn't find a good place in core to test it, so I skipped that. I replaced the old implementation in antd. I also went through all themes and fixed #2175 for bootstrap-4 and fluid-ui.

@epicfaace epicfaace self-assigned this Jun 14, 2021
Copy link
Member

@epicfaace epicfaace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@epicfaace epicfaace changed the title material-ui: hide grid for hidden fields Hide grid for hidden fields (material-ui, bootstrap-4, fluent-ui) Jun 15, 2021
@epicfaace epicfaace changed the title Hide grid for hidden fields (material-ui, bootstrap-4, fluent-ui) Hide grid for hidden fields (material-ui, bootstrap-4, fluent-ui); pass hidden prop to ObjectFieldTemplate Jun 15, 2021
@epicfaace epicfaace merged commit 2393797 into rjsf-team:master Jun 15, 2021
@Fox32 Fox32 deleted the feat/fix-hidden-material-ui branch June 15, 2021 14:48
nickgros added a commit to nickgros/react-jsonschema-form that referenced this pull request Jun 18, 2021
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.

Hidden field with Material-ui display large Spacing The ui:widget hidden does not hide description
3 participants