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

viewMode: 'clock' defaults to date view if date components are not deactived #2583

Closed
cdubz opened this issue Jun 8, 2022 · 5 comments
Closed

Comments

@cdubz
Copy link

cdubz commented Jun 8, 2022

I'm hoping to have a picker that supports all the default time and date components but that opens to the clock view mode initially. If I set the picker options as simply --

{ display: { viewMode: 'clock' } }

the picker opens in the default calendar view mode expect that toggles are reversed (i.e., the calendar toggle has a calendar icon and the label is "Select Date" and when I change to the time selector the toggle is a clock icon and the label is "Select Time").

The clock view mode works as expected if the date components are disabled (though I think this is just the default behavior).

@cdubz
Copy link
Author

cdubz commented Jun 8, 2022

Doing a little digging around... this seems to be cause, at least in part, by this logic during configuration initialization:

// Update view mode if needed
if (
CalendarModes[this.optionsStore.currentCalendarViewMode].name !==
newConfig.display.viewMode
) {
this.optionsStore.currentCalendarViewMode = Math.max(
CalendarModes.findIndex((x) => x.name === newConfig.display.viewMode),
this.optionsStore.minimumCalendarViewMode
);
}

In my use case CalendarModes[this.optionsStore.currentCalendarViewMode].name would be the default calendar and newConfig.display.viewMode would be clock.

CalendarModes does not have a clock entry:

const CalendarModes: {
name: keyof ViewMode;
className: string;
unit: Unit;
step: number;
}[] = [
{
name: 'calendar',
className: Namespace.css.daysContainer,
unit: Unit.month,
step: 1,
},
{
name: 'months',
className: Namespace.css.monthsContainer,
unit: Unit.year,
step: 1,
},
{
name: 'years',
className: Namespace.css.yearsContainer,
unit: Unit.year,
step: 10,
},
{
name: 'decades',
className: Namespace.css.decadesContainer,
unit: Unit.year,
step: 100,
},
];

So the result of the Math.max operation above ends up being the default this.optionsStore.minimumCalendarViewMode (0 = calendar).

It doesn't seem like it would make sense to just add clock to CalendarModes so maybe some special handling is needed in the config initialization conditional?

@cdubz
Copy link
Author

cdubz commented Jun 8, 2022

It seems the configuration initialization process is not at fault/relevant here -- #2584 instead fixes the issue by incorporating a check of the options in the show event where there is already special logic for handling the "clock only" use case.

@Eonasdan
Copy link
Owner

Eonasdan commented Jun 8, 2022

This is a bug that I have pending code to fix.

@cdubz
Copy link
Author

cdubz commented Jun 8, 2022

Ok -- feel free to scrap that PR. Thanks!

Eonasdan added a commit that referenced this issue Jun 10, 2022
@Eonasdan
Copy link
Owner

Eonasdan commented Jun 10, 2022

Hi, please check the latest version. Thanks for your PR btw.

Eonasdan added a commit that referenced this issue Jul 11, 2022
* make viewMode optional (#2551)

* introduce a simple overridable function parseInput (#2552)

so that you don't have to know all the internal details when overriding
this just gets 1 input and can return another
Just as formatInput also works (its the opposite)

* fixed #2487, #2495

* fixed #2487, #2495

* fix for #2506

* fix for #2549

* fix for #2549

* pub npm

* pub npm

* package update

* * added locale from pr
* updated github templates
* updated link nav

* fixes #2583, #2578

* [IMP] adding support for Arabic locales (#2592)

* Add display.theme option to control dark/light mode (#2593)

* adding display.theme to control dark vs light mode

* removing changes in dist folder per contribution guidelines

* fixes #2547

* upstream

* fixing bug where side-by-side shows blank clock (#2596) (#2597)

* fix clock

* fix #2595

* fix #2563
fix #2563

* fix #2599

* fix #2576

* issue templates to forms

* fixes #2568

* nuget package

* fix spelling and oops

* remove commented out code

Co-authored-by: Johan Compagner <[email protected]>
Co-authored-by: Khaled Said <[email protected]>
Co-authored-by: Killian Hale <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants