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 missing material theme string widgets #1789
Add missing material theme string widgets #1789
Conversation
I don't think this requires any documentation changes since this is just filling in gaps on the material theme, but I am happy to add anything if desired. As far as tests, I wasn't entirely sure what was best to add here. There are existing tests in |
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.
Thanks for these changes -- really appreciate them. Can you add some snapshot tests that cover each widget in https://github.com/rjsf-team/react-jsonschema-form/blob/558ecd1c8866c0dba1efb2158ec792462a71aa3c/packages/material-ui/test/Form.test.tsx (meaning you would add schemas with the different string formats there)?
I'm not quite sure how to strike the balance between testing for themes -- between testing too much to be repetitive with the core library and too little to be not comprehensive enough -- for now, just settled on snapshot tests to do that (see #1688).
Snapshots were updated for email and url, I will add some schema for the other types. I just noticed that my prettier extension in vscode reformatted some of the stuff I touched. I didn't find a prettier config, I did notice this comment https://react-jsonschema-form.readthedocs.io/en/latest/contributing/#coding-style and just wanted to make sure the defaults are being used and some of the formatting stuff included here is OK or if I should back it out. |
Tests added and snapshots have been updated @epicfaace. |
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.
Interesting, looks like that happens in Chrome but not Safari. It appears to be a bug with material-ui. From what I gather I need to set this on
Check out the example here: https://material-ui.com/components/pickers/#datepickers This will mean that label will not bounce up above the input upon focus, which is the current default behavior on rjsf. If you're OK with that I'll work that in. Thinking out loud here... We could use these pickers https://material-ui.com/components/pickers/ for the date and time widgets, or we could use them in the alt-date alt-datetime widgets too. Any interest in either of those options? |
@epicfaace here's a set of changes that would allow for passing the shrink settings. https://github.com/stanlemon/react-jsonschema-form/pull/1/files It also allows for further properties to be passed down to the underlying |
Yeah, those would probably be ideal. We would need to add a peer dependency on |
Just to clarify: They would be ideal for the main widgets or the alt widgets? |
Probably for the main widgets. |
Sounds good to me! |
Good deal. I merged in the change to support the shrink param, so that issue should be resolved. |
Clean build, this one might be ready. 🤞 If you have any guidance on that last commit with regards to the typing let me know. I think it is OK, but my typescript-foo is limited so I'm not entirely confident. |
@stanlemon can you also change the format in which the date widget gives its value? Right now, the format doesn't seem to be valid for a "date-time" format in JSON Schema: Compare this with the default date widget value: |
@epicfaace good catch, 81b2035 should resolve that. Thanks. |
@@ -1048,6 +1048,36 @@ export function toDateString( | |||
return time ? datetime : datetime.slice(0, 10); | |||
} | |||
|
|||
export function utcToLocal(jsonDate) { |
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.
What exactly is the point of this function?
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.
This is what ensures the format is correct in the Bootstrap theme. I didn’t write this, just simply relocated it to utils.
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.
Looks great, thanks!
Reasons for making this change
Several string widgets are missing from the material theme, specifically color, date, date time, email and URI. Without these widgets using the various formats for fields with type 'string' will fall back to the bootstrap theme. This PR adds support for all of those widgets in material UI with the same reuse pattern as in the bootstrap theme (pass back the
TextWidget
with a more specific type, see https://github.com/rjsf-team/react-jsonschema-form/blob/master/packages/core/src/components/widgets/ColorWidget.js for an example).Note that I needed to add 'type' to the
WidgetProps
to support this. The bootstrap widgets do not have their props typed so I believe this is why that wasn't an issue before.Here is an example schema that you can use in the playground to see what happens when you use the material theme.
There is a similar PR just for the date widget in #1765
Checklist