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

allow Material-ui boolean checkboxes to have descriptions #2330

Closed
wants to merge 30 commits into from
Closed

allow Material-ui boolean checkboxes to have descriptions #2330

wants to merge 30 commits into from

Conversation

cfluke-twilio
Copy link

@cfluke-twilio cfluke-twilio commented Apr 9, 2021

Reasons for making this change

Descriptions for boolean checkboxes were being ignored.

If this is related to existing tickets, include links to them as well. Use the syntax fixes #[issue number] (ex: fixes #123).
fixes #2203

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/

@cfluke-twilio cfluke-twilio changed the title allow booleans to have descriptions allow Material-ui boolean checkboxes to have descriptions Apr 9, 2021
@cfluke-twilio
Copy link
Author

Is the correct fix to this issue, to add the schema.description check in CheckboxWidget?
to make it similar to core?

this appears to be a problem in material-ui, antd, and sematic-ui as well.

The current solution does currently make it double appear in default theme. This seems to be caused by the WrapIfAdditional and DefaultTemplate adding the description as well.

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.

Are you sure this is the right approach? This same function appears in utils.js --

export function getDisplayLabel(schema, uiSchema, rootSchema) {
const uiOptions = getUiOptions(uiSchema);
let { label: displayLabel = true } = uiOptions;
if (schema.type === "array") {
displayLabel =
isMultiSelect(schema, rootSchema) ||
isFilesArray(schema, uiSchema, rootSchema);
}
if (schema.type === "object") {
displayLabel = false;
}
if (schema.type === "boolean" && !uiSchema["ui:widget"]) {
displayLabel = false;
}
if (uiSchema["ui:field"]) {
displayLabel = false;
}
return displayLabel;
}
-- is there another way to fix this?

@cfluke-twilio
Copy link
Author

cfluke-twilio commented Apr 12, 2021

Hi @epicfaace, see my comment above.
The easiest, simplest fix for material ui is to add:
{schema.description && ( <DescriptionField description={schema.description} /> )}

into the CheckBox widget itself. but the problem is in 2 other theme libraries as well. So I was looking at a more global solution to keep the pattern consistent across the various themes.

From a library design perspective, do you want widgets to be responsible for their own descriptions? or allow WrapIfAdditional pattern?

Should I move ahead with only the material-ui fix to move this forward?

@epicfaace
Copy link
Member

From a library design perspective, do you want widgets to be responsible for their own descriptions? or allow WrapIfAdditional pattern?

Yeah, let's move ahead with the material-ui fix to move this forward for now. Unfortunately, as you note, there is an inconsistency between themes in which some themes have widgets responsible for their own descriptions, while others don't. Maybe we can consider improving that to make it consistent in a future major version release.

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.

Thanks, can you add a snapshot test for this as well?

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.

Looks good -- thanks!

@epicfaace
Copy link
Member

From a library design perspective, do you want widgets to be responsible for their own descriptions? or allow WrapIfAdditional pattern?

Sorry, @cfluke-twilio I'm a bit confused. Why do descriptions work for the TextWidget in material-ui, even though there's no code like the one in this PR for TextWidget?

@cfluke-twilio
Copy link
Author

cfluke-twilio commented Apr 27, 2021

TextWidget is calling the getDisplayLabel from the core utils here
The FieldTemplate uses that getDisplayLabel to determine if it should add a Typography and rawDescription here

The core utils has getDisplayLabel return false for checkboxes.

@Morriz
Copy link

Morriz commented Jun 14, 2021

bump

@Morriz
Copy link

Morriz commented Jun 14, 2021

We have created a lot of hacky workarounds to overcome all of these weird exceptions. Maybe we should consider adding to your core, as we depend on it sooooo much @epicfaace. Thanks for all the hard work. I do get the feeling that the maintainers are all paid volunteers, and it would be awesome if this project could get adopted by a major corp to start funding development.

epicfaace and others added 13 commits June 14, 2021 11:12
…ss hidden prop to ObjectFieldTemplate (#2405)

* material-ui: hide grid for hidden fields

Implementations follows the one that already exists for ant design.

Closes #1974

* Update test snapshot to latest master

* Add comment

* Move ui:widget evaluation into core

* Add test for hidden in antd

* Hide hidden fields in bootstrap

Closes #2175

* Improve tests

* Remove whitespace for hidden in fluent-ui

* Update custom-templates.md

Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
Bumps [postcss](https://github.com/postcss/postcss) from 7.0.27 to 7.0.36.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](postcss/postcss@7.0.27...7.0.36)

---
updated-dependencies:
- dependency-name: postcss
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
* Deploy canary builds to npm from master

* fix typo

* use npx
* Add null check to componentDidUpdate

* added test case to altdatewidget
* Add null check to componentDidUpdate

* added test case to altdatewidget

* change npm install to npm ci in release pipeline

Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
epicfaace and others added 12 commits June 29, 2021 11:44
It seems like 3.0.0 doesn't work if you use the UMD bundle. Reverting it to 2.5.1 for now to address #2447
* Restore global external for UMD hosted in CDN

* Update webpack.config.dist.js

* Update docs/main.js

Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.1.5 to 2.3.0.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v2.1.5...v2.3.0)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This pull request was closed.
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.

Checkbox doesn't support descriptions for material-ui / bootstrap-4
6 participants