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

[Bug] No switching from day view to week view on resize #231

Open
lukasz-fi opened this issue Jan 10, 2024 · 5 comments
Open

[Bug] No switching from day view to week view on resize #231

lukasz-fi opened this issue Jan 10, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@lukasz-fi
Copy link

Context (REQUIRED):

  • Browser: Chrome
  • Browserversion: 120.0.6099.199
  • Qalendar Version: v3.7.0

Describe the bug (REQUIRED)

On web browser resize the calendar doesn't switch back to week mode after it once has switched to day mode.

To Reproduce

Steps to reproduce the behavior:

  1. Set the calendar to week mode (per defaultMode)
  2. Resize the web browser to 700px (or less) width, so that it switches to day view mode.
  3. Resize the web browser above 700px width.

Expected behavior

After the resize the calendar should switch back to week mode.

@abdul737
Copy link

I guess it's because of design considerations, since the week mode won't look good on smaller screens

@lukasz-fi
Copy link
Author

That has nothing to do with small screens/resolutions, the issue exists on regular screens.
Resize web browser to a small window (below 700px) and resize it back to e.g. 4000px it is still in day view mode.
This issue is especially problematic if the calendar is inside a container that has a transition, because then the calendar starts in day view mode and gets stuck in it even after the transition finishes. Example: Put the calendar in a v-tab (Vuetify).

@abdul737
Copy link

@lukasz-fi Sorry I misunderstood you

@Bl00D4NGEL
Copy link

The issue seems to be that while the check for "is small screen" does work and is ran on window resize this.mode is only overwritten to day whenever the this.mode is neither day or month. Therefore once a calendar is considered to be in "day mode" because the screen size is small the resizing listener will not go from day or month mode to week mode.

The "easiest" fix would be to switch from day to week mode once the screen is big enough, however this could be irritating for a user if they intentionally selected the day mode on a bigger screen and resize from "big enough" to "small enough" to "big enough".

A better approach would be to keep track of whether the user changed their mode manually. If the user did not manually change the mode we should be "safe" to change the mode from day to week. If the user did change the mode manually we should not do anything.
This could be achieved by removing the resize event listener when the mode is set via handleChangeMode and rewriting the mode setting logic from just

if (this.isSmall && !['day', 'month'].includes(this.mode)) {
  this.mode = 'day';
}

to something like

if (this.isSmall) {
  if (!['day', 'month'].includes(this.mode)) {
    this.mode = 'day';
  }
} else {
  if (!['week', 'month'].includes(this.mode)) {
    this.mode = 'week';
  }
}

@tomosterlund I'd be willing to attempt to submit a PR with a fix for this if you would point me in the right direction (or validate that either of my approaches would work).

@tomosterlund tomosterlund added the bug Something isn't working label Feb 23, 2024
@tomosterlund
Copy link
Owner

tomosterlund commented Feb 23, 2024

Hi. Since week is the default view this would make sense.

I'd be open to have a look at a PR with this change. My guess is you've actually coded the full solution here in your last comment already. Additionally, but optionally I'd say, you could write a unit test for this in tests/unit/components/Qalendar.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants