Skip to content

Commit e1afa50

Browse files
csm-thunborde-CSM
andcommitted
feat: [PROD-11209] add optional tooltip for each option in BasicEnumInput
Co-authored-by: Nicolas Borde <nicolas.borde@cosmotech.com>
1 parent 9a4d626 commit e1afa50

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/inputs/BasicInputs/BasicEnumInput/BasicEnumInput.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Cosmo Tech.
22
// Licensed under the MIT license.
33

4-
import { MenuItem, Grid, Stack, TextField } from '@mui/material';
4+
import { MenuItem, Grid, Stack, TextField, Tooltip, Fade, Box } from '@mui/material';
55
import makeStyles from '@mui/styles/makeStyles';
66
import PropTypes from 'prop-types';
77
import React from 'react';
@@ -42,13 +42,34 @@ export const BasicEnumInput = (props) => {
4242
sx={{ flexGrow: 1 }}
4343
select
4444
value={value}
45-
onChange={(event) => {
46-
return changeEnumField(event.target.value);
45+
SelectProps={{
46+
renderValue: (value) => <Box>{value}</Box>, // Prevent extra padding on selected value
47+
'data-cy': `enum-input-select-${id}`,
48+
MenuProps: { 'data-cy': `enum-input-menu-${id}` },
4749
}}
50+
onChange={(event) => changeEnumField(event.target.value)}
4851
>
4952
{enumValues.map((option) => (
50-
<MenuItem key={option.key} value={option.key} data-cy={option.key}>
51-
{option.value}
53+
<MenuItem
54+
key={option.key}
55+
value={option.key}
56+
data-cy={option.key}
57+
sx={{ p: '0px' }} // Remove default MenuItem padding to increase the hover area for the items tooltips
58+
>
59+
<Tooltip
60+
data-cy={`enum-input-value-tooltip-${option.key}`}
61+
title={option.tooltip}
62+
placement="right-end"
63+
TransitionComponent={Fade}
64+
TransitionProps={{ timeout: 600 }}
65+
>
66+
<Box
67+
// Extra padding on menu items to increase the hover area for the items tooltips
68+
sx={{ px: '16px', py: '6px', width: '100%' }}
69+
>
70+
{option.value}
71+
</Box>
72+
</Tooltip>
5273
</MenuItem>
5374
))}
5475
</TextField>

0 commit comments

Comments
 (0)