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

[Grid] Prevent crash if spacing is set to zero in theme #33777

Merged
merged 7 commits into from Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 22 additions & 3 deletions docs/data/material/customization/density/DensityTool.js
Expand Up @@ -25,9 +25,20 @@ export default function DensityTool() {
};

const handleSpacingChange = (event, value) => {
let spacing = value || +event.target.value;

// If the entered value is greater than maxSpacing, setting up maxSpacing as value
if (spacing > maxSpacing) {
spacing = maxSpacing;
}
// If the entered value is less than minSpacing, setting up minSpacing as value
else if (spacing < minSpacing) {
spacing = minSpacing;
}
PunitSoniME marked this conversation as resolved.
Show resolved Hide resolved

dispatch({
type: 'SET_SPACING',
payload: value || +event.target.value,
payload: spacing,
});
};

Expand Down Expand Up @@ -71,7 +82,11 @@ export default function DensityTool() {
</Typography>
</Grid>
<Grid item>
<IconButton aria-label={t('increaseSpacing')} onClick={decreaseSpacing}>
<IconButton
aria-label={t('increaseSpacing')}
PunitSoniME marked this conversation as resolved.
Show resolved Hide resolved
onClick={decreaseSpacing}
disabled={spacingUnit === minSpacing}
>
<DecreaseIcon />
</IconButton>
<Input
Expand All @@ -86,7 +101,11 @@ export default function DensityTool() {
'aria-labelledby': 'input-slider',
}}
/>
<IconButton aria-label={t('decreaseSpacing')} onClick={increaseSpacing}>
<IconButton
aria-label={t('decreaseSpacing')}
PunitSoniME marked this conversation as resolved.
Show resolved Hide resolved
onClick={increaseSpacing}
disabled={spacingUnit === maxSpacing}
>
<IncreaseIcon />
</IconButton>
</Grid>
Expand Down
6 changes: 4 additions & 2 deletions packages/mui-material/src/Grid/Grid.js
Expand Up @@ -181,7 +181,8 @@ export function generateRowGap({ theme, ownerState }) {
};
}

if (zeroValueBreakpointKeys.includes(breakpoint)) {
// Issue - #33771 - Code crashes from Demo DensityTool screen when we set it 0
PunitSoniME marked this conversation as resolved.
Show resolved Hide resolved
PunitSoniME marked this conversation as resolved.
Show resolved Hide resolved
if (zeroValueBreakpointKeys && zeroValueBreakpointKeys.includes(breakpoint)) {
PunitSoniME marked this conversation as resolved.
Show resolved Hide resolved
return {};
}

Expand Down Expand Up @@ -227,7 +228,8 @@ export function generateColumnGap({ theme, ownerState }) {
};
}

if (zeroValueBreakpointKeys.includes(breakpoint)) {
// Issue - #33771 - Code crashes from Demo DensityTool screen when we set it 0
if (zeroValueBreakpointKeys && zeroValueBreakpointKeys.includes(breakpoint)) {
PunitSoniME marked this conversation as resolved.
Show resolved Hide resolved
return {};
}

Expand Down