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

[ButtonBase] Fix when changing enableRipple prop from false to true #19667

Merged
10 changes: 5 additions & 5 deletions packages/material-ui/src/ButtonBase/ButtonBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ const ButtonBase = React.forwardRef(function ButtonBase(props, ref) {
{...other}
>
{children}
{!disableRipple && !disabled ? (
<NoSsr>
{/* TouchRipple is only needed client-side, x2 boost on the server. */}
<NoSsr>
{!disableRipple && !disabled && (
/* TouchRipple is only needed client-side, x2 boost on the server. */
<TouchRipple ref={rippleRef} center={centerRipple} {...TouchRippleProps} />
</NoSsr>
) : null}
)}
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
</NoSsr>
</ComponentProp>
);
});
Expand Down
40 changes: 40 additions & 0 deletions packages/material-ui/src/ButtonBase/ButtonBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,46 @@ describe('<ButtonBase />', () => {
button.querySelectorAll('.ripple-visible .child:not(.child-leaving)'),
).to.have.lengthOf(0);
});

it('should not crash when changes enableRipple from false to true', () => {
function App() {
const [enableRipple, setRipple] = React.useState(false);

return (
<div>
<button
type="button"
data-testid="trigger"
onClick={() => {
setRipple(true);
}}
>
Trigger crash
</button>
<ButtonBase
autoFocus
TouchRippleProps={{
classes: {
ripplePulsate: 'ripple-pulsate',
},
}}
focusRipple
disableRipple={!enableRipple}
>
1
</ButtonBase>
<ButtonBase autoFocus focusRipple>
2
</ButtonBase>
</div>
);
}

const { container, getByTestId } = render(<App />);

fireEvent.click(getByTestId('trigger'));
expect(container.querySelectorAll('.ripple-pulsate')).to.have.lengthOf(1);
});
});
});

Expand Down