Skip to content
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] Fix DatePicker bug by limiting years to 4 digits #3222

Merged
merged 5 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export function GridEditDateCell(props: GridRenderEditCellParams & InputBaseProp
fullWidth
className={classes.root}
type={isDateTime ? 'datetime-local' : 'date'}
inputProps={{
max: isDateTime ? '9999-12-31T23:59' : '9999-12-31',
m4theushw marked this conversation as resolved.
Show resolved Hide resolved
}}
value={valueState.formatted}
onChange={handleChange}
{...other}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type GridFilterInputDateProps = GridFilterInputValueProps &
export const SUBMIT_FILTER_DATE_STROKE_TIME = 500;

function GridFilterInputDate(props: GridFilterInputDateProps) {
const { item, applyValue, type, apiRef, focusElementRef, ...other } = props;
const { item, applyValue, type, apiRef, focusElementRef, inputProps, ...other } = props;

const filterTimeout = React.useRef<any>();
const [filterValueState, setFilterValueState] = React.useState(item.value ?? '');
Expand Down Expand Up @@ -47,7 +47,10 @@ function GridFilterInputDate(props: GridFilterInputDateProps) {

const InputProps = {
...(applying ? { endAdornment: <GridLoadIcon /> } : {}),
max: type === 'datetime-local' ? '9999-12-31T23:59' : '9999-12-31',
inputProps: {
max: type === 'datetime-local' ? '9999-12-31T23:59' : '9999-12-31',
...inputProps,
Copy link
Member

@m4theushw m4theushw Nov 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter input is based on the TextField so users expect that the props will be forwarded to the root component.

Here you're spreading the top-level inputProps inside InputProps. It's like:

<GridFilterInputDate inputProps={{ min: '...' }} />
-> <TextField InputProps={{ inputProps: { min: '...' } }} /> (this PR)
-> <TextField inputProps={{ min: '...' }} /> (how it should behave)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree, but Eslint do not agree with us and complains about duplicate props.
I made some research to find other solutions, but it seems core team recommends it mui/material-ui#10064 (comment)

},
...other.InputProps,
};

Expand Down