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

[material-ui][Tabs] Deprecate *Props and complete slots, slotProps #45012

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jan 13, 2025

part of #41281

  • Added slots: root, scroller, flexContainer, scrollbar, indicator, scrollButtons, startScrollButtonIcon, endScrollButtonIcon.
    These are existing slots and classes.

@siriwatknp siriwatknp added the component: tabs This is the name of the generic UI component, not the React module! label Jan 13, 2025
@mui-bot
Copy link

mui-bot commented Jan 13, 2025

Netlify deploy preview

TabList: parsed: +1.21% , gzip: +1.15%
@material-ui/core: parsed: +0.13% , gzip: +0.14%
@material-ui/lab: parsed: +0.24% , gzip: +0.24%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 538e464

@siriwatknp siriwatknp marked this pull request as ready for review January 13, 2025 07:07
@siriwatknp siriwatknp requested a review from DiegoAndai January 13, 2025 07:07
},
indicator: {
expectedClassName: classes.indicator,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

i think tests for scrollButton, startScrollButtonIcon, endScrollButtonIcon are missing

Copy link
Member Author

@siriwatknp siriwatknp Jan 21, 2025

Choose a reason for hiding this comment

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

Added at the end of this file. I could not leverage describeConformance because there are 2 scroll buttons when rendered, so the tests will fail due to queryByTestId.

Copy link
Contributor

@sai6855 sai6855 left a comment

Choose a reason for hiding this comment

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

LGTM, just left a comment

elementType: FlexContainer,
externalForwardedProps,
ownerState,
getSlotProps: (handlers) => ({
Copy link
Member

Choose a reason for hiding this comment

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

Why use getSlotProps here and not with other handlers?

Where do the handlers.onKeyDown?.(event) come from? If it is from the props, then can we extract it and handle this on the handleKeyDown definition?

Copy link
Member Author

@siriwatknp siriwatknp Jan 21, 2025

Choose a reason for hiding this comment

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

Why use getSlotProps here and not with other handlers?

Because only flexContainer slot has onKeyDown logic in this component.

Where do the handlers.onKeyDown?.(event) come from

Yes, it comes from slotProps.flexContainer

The intention of the change solely due to slotProps.* could be a function. That's why getSlotProps exists from MUI Base to ensure that handlers is resolved to an object.

Copy link
Member

Choose a reason for hiding this comment

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

Because only flexContainer slot has onKeyDown logic in this component.

But there are other event handlers, for example onChange on the scroller slot 🤔

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 guess you meant scrollbar slot and I think your question is "why scrollbar does not have getSlotProp given it receive onChange" right?

Let me update it.

},
});

const [FlexContainerSlot, flexContainerSlotProps] = useSlot('flexContainer', {
Copy link
Member

Choose a reason for hiding this comment

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

The flexContainer slot seems difficult to understand from the users perspective, would 'list' be a better name?

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 don't think so, this is because the slot is created with flexContainer name. It's not a new slot.

// line: 198
const FlexContainer = styled('div', {
  name: 'MuiTabs',
  slot: 'FlexContainer',
  overridesResolver: (props, styles) => {
    const { ownerState } = props;
    return [
      styles.flexContainer,
      ownerState.vertical && styles.flexContainerVertical,
      ownerState.centered && styles.centered,
    ];
  },
})({

So styleOverrides already work with flexContainer slot. I think slots and slotProps should follow the same name.

Copy link
Member

Choose a reason for hiding this comment

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

Could we deprecate styles.flexContainer and change it? I really think it's a bad name as it doesn't explain to users what this slot's role is in the component: flexContainer can be anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure? that will increase the effort for writing a codemod to migrate styleOverrides. Given there is no complain about the flexContainer name so far, do you think it's worth to rename it @aarongarciah ?

Copy link
Member

Choose a reason for hiding this comment

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

I agree it's not a good name. Let's change it now that we are at it 🙏

Copy link
Member Author

@siriwatknp siriwatknp Jan 22, 2025

Choose a reason for hiding this comment

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

@DiegoAndai let's do this in v7. Renaming flexContainer to list for the styleOverrides altogether now will be a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabs This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants