-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[data grid] Pressing Delete
key in a Boolean type cell, the value incorrectly resets to empty string
#12125
Comments
Hey @mororyou and thanks for raising this. I did play around with it a bit and found an easy way to fix this for diff --git a/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts b/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts
index 25c7cfdb5..3108844a7 100644
--- a/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts
+++ b/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts
@@ -329,8 +329,24 @@ export const useGridCellEditing = (
const { id, field, deleteValue, initialValue } = params;
let newValue = apiRef.current.getCellValue(id, field);
- if (deleteValue || initialValue) {
- newValue = deleteValue ? '' : initialValue;
+
+ if (deleteValue) {
+ const fieldType = apiRef.current.getColumn(field).type;
+ switch (fieldType) {
+ case 'boolean':
+ newValue = false;
+ break;
+ case 'date':
+ case 'dateTime':
+ case 'number':
+ newValue = undefined;
+ break;
+ case 'singleSelect':
+ case 'string':
+ default:
+ newValue = '';
+ break;
+ }
+ } else if (initialValue) {
+ newValue = initialValue;
}
const newProps = { It would be beneficial if we could add a test or two as well to prevent regressions. Thanks again for reporting it! 🙇🏼 |
Delete
key in a Boolean type cell, the value incorrectly resets to empty string
hi @michelengelen, can I work on this issue? Kindly assign it to me! 🙏 |
+ case 'singleSelect':
+ case 'string':
+ default:
+ newValue = '';
+ break; For singleSelect, is it also intended to fallback into empty string? |
I've been thinking about the suggestion to set the singleSelect field's value to an empty string ('') upon a delete key event. From what I've gathered, it might enhance user experience to more explicitly indicate a 'no selection' state with Since I'm new and still learning about the project's data handling, I would greatly appreciate any additional insights on this matter. 😊 |
That sounds about right. I just left it as an empty string because the previous implementation was using it as well ... if (deleteValue || initialValue) {
newValue = deleteValue ? '' : initialValue;
... I would be fine with |
How did we do @mororyou? |
Steps to reproduce
Link to live example: https://codesandbox.io/p/github/mororyou/mui-datagrid-test/main
To open Developer Tools
Hover over the cells in the isAdmin column.
To delete, use the Delete key or the Backspace key.
Check the Console in Developer Tools.
You can confirm in the console that the value of valueSetter's params is an empty string.
Also, I'll attach a screenshot for reference.
https://gyazo.com/787beae18b71f4366be716d654a6cf50
Current behavior
I was expecting to receive a Boolean, but an empty string is being sent.
Expected behavior
Can we change the Boolen value so that it can be retrieved?
Context
No response
Your environment
npx @mui/envinfo
Search keywords: DataGrid, valueSetter
Order ID: 67619
The text was updated successfully, but these errors were encountered: