Skip to content

Commit

Permalink
[lab][LoadingButton] Apply wrapping element to prevent React crash on…
Browse files Browse the repository at this point in the history
… Google page translation (mui#35198)

Co-authored-by: Aarón García Hervás <[email protected]>
  • Loading branch information
BartJanvanAssen and aarongarciah authored Jun 14, 2024
1 parent d32a8ce commit b51fd5d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function LoadingButtonsTransition() {
variant="outlined"
disabled
>
<span>disabled</span>
Disabled
</LoadingButton>
<LoadingButton
size="small"
Expand All @@ -43,7 +43,7 @@ export default function LoadingButtonsTransition() {
loadingIndicator="Loading…"
variant="outlined"
>
<span>Fetch data</span>
Fetch data
</LoadingButton>
<LoadingButton
size="small"
Expand All @@ -53,7 +53,7 @@ export default function LoadingButtonsTransition() {
loadingPosition="end"
variant="contained"
>
<span>Send</span>
Send
</LoadingButton>
<LoadingButton
size="small"
Expand All @@ -64,7 +64,7 @@ export default function LoadingButtonsTransition() {
startIcon={<SaveIcon />}
variant="contained"
>
<span>Save</span>
Save
</LoadingButton>
</Box>
<Box sx={{ '& > button': { m: 1 } }}>
Expand All @@ -74,15 +74,15 @@ export default function LoadingButtonsTransition() {
variant="outlined"
disabled
>
<span>disabled</span>
Disabled
</LoadingButton>
<LoadingButton
onClick={handleClick}
loading={loading}
loadingIndicator="Loading…"
variant="outlined"
>
<span>Fetch data</span>
Fetch data
</LoadingButton>
<LoadingButton
onClick={handleClick}
Expand All @@ -91,7 +91,7 @@ export default function LoadingButtonsTransition() {
loadingPosition="end"
variant="contained"
>
<span>Send</span>
Send
</LoadingButton>
<LoadingButton
color="secondary"
Expand All @@ -101,7 +101,7 @@ export default function LoadingButtonsTransition() {
startIcon={<SaveIcon />}
variant="contained"
>
<span>Save</span>
Save
</LoadingButton>
</Box>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function LoadingButtonsTransition() {
variant="outlined"
disabled
>
<span>disabled</span>
Disabled
</LoadingButton>
<LoadingButton
size="small"
Expand All @@ -43,7 +43,7 @@ export default function LoadingButtonsTransition() {
loadingIndicator="Loading…"
variant="outlined"
>
<span>Fetch data</span>
Fetch data
</LoadingButton>
<LoadingButton
size="small"
Expand All @@ -53,7 +53,7 @@ export default function LoadingButtonsTransition() {
loadingPosition="end"
variant="contained"
>
<span>Send</span>
Send
</LoadingButton>
<LoadingButton
size="small"
Expand All @@ -64,7 +64,7 @@ export default function LoadingButtonsTransition() {
startIcon={<SaveIcon />}
variant="contained"
>
<span>Save</span>
Save
</LoadingButton>
</Box>
<Box sx={{ '& > button': { m: 1 } }}>
Expand All @@ -74,15 +74,15 @@ export default function LoadingButtonsTransition() {
variant="outlined"
disabled
>
<span>disabled</span>
Disabled
</LoadingButton>
<LoadingButton
onClick={handleClick}
loading={loading}
loadingIndicator="Loading…"
variant="outlined"
>
<span>Fetch data</span>
Fetch data
</LoadingButton>
<LoadingButton
onClick={handleClick}
Expand All @@ -91,7 +91,7 @@ export default function LoadingButtonsTransition() {
loadingPosition="end"
variant="contained"
>
<span>Send</span>
Send
</LoadingButton>
<LoadingButton
color="secondary"
Expand All @@ -101,7 +101,7 @@ export default function LoadingButtonsTransition() {
startIcon={<SaveIcon />}
variant="contained"
>
<span>Save</span>
Save
</LoadingButton>
</Box>
</div>
Expand Down
11 changes: 0 additions & 11 deletions docs/data/material/components/buttons/buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,3 @@ This has the advantage of supporting any element, for instance, a link `<a>` ele
Toggle the loading switch to see the transition between the different states.

{{"demo": "LoadingButtonsTransition.js"}}

:::warning
There is a [known issue](https://github.com/mui/material-ui/issues/27853) with translating a page using Chrome tools when a Loading Button is present.
After the page is translated, the application crashes when the loading state of a Button changes.
To prevent this, ensure that the contents of the Loading Button are nested inside any HTML element, such as a `<span>`:

```jsx
<LoadingButton loading variant="outlined">
<span>Submit</span>
</LoadingButton>
```
6 changes: 6 additions & 0 deletions docs/data/material/migration/migration-v5/migration-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,9 @@ Both of these changes might slightly affect your layout.
Note that the items' position doesn't change.
We recommend adopting this new behavior and **not trying to replicate the old one**, as this is a more predictable and modern approach.
:::

### LoadingButton

#### Contents wrapped in a <span>

The `children` passed to the LoadingButton component is now wrapped in a `<span>` tag to avoid [issues](https://github.com/mui/material-ui/issues/27853) when using tools to translate websites.
13 changes: 11 additions & 2 deletions packages/mui-lab/src/LoadingButton/LoadingButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,17 @@ const LoadingButton = React.forwardRef(function LoadingButton(inProps, ref) {
classes={classes}
ownerState={ownerState}
>
{ownerState.loadingPosition === 'end' ? children : loadingButtonLoadingIndicator}
{ownerState.loadingPosition === 'end' ? loadingButtonLoadingIndicator : children}
{ownerState.loadingPosition === 'end' ? (
<span>{children}</span>
) : (
loadingButtonLoadingIndicator
)}

{ownerState.loadingPosition === 'end' ? (
loadingButtonLoadingIndicator
) : (
<span>{children}</span>
)}
</LoadingButtonRoot>
);
});
Expand Down

0 comments on commit b51fd5d

Please sign in to comment.