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

[DatePicker] Can't see date view for the month in which all the dates are disabled with shouldDisableDate #4917

Closed
2 tasks done
NikitaGimon opened this issue May 17, 2022 · 2 comments
Labels
component: DatePicker The React component. component: pickers This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@NikitaGimon
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

The user selects the month/year with all dates disabled in this month/year and material ui redirects the user to the "date" view with the closest enabled date.

I have enabled dates:
image

I click on the datepicker:
image

I want to change the date to see even disabled dates in 2019 year
image

I click on 2019 year and I'm redirected to the closest enabled 2020-09-30
image

Code:
`
export const SnapshotDatePicker = ({handleCloseDialog, snapshotDatesList, changeSnapshotDate}) => {
const [date, changeDate] = useState(new Date());

const disableDates = date => {
	const mappesSnapshotList = snapshotDatesList.map(el => el.snapshotDate);
	return !mappesSnapshotList.includes(formatDateAPI(date));
};

const handleChangeDate = () => {
	const formattedDate = formatDateAPI(date);
	if (formattedDate === formatDateAPI(date)) {
		changeSnapshotDate(snapshotDatesList.find(el => el.snapshotDate === formattedDate)?.snapshotDate);
		handleCloseDialog();
	}
};

return (
	<Dialog open={true} onClose={handleCloseDialog}>
		<DialogTitleContainer>
			Choose Snapshot <CrossIcon onClick={handleCloseDialog} />
		</DialogTitleContainer>
		<DatePickerContainer>
			<MuiPickersUtilsProvider utils={DateFnsUtils}>
				<ThemeProvider theme={materialTheme}>
					<DatePicker
						variant="static"
						shouldDisableDate={disableDates}
						openTo="date"
						value={date}
						views={['year', 'month', 'date']}
						onChange={e => {
							changeDate(e);
						}}
					/>
				</ThemeProvider>
			</MuiPickersUtilsProvider>
		</DatePickerContainer>
		<DialogActionsStyled>
			<ButtonCancel onClick={handleCloseDialog} type="button">
				Cancel
			</ButtonCancel>
			<ButtonConfirm onClick={() => handleChangeDate()} type="submit">
				Confirm
			</ButtonConfirm>
		</DialogActionsStyled>
	</Dialog>
);

};

SnapshotDatePicker.propTypes = {
snapshotDatesList: PropTypes.array,
handleCloseDialog: PropTypes.func,
changeSnapshotDate: PropTypes.func,
};
`

Expected behavior 🤔

Want to see date view also for disabled dates. Click on 2019 and see 2019 dates even if they are disabled

Steps to reproduce 🕹

Steps:

  1. Import DatePicker
  2. Disable all dates from the chosen month
  3. Try to see this month as a date view choosing year
  4. You will be redirected to the date view with the available (not disabled) date

Context 🔦

We need to create a Datepicker to choose the date from an array of available dates. The rest of the dates (which are not in this array of available) need to be disabled.

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
@NikitaGimon NikitaGimon added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 17, 2022
@mnajdova mnajdova transferred this issue from mui/material-ui May 17, 2022
@flaviendelangle
Copy link
Member

Hi

This relates to #4814 and #4834

You should be able to disable the month / year entirely in the month / year pickers with the props shouldDisableMonth and shouldDisableYear.

And in #4814 we will improve the default behaviors when shouldDisableMonth is not provided and all days within the targets month are disabled. We will show the target month but without changing the selected date (same for years).
This behavior is touchy so we are taking some time to make sure everything is working fine.

I hope it will solve your problem.

@flaviendelangle flaviendelangle added new feature New feature or request component: pickers This is the name of the generic UI component, not the React module! component: DatePicker The React component. and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 17, 2022
@flaviendelangle flaviendelangle changed the title DatePicker issue. Can't see date view for the month in which all the dates are disabled with shouldDisableDate [DatePicker] Can't see date view for the month in which all the dates are disabled with shouldDisableDate May 17, 2022
@flaviendelangle
Copy link
Member

Closing this one
Fixed by #4814

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: DatePicker The React component. component: pickers This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants