-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIMSBIOHUB 335: Tab Through Observation Edit (#1156)
* Modified each custom renderEditCell component of the ObservationTable to manually set hasFocus. This allows the user to Tab forward to the next cell or Shift+Tab back to the previous. * Wrapped some of the simpler TextField / DatePicker renders in their own functional components so that the same hasFocus pattern could be used.
- Loading branch information
1 parent
aefe64f
commit c882b79
Showing
6 changed files
with
148 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import TextField, { TextFieldProps } from '@mui/material/TextField/TextField'; | ||
import useEnhancedEffect from '@mui/material/utils/useEnhancedEffect'; | ||
import { GridRenderEditCellParams, GridValidRowModel } from '@mui/x-data-grid'; | ||
import { useRef } from 'react'; | ||
|
||
interface ITextFieldCustomValidation<DataGridType extends GridValidRowModel> { | ||
textFieldProps: TextFieldProps; | ||
dataGridProps: GridRenderEditCellParams<DataGridType>; | ||
} | ||
|
||
const TextFieldDataGrid = <DataGridType extends GridValidRowModel>({ | ||
textFieldProps, | ||
dataGridProps | ||
}: ITextFieldCustomValidation<DataGridType>) => { | ||
const ref = useRef<HTMLInputElement>(); | ||
useEnhancedEffect(() => { | ||
if (dataGridProps.hasFocus) { | ||
ref.current?.focus(); | ||
} | ||
}, [dataGridProps.hasFocus]); | ||
return ( | ||
<TextField | ||
inputRef={ref} | ||
value={dataGridProps.value ?? ''} | ||
variant="outlined" | ||
type="text" | ||
inputProps={{ inputMode: 'numeric' }} | ||
{...textFieldProps} | ||
/> | ||
); | ||
}; | ||
|
||
export default TextFieldDataGrid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import useEnhancedEffect from '@mui/material/utils/useEnhancedEffect'; | ||
import { GridRenderEditCellParams, GridValidRowModel, useGridApiContext } from '@mui/x-data-grid'; | ||
import { LocalizationProvider, TimePicker, TimePickerProps } from '@mui/x-date-pickers'; | ||
import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment'; | ||
import moment from 'moment'; | ||
import { useRef } from 'react'; | ||
|
||
interface ITimePickerDataGridProps<DataGridType extends GridValidRowModel> { | ||
dateFieldProps?: TimePickerProps<any>; | ||
dataGridProps: GridRenderEditCellParams<DataGridType>; | ||
} | ||
|
||
const TimePickerDataGrid = <DataGridType extends GridValidRowModel>({ | ||
dateFieldProps, | ||
dataGridProps | ||
}: ITimePickerDataGridProps<DataGridType>) => { | ||
const apiRef = useGridApiContext(); | ||
const ref = useRef<HTMLInputElement>(null); | ||
useEnhancedEffect(() => { | ||
if (dataGridProps.hasFocus) { | ||
ref.current?.focus(); | ||
} | ||
}, [dataGridProps.hasFocus]); | ||
return ( | ||
<LocalizationProvider dateAdapter={AdapterMoment}> | ||
<TimePicker | ||
inputRef={ref} | ||
value={(dataGridProps.value && moment(dataGridProps.value, 'HH:mm:ss')) || null} | ||
onChange={(value) => { | ||
apiRef?.current.setEditCellValue({ id: dataGridProps.id, field: dataGridProps.field, value: value }); | ||
}} | ||
onAccept={(value) => { | ||
apiRef?.current.setEditCellValue({ | ||
id: dataGridProps.id, | ||
field: dataGridProps.field, | ||
value: value?.format('HH:mm:ss') | ||
}); | ||
}} | ||
views={['hours', 'minutes', 'seconds']} | ||
timeSteps={{ hours: 1, minutes: 1, seconds: 1 }} | ||
ampm={false} | ||
{...dateFieldProps} | ||
/> | ||
</LocalizationProvider> | ||
); | ||
}; | ||
|
||
export default TimePickerDataGrid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters