Skip to content

Commit 6504560

Browse files
committed
feat: [PROD-12032] add error display and helperText to GenericToggleInput
1 parent 49afe5a commit 6504560

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

src/inputs/BasicInputs/BasicToggleInput/BasicToggleInput.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import React from 'react';
55
import PropTypes from 'prop-types';
6-
import { Grid, Stack, Switch, FormControlLabel } from '@mui/material';
6+
import { Grid, Stack, Switch, FormControlLabel, FormHelperText, FormControl } from '@mui/material';
77
import makeStyles from '@mui/styles/makeStyles';
88
import { BasicInputPlaceholder } from '../BasicInputPlaceholder';
99
import { TooltipInfo } from '../../../misc';
@@ -13,7 +13,7 @@ const useStyles = makeStyles(getCommonInputStyles);
1313

1414
export const BasicToggleInput = (props) => {
1515
const classes = useStyles();
16-
const { id, label, tooltipText, value, switchProps, changeSwitchType, isDirty, ...otherProps } = props;
16+
const { id, label, tooltipText, value, switchProps, changeSwitchType, isDirty, error, ...otherProps } = props;
1717

1818
if (switchProps.disabled)
1919
return (
@@ -28,28 +28,25 @@ export const BasicToggleInput = (props) => {
2828

2929
return (
3030
<Grid item xs={3}>
31-
<Stack
32-
data-cy={`toggle-input-${id}`}
33-
direction="row"
34-
spacing={1}
35-
alignItems="center"
36-
className={isDirty ? classes.dirtyInput : classes.notDirtyInput}
37-
>
38-
<FormControlLabel
39-
value="value"
40-
control={
41-
<Switch
42-
color="secondary"
43-
onChange={(event) => changeSwitchType(event.target.checked)}
44-
checked={value}
45-
{...switchProps}
46-
/>
47-
}
48-
label={label}
49-
labelPlacement="end"
50-
/>
51-
<TooltipInfo title={tooltipText} variant="small" />
52-
</Stack>
31+
<FormControl className={isDirty ? classes.dirtyInput : classes.notDirtyInput}>
32+
<Stack data-cy={`toggle-input-${id}`} direction="row" spacing={1} alignItems="center">
33+
<FormControlLabel
34+
value="value"
35+
control={
36+
<Switch
37+
color="secondary"
38+
onChange={(event) => changeSwitchType(event.target.checked)}
39+
checked={value}
40+
{...switchProps}
41+
/>
42+
}
43+
label={label}
44+
labelPlacement="end"
45+
/>
46+
<TooltipInfo title={tooltipText} variant="small" />
47+
</Stack>
48+
<FormHelperText error={error?.message?.length > 0}>{error?.message ?? ''}</FormHelperText>
49+
</FormControl>
5350
</Grid>
5451
);
5552
};
@@ -83,6 +80,10 @@ BasicToggleInput.propTypes = {
8380
* Boolean value that defines whether the input has been modified or not; if true, a special css class is applied.
8481
*/
8582
isDirty: PropTypes.bool,
83+
/**
84+
* Error object that contains the type of error and its message
85+
*/
86+
error: PropTypes.object,
8687
};
8788
BasicToggleInput.defaultProps = {
8889
isDirty: false,

0 commit comments

Comments
 (0)