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

Make material-ui and fluent-ui pull TextWidget from the registry; remove registry prop from <div> in TextWidget #2515

Conversation

heath-freenome
Copy link
Member

@heath-freenome heath-freenome commented Aug 12, 2021

Reasons for making this change

In all the TextWidget wrappers, rather than directly import TextWidget from the source hierarchy, instead pull from the registry.widgets

  • These changes allow all of these TextWidget wrappers (like EmailWidget, etc...) to immediately use a custom TextWidget class
  • Added a new Registry type in the core/index.d.ts file, refactoring it from FieldProps, and adding it to WidgetProps as well
  • Updated all of the material-ui and fluent-ui widgets to use TextWidget from the registry
    • Converted the material-ui PasswordWidget to simply use TextWidget in a manner similar the other material-ui wrappers
      • fluent-ui simply wraps TextWidget and it seemed like doing so here made sense as well
  • Updated material-ui TextWidget to declare registry in the props so it doesn't get collected into the textFieldProps
  • Needed to updated the snapshots for the material-ui tests since registry is no longer part of the snapshots
    • The only non-registry change was adding placeholder='' to the PasswordWidget, since password inputs are allowed to have them in html 5 it seems like a small bug fix
  • Also needed to update UpDownWidget.test.tsx to add a mock registry
  • Updated packages/bootstrap-4/test/helpers/createMocks.ts to add a mock registry

fixes #2512

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

- In all the `TextWidget` wrappers, rather than directly import `TextWidget` from the source hierarchy, instead pull from the `registry.widgets`
- This allows all of these `TextWidget` wrappers (like `EmailWidget`, etc...) to immediately use a custom `TextWidget` class
- Added a new `Registry` type in the `core/index.d.ts` file, refactoring it from `FieldProps`, and adding it to `WidgetProps` as well
- Needed to updated the snapshots for the `material-ui` tests for `Form` since registry is now part of the snapshot
  - Also needed to update `UpDownWidget.test.tst` to add a mock `registry`
- Updated `packages/bootstrap-4/test/helpers/createMocks.ts` to add a mock `registry`
@heath-freenome
Copy link
Member Author

@epicfaace Here's the PR... let me know what is needed to get it merged

const PasswordWidget = (props: TextWidgetProps) => {
const { registry } = props;
const { TextWidget } = registry.widgets;
return <TextWidget type="password" {...props} />;
Copy link
Member

Choose a reason for hiding this comment

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

Will this render the exact same content as the old PasswordWidget component? Trying to see if this will be a breaking change or not.

Copy link
Member Author

@heath-freenome heath-freenome Aug 12, 2021

Choose a reason for hiding this comment

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

The snapshot update was to add the registry to the outer div (which seems weird and probably should be removed). The only other thing was adding an empty placeholder to the input, which honestly might have been a bug with the PasswordWidget before.

Copy link
Member Author

@heath-freenome heath-freenome Aug 12, 2021

Choose a reason for hiding this comment

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

@epicfaace let me know if stripping the registry from the outer div (as seen in the snapshots) is considered a breaking change. Honestly, to me it feels like a super helpful fix since the whole registry object being dumped to the div was just useless clutter on the div tag... especially when the rootSchema is HUGE

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think it should be fine, not considered a breaking change since that doesn't affect how users use the library / any of the look-and-feel at all.

…ome part of `textFieldProps` which just seems wrong
@epicfaace epicfaace changed the title Make material-ui and fluent-ui pull TextWidget from the registry Make material-ui and fluent-ui pull TextWidget from the registry; remove registry prop from <div>s Aug 13, 2021
@epicfaace epicfaace changed the title Make material-ui and fluent-ui pull TextWidget from the registry; remove registry prop from <div>s Make material-ui and fluent-ui pull TextWidget from the registry; remove registry prop from <div> in TextWidget Aug 13, 2021
@heath-freenome
Copy link
Member Author

Yay! Thanks for the approval! I look forward to updating my code to use these changes

@epicfaace epicfaace merged commit fa91f2b into rjsf-team:master Aug 13, 2021
@heath-freenome heath-freenome deleted the TextWidget-wrappers-use-registry-material-and-fluent-ui branch August 13, 2021 04:51
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.

Customizing @material-ui TextWidget requires me to customize ALL of the TextWidget wrapped widgets
2 participants