-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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][IconButton] Fix disableRipple behaviour when disableRipple is set in MuiButtonBase theme #43714
Conversation
This reverts commit d9d0a37.
Netlify deploy previewhttps://deploy-preview-43714--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
fa42d80
to
5e5c258
Compare
(I have reverted old PR logic and updated new logic in same PR, let me know if this has to be split in seperate PR's) |
@DiegoAndai I'm not sure why before and after sandboxes isn't getting updated code, meanwhile can you paste below code in these following demos to test the fix before: https://mui.com/material-ui/react-button/#icon-button
|
Hmm, what do you mean by this 🤔 ? i tried clicking on icons in this demo, everything seems to be fine Recording.2024-09-11.230629.mp4 |
@sai6855 I found the issue and committed it: 34eeaec. I think this covers it. Let's wait for @siriwatknp's review to merge this. |
@@ -113,7 +113,7 @@ const IconButtonRoot = styled(ButtonBase, { | |||
...Object.entries(theme.palette) | |||
.filter(createSimplePaletteValueFilter()) // check all the used fields in the style below | |||
.map(([color]) => ({ | |||
props: { color, disableRipple: false }, | |||
props: (props) => props.color === color && !props.disableRipple, |
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.
@siriwatknp If I remember correctly, there's a problem with accessing color like this, isn't there? How might we implement this one?
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.
Ah, you are right. This won't work with Pigment CSS. Let me think of something else.
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.
Here is my proposal using CSS variable: sai6855#1.
We keep the previous logic and separate the disableRipple
from the variants.
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.
Here is my proposal using CSS variable: sai6855#1.
We keep the previous logic and separate the
disableRipple
from the variants.
Sure, @DiegoAndai I'm not really familiar with the changes, but if you give the go-ahead to the sai6855#1 I can merge the PR.
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 @siriwatknp! This solution makes sense 👌🏼
@sai6855 may I ask you to update this PR with that solution?
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.
@Janpot I can confirm that your quick test works, as well as CSS variables in the IconButton component when running with Karma.
I discovered that the issue I'm facing, and why the test is not working, is that for some reason I can't get the hover style to be applied. I assume this is the reason the existing test is skipped in Karma: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/IconButton/IconButton.test.js#L146
I've tried fireEvent.mouseMove
, fireEvent.mouseOver
, fireEvent.mouseEnter
, and userEvent.hover
, and none are working.
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.
I don't think it's possible to trigger pseudo classes programmatically if that's what the style relies on on. So I don't believe fireEvent
/userEvent
will ever be able to do that. testing-library/user-event#1210
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.
But we are currently using fireEvent
in JSDOM to test the hover style: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/IconButton/IconButton.test.js#L152
This is the only test we have that uses this, though, and it seems like:
- JSDOM handles hover but not CSS variables
- Browser tests handle CSS variables but not hover
😅
At this point, I'm considering removing the test and opening an issue to properly implement hover tests in the future. What do you think?
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.
We're working on a migration to vitest
and in their browser mode we'll have access to real user events https://vitest.dev/guide/browser/context.html. Doesn't look like karma has an equivalent. Maybe just skip the test for now?
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.
👍🏼 agree
Thanks for working on this @sai6855 |
This PR does following things
disableRipple
onMuiButtonBase
doesn't disable ripple effect onIconButton
#43617closes #43617
check #43617 (comment) for more context
before: https://codesandbox.io/embed/p2smlj?module=/src/Demo.tsx
after: https://codesandbox.io/embed/g7kd38?module=/src/Demo.tsx