[DataGrid] Improve API to control cell editing through custom components #1824
Labels
component: data grid
This is the name of the generic UI component, not the React module!
new feature
New feature or request
Summary 馃挕
While I was creating the components for #1817 I had some problems with the cell editing API. I'm listing all of them here because I think it demands work in this entire API and not just in a particular method.
Inconsistencies on how to save values - I first raised this in [DataGrid] Add
valueParser
to parse values entered by the user聽#1785 (comment) but I faced the same problem in [docs] Make cell editable in demos聽#1817. We have different components using different APIs to do the same thing. Officially, users should usecommitCellChange
but this same method has its problems. Which API both us and developers should use to create custom edit components?GridEditInputCell
andGridEditBooleanCell
publish theGRID_CELL_EDIT_PROPS_CHANGE
eventValidateServerNameGrid
demo callssetEditCellProps
commitCellChange
.Calling
commitCellChange
withoutsetCellMode
reverts the value when clicking outside the cell - Open this CodeSandbox, change a value in the favorite color column and click outside the cell to save. It reverts to the original value, but it shouldn't. The reason to not callsetCellMode
would be if I want to stay in the edit mode after selecting a value (e.g. a Slider).Keyboard support? - Open this CodeSandbox and select a new value for a cell of the favorite color column with the keyboard. When Enter is pressed it doesn't change to the view mode, even using
setCellMode
. In [docs] Make cell editable in demos聽#1817 I had to callsetEditCellProps
when the value is selected through the keyboard.Components that use a backdrop - Since I changed in [DataGrid] Add support for edit components that use portal聽#1772 to relay in the click, instead of blur, we now have a new problem. If a component has a backdrop, clicking "outside" it doesn't exit from the edit mode because for us the click was inside it. That being said, we should provide a new API so users can handle the outside click themselves. That means publishing
GRID_CELL_EDIT_PROPS_CHANGE_COMMITTED
andGRID_CELL_EDIT_EXIT
.https://github.com/mui-org/material-ui-x/blob/b1aac5cd14d3e5bba44cdc612dcf35a78c0a50d8/packages/grid/_modules_/grid/hooks/features/rows/useGridEditRows.ts#L65-L71
The text was updated successfully, but these errors were encountered: