Skip to content

Commit

Permalink
[ButtonBase] Fix when changing enableRipple prop from false to true (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
dmtrKovalenko authored and EsoterikStare committed Mar 30, 2020
1 parent 60b3f73 commit a54f6c6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api/no-ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ This component can be useful in a variety of situations:

| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name required">children&nbsp;*</span> | <span class="prop-type">node</span> | | You can wrap a node. |
| <span class="prop-name">children</span> | <span class="prop-type">node</span> | | You can wrap a node. |
| <span class="prop-name">defer</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the component will not only prevent server-side rendering. It will also defer the rendering of the children into a different screen frame. |
| <span class="prop-name">fallback</span> | <span class="prop-type">node</span> | <span class="prop-default">null</span> | The fallback content to display. |

Expand Down
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 @@ -304,12 +304,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}
) : null}
</NoSsr>
</ComponentProp>
);
});
Expand Down
48 changes: 48 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,54 @@ 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() {
/** @type {React.MutableRefObject<import('./ButtonBase').ButtonBaseActions | null>} */
const buttonRef = React.useRef(null);
const [enableRipple, setRipple] = React.useState(false);

React.useEffect(() => {
if (buttonRef.current) {
buttonRef.current.focusVisible();
} else {
throw new Error('buttonRef.current must be available');
}
}, []);

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/NoSsr/NoSsr.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

export interface NoSsrProps {
children: React.ReactNode;
children?: React.ReactNode;
defer?: boolean;
fallback?: React.ReactNode;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/NoSsr/NoSsr.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ NoSsr.propTypes = {
/**
* You can wrap a node.
*/
children: PropTypes.node.isRequired,
children: PropTypes.node,
/**
* If `true`, the component will not only prevent server-side rendering.
* It will also defer the rendering of the children into a different screen frame.
Expand Down

0 comments on commit a54f6c6

Please sign in to comment.