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

[pickers] Use slots in the mobile and desktop wrappers instead of XXXComponent and XXXProps #6381

Merged
merged 26 commits into from
Oct 11, 2022

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Oct 4, 2022

Part of #4466
Needed for #6070

Doc preview of the DatePicker slots

Desktop

  • Replace props.PaperProps by componentsProps.desktopPaper (add add components.DesktopPaper for consistency)
  • Replace props.PopperProps by componentsProps.popper (and add components.Popper for consistency)
  • Replace props.TransitionComponent by components.DesktopTransition, it is not used on mobile ! (and add a componentsProps.transition for consistency)
  • Replace props.TrapFocusProps by componentsProps.desktopTrapFocus, this prop was missing from the public component signature btw (and add a components.DesktopTrapFocus for consistency)

Mobile

  • Replace props.DialogProps by componentsProps.Dialog (and add components.dialog for consistency)
  • Add components.MobileTransition and componentsProps.mobileTransition (in the tests we were using props.DialogProps.TransitionProps which was not consistent with the desktop transition which was using props.TransitionProps).
  • Add components.MobilePaper and componentsProps.mobilePaper (replaces [pickers] Use PaperProps in mobile pickers #6223)

Changelog

Breaking changes

  • All the props used by the mobile and desktop wrappers to override components or components props has been replaced by component slots. You can find more information about this pattern in the MUI Base documentation.

    Some of the names have also been prefixed by desktop when it was unclear that the behavior was only applied on the desktop version of the pickers (or the responsive version when used on a desktop).

    The DialogProps prop has been replaced by a dialog component props slot on a responsive an mobile pickers:

    // Same on MobileDatePicker, DateTimePicker, MobileDateTimePicker, 
    // TimePicker, MobileTimePicker, DateRangePicker and MobileDateRangePicker.
    <DatePicker
    -  DialogProps={{ backgroundColor: 'red' }}
    +  componentsProps={{ dialog: { backgroundColor: 'red }}}
    />

    The PaperProps prop has been replaced by a desktopPaper component props slot on all responsive and desktop pickers:

    // Same on DesktopDatePicker, DateTimePicker, DesktopDateTimePicker, 
    // TimePicker, DesktopTimePicker, DateRangePicker and DesktopDateRangePicker.
    <DatePicker
    -  PaperProps={{ backgroundColor: 'red' }}
    +  componentsProps={{ desktopPaper: { backgroundColor: 'red }}}
    />

    The PopperProps prop has been replaced by a popper component props slot on all responsive and desktop pickers:

    // Same on DesktopDatePicker, DateTimePicker, DesktopDateTimePicker, 
    // TimePicker, DesktopTimePicker, DateRangePicker and DesktopDateRangePicker.
    <DatePicker
    -  PopperProps={{ onClick: handleClick }}
    +  componentsProps={{ popper: { onClick: handleClick }}}
    />

    The TransitionComponent prop has been replaced by a DesktopTransition component slot on all responsive and desktop pickers:

    // Same on DesktopDatePicker, DateTimePicker, DesktopDateTimePicker, 
    // TimePicker, DesktopTimePicker, DateRangePicker and DesktopDateRangePicker.
    <DatePicker
    -  TransitionComponent={Fade}
    +  components={{ DesktopTransition: Fade }}
    />

    The TrapFocusProps prop has been replaced by a desktopTrapFocus component props slot on all responsive and desktop pickers:

    // Same on DesktopDatePicker, DateTimePicker, DesktopDateTimePicker, 
    // TimePicker, DesktopTimePicker, DateRangePicker and DesktopDateRangePicker.
    <DatePicker
    -  TrapFocusProps={{ isEnabled: () => false }}
    +  componentsProps={{ desktopTrapFocus: { isEnabled: () => false }}}
    />

@flaviendelangle flaviendelangle added the component: pickers This is the name of the generic UI component, not the React module! label Oct 4, 2022
@flaviendelangle flaviendelangle marked this pull request as draft October 4, 2022 12:58
@flaviendelangle flaviendelangle self-assigned this Oct 4, 2022
@mui-bot
Copy link

mui-bot commented Oct 4, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 682.9 1,194.6 687.5 906.36 196.362
Sort 100k rows ms 786.5 1,370.1 1,241 1,110.62 201.34
Select 100k rows ms 302.9 343.1 324.4 324.62 13.007
Deselect 100k rows ms 172.7 406.6 217.3 253.46 82.922

Generated by 🚫 dangerJS against 3508f9c

@flaviendelangle flaviendelangle changed the title [pickers] Use slots in PickersPopper and PickersModalDialog [WIP] [pickers] Use slots in PickersPopper and PickersModalDialog [WIP] Oct 5, 2022
@flaviendelangle flaviendelangle changed the title [pickers] Use slots in PickersPopper and PickersModalDialog [WIP] [pickers] Use slots in the mobile and desktop wrappers instead of XXXComponent and XXXProps Oct 5, 2022
@flaviendelangle flaviendelangle marked this pull request as ready for review October 5, 2022 09:32
@github-actions
Copy link

github-actions bot commented Oct 6, 2022

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 6, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 6, 2022
Copy link
Member

@alexfauquette alexfauquette left a comment

Choose a reason for hiding this comment

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

Sounds good. I'm just wondering is PaperContent is still relevant or is it can be replaced by desktopPaper and mobilePaper


Not related to this PR (was there before) but I saw it when reading slot doc preview. The api page ends with

The component cannot hold a ref.

Even if DatePicker are wrapped into a React.forwardRef

Comment on lines -344 to 395
elevation={8}
ref={handlePaperRef}
<Transition {...TransitionProps} {...componentsProps?.desktopTransition}>
<Paper
{...paperProps}
onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
onPaperClick(event);
if (onPaperClickProp) {
onPaperClickProp(event);
}
paperProps.onClick?.(event);
}}
onTouchStart={(event: React.TouchEvent<HTMLDivElement>) => {
onPaperTouchStart(event);
if (onPaperTouchStartProp) {
onPaperTouchStartProp(event);
}
paperProps.onTouchStart?.(event);
}}
ownerState={{ ...ownerState, placement }}
className={classes.paper}
{...otherPaperProps}
>
<PaperContent {...componentsProps?.paperContent}>
Copy link
Member

Choose a reason for hiding this comment

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

Why not merging Paper and PaperContent in a single element?

If I remember correctly, the PaperContent being a Fragment was just to avoid breaking changes. Now we are allowed to break it's the opportunity

@LukasTy Was there another reason?

Copy link
Member

Choose a reason for hiding this comment

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

After many discussions and experimentations—let's isolate this PR only for the refactor of props -> slots.
Merging Paper and PaperContent is not trivial as Static pickers do not have a wrapping Paper.
And we also have the issue of possibly having difficulties changing component layout once we flatten the structure of sub-components.
I think then will be the time to revisit this topic and look into a way of having a homogenous approach towards overriding/slots.

Comment on lines +100 to +101
PaperComponent={components?.MobilePaper}
PaperProps={componentsProps?.mobilePaper}
Copy link
Member

Choose a reason for hiding this comment

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

If we keep the contentPaper should it also apply on mobile?

Suggested change
PaperComponent={components?.MobilePaper}
PaperProps={componentsProps?.mobilePaper}
PaperComponent={components?.MobilePaper ?? components?.ContentPaper}
PaperProps={componentsProps?.mobilePaper ?? componentsProps?.contentPaper}

Copy link
Member Author

Choose a reason for hiding this comment

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

@LukasTy was in favor not to because the layout wanted are often different
I will explain better than me

Copy link
Member

Choose a reason for hiding this comment

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

PaperContent could possibly be added to the mobile pickers as well.
It could be up to the user to decide when to display it or not using CSS if it is needed.

@flaviendelangle
Copy link
Member Author

Pour le rôle de PaperContent, je laisse @LukasTy juger, il connait mieux le sujet 👍

@@ -50,7 +50,7 @@
"test:performance:server": "serve test/performance -p 5001",
"test:argos": "node ./scripts/pushArgos.js",
"typescript": "lerna run --no-bail --parallel typescript",
"typescript:ci": "lerna run --concurrency 7 --no-bail --no-sort typescript",
"typescript:ci": "lerna run --concurrency 6 --no-bail --no-sort typescript",
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason behind this change? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I have a 137 TS error (out of memory)
And I can't find how to fix it without reducing the concurrency.
If you have a better solution 😬

Comment on lines -344 to 395
elevation={8}
ref={handlePaperRef}
<Transition {...TransitionProps} {...componentsProps?.desktopTransition}>
<Paper
{...paperProps}
onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
onPaperClick(event);
if (onPaperClickProp) {
onPaperClickProp(event);
}
paperProps.onClick?.(event);
}}
onTouchStart={(event: React.TouchEvent<HTMLDivElement>) => {
onPaperTouchStart(event);
if (onPaperTouchStartProp) {
onPaperTouchStartProp(event);
}
paperProps.onTouchStart?.(event);
}}
ownerState={{ ...ownerState, placement }}
className={classes.paper}
{...otherPaperProps}
>
<PaperContent {...componentsProps?.paperContent}>
Copy link
Member

Choose a reason for hiding this comment

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

After many discussions and experimentations—let's isolate this PR only for the refactor of props -> slots.
Merging Paper and PaperContent is not trivial as Static pickers do not have a wrapping Paper.
And we also have the issue of possibly having difficulties changing component layout once we flatten the structure of sub-components.
I think then will be the time to revisit this topic and look into a way of having a homogenous approach towards overriding/slots.

Comment on lines +100 to +101
PaperComponent={components?.MobilePaper}
PaperProps={componentsProps?.mobilePaper}
Copy link
Member

Choose a reason for hiding this comment

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

PaperContent could possibly be added to the mobile pickers as well.
It could be up to the user to decide when to display it or not using CSS if it is needed.

@flaviendelangle flaviendelangle merged commit e18970e into mui:next Oct 11, 2022
@flaviendelangle flaviendelangle deleted the use-slots-in-popper branch October 11, 2022 06:44
@LukasTy LukasTy added the v6.x label Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: pickers This is the name of the generic UI component, not the React module! v6.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants