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

[TabScrollButton] Add ability to change left and right icons #33863

Merged
merged 22 commits into from
Mar 15, 2023

Conversation

pratikkarad
Copy link
Contributor

Closes #33235

@mui-bot
Copy link

mui-bot commented Aug 8, 2022

Netlify deploy preview

https://deploy-preview-33863--material-ui.netlify.app/

@material-ui/core: parsed: +0.14% , gzip: +0.14%
@material-ui/lab: parsed: +0.28% , gzip: +0.24%

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 278b2bb

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

I basically have the same comment as on the other PR. We need to also have componentsProps for allowing adding additional props. @pratikkarad in order to speed up the review process & not have many distraction, can we focus on getting one of these PRs to the finish line first, and then follow up with the others.

@pratikkarad
Copy link
Contributor Author

Sure, no problem 👍🏻

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

I apologize for the delayed review. I've left some comments, please have a look.


const theme = useTheme();
const isRtl = theme.direction === 'rtl';

const ownerState = { isRtl, ...props };

const classes = useUtilityClasses(ownerState);
const ScrollButtonStart = components.ScrollButtonStart;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const ScrollButtonStart = components.ScrollButtonStart;
const ScrollButtonStart = components.ScrollButtonStart ?? KeyboardArrowLeft;


const theme = useTheme();
const isRtl = theme.direction === 'rtl';

const ownerState = { isRtl, ...props };

const classes = useUtilityClasses(ownerState);
const ScrollButtonStart = components.ScrollButtonStart;
const ScrollButtonEnd = components.ScrollButtonEnd;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const ScrollButtonEnd = components.ScrollButtonEnd;
const ScrollButtonEnd = components.ScrollButtonEnd ?? KeyboardArrowRight;

Comment on lines 52 to 55
components = {
ScrollButtonStart: KeyboardArrowLeft,
ScrollButtonEnd: KeyboardArrowRight,
},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
components = {
ScrollButtonStart: KeyboardArrowLeft,
ScrollButtonEnd: KeyboardArrowRight,
},
components = {},

The main value with this is that, if developer apply only one, it would crash the component


const theme = useTheme();
const isRtl = theme.direction === 'rtl';

const ownerState = { isRtl, ...props };

const classes = useUtilityClasses(ownerState);
const ScrollButtonStart = components.ScrollButtonStart;
const ScrollButtonEnd = components.ScrollButtonEnd;
const getDefaultProps = (icon) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const getDefaultProps = (icon) => {
const getIconProps = (icon) => {

@@ -67,9 +94,9 @@ const TabScrollButton = React.forwardRef(function TabScrollButton(inProps, ref)
{...other}
>
{direction === 'left' ? (
<KeyboardArrowLeft fontSize="small" />
<ScrollButtonStart {...getDefaultProps(ScrollButtonStart)} />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<ScrollButtonStart {...getDefaultProps(ScrollButtonStart)} />
<ScrollButtonStart {...getIconProps(ScrollButtonStart)} />

) : (
<KeyboardArrowRight fontSize="small" />
<ScrollButtonEnd {...getDefaultProps(ScrollButtonEnd)} />
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<ScrollButtonEnd {...getDefaultProps(ScrollButtonEnd)} />
<ScrollButtonEnd {...getIconProps(ScrollButtonEnd)} />

@@ -48,5 +50,33 @@ describe('<TabScrollButton />', () => {
);
expect(getAllByTestId('KeyboardArrowRightIcon').length).to.equal(1);
});

it('should render with the ArrowBackIcon icon', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it('should render with the ArrowBackIcon icon', () => {
it('should render with the custom start icon', () => {

expect(getAllByTestId('ArrowBackIcon').length).to.equal(1);
});

it('should render with the ArrowForwardIcon icon', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it('should render with the ArrowForwardIcon icon', () => {
it('should render with the end icon', () => {

Comment on lines 246 to 249
components = {
ScrollButtonStart: KeyboardArrowLeft,
ScrollButtonEnd: KeyboardArrowRight,
},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
components = {
ScrollButtonStart: KeyboardArrowLeft,
ScrollButtonEnd: KeyboardArrowRight,
},
components = {},

@pratikkarad pratikkarad requested review from mnajdova and removed request for michaldudak and hbjORbj September 26, 2022 18:42
@pratikkarad
Copy link
Contributor Author

Hi @mnajdova, I made changes in PR as suggested. I also tested locally it is working fine but failing on ci/circleci. Could you please advise, what is going wrong? Thanks!

@pratikkarad
Copy link
Contributor Author

Hi @mnajdova, As per my understanding, we have removed the initialization of components prop from Tab.js

components = {
  ScrollButtonStart: KeyboardArrowLeft,
  ScrollButtonEnd: KeyboardArrowRight,
},

to

components = {},

that's why Argo is complaining about this because the start & end icon was hard coded before. Now it is trying to compare the before and after snapshots.

@michaldudak michaldudak added the component: tabs This is the name of the generic UI component, not the React module! label Oct 12, 2022
@pratikkarad
Copy link
Contributor Author

I tried initializing the component prop in Tab.test.js, still, it is failing at circleci regression test.

Hi @mnajdova, As per my understanding, we have removed the initialization of components prop from Tab.js

components = {
  ScrollButtonStart: KeyboardArrowLeft,
  ScrollButtonEnd: KeyboardArrowRight,
},

to

components = {},

that's why Argo is complaining about this because the start & end icon was hard coded before. Now it is trying to compare the before and after snapshots.

As I suggested, I think initializing the component prop with default Icons may solve the issue. Any suggestions on this?
cc: @mnajdova, @michaldudak

@michaldudak
Copy link
Member

Regression tests fail because they in your branch use the old SDK that's not supported anymore. Please marge in the latest master.

@pratikkarad
Copy link
Contributor Author

Hi @mnajdova, I've updated PR, PTAL.

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

@pratikkarad we've updated the props name to slots and slotProps accordingly. Would be great if we can follow this new convention. Also, I would use the description we have in the other components for these props, so that we are consistent. From technical point of view, I don't have any comments 👍

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 27, 2023
@safeamiiir
Copy link
Contributor

Hi @mnajdova,
I was trying to find an issue to work on.
I found this PR only needs tiny name change, Can I push new commit into this branch and make it done?

As I understand we only need a naming change:
component -> slot
componentProps -> slotProps

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Mar 10, 2023
@ZeeshanTamboli
Copy link
Member

@safeamiiir Please go ahead.

@ZeeshanTamboli ZeeshanTamboli added the new feature New feature or request label Mar 15, 2023
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

I made the appropriate and required changes.

Supported callback in slotsProps, improved unit tests, added TypeScript tests, and updated the documentation.

It looks good to me now!

@ZeeshanTamboli ZeeshanTamboli merged commit 6776631 into mui:master Mar 15, 2023
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! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TabScrollButton] Add ability to change left and right icons
6 participants