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
[DataGrid] Sync date
column value when entering edit mode by pressing a digit
#8364
Conversation
Netlify deploy previewNetlify deploy preview: https://deploy-preview-8364--material-ui-x.netlify.app/ Updated pagesNo updates. These are the results for the performance tests:
|
@@ -98,24 +98,32 @@ function GridEditDateCell(props: GridEditDateCellProps) { | |||
const ownerState = { classes: rootProps.classes }; | |||
const classes = useUtilityClasses(ownerState); | |||
|
|||
const hasUpdatedValueOnRender = React.useRef(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hasUpdatedValueOnRender = React.useRef(false); | |
const hasUpdatedEditValueOnMount = React.useRef(false); |
Would this name better reflect what it's used for?
@@ -145,9 +153,23 @@ function GridEditDateCell(props: GridEditDateCellProps) { | |||
} | |||
}, [hasFocus]); | |||
|
|||
const meta = apiRef.current.unstable_getEditCellMeta(id, field); | |||
|
|||
const handleInputRef = async (el: HTMLInputElement) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const handleInputRef = async (el: HTMLInputElement) => { | |
const handleInputRef = (el: HTMLInputElement) => { |
Fixes #8302
Preview: https://deploy-preview-8364--material-ui-x.netlify.app/x/react-data-grid/editing/#making-a-column-editable
The solution I implemented here was not what I intended to do in #8302 (comment). When a digit key is pressed, we update the input value to be equal to the key pressed. In a
type=date
input, this updates the first date component, which could be the day or month, depending on the locale. Calling the value parser won't work because we don't know the date format (it's defined by the browser) to replace the right date component. The solution used here is a workaround involving callingsetEditCellValue
as soon as the input is rendered and a digit key press was the reason for the cell to enter edit mode.