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

Fix the issue that dynamically updated disabled date doesn't update the central date #2411

Merged
merged 5 commits into from
Nov 21, 2024

Conversation

ryubro
Copy link
Contributor

@ryubro ryubro commented Nov 15, 2024

What I did

In case the disabled dates of the calendar element in LionInputDatepicker changes dynamically (for instance, when two date pickers take start and end date from user, while start date changes the min value of the end date), the calendar's central date can be a disabled date and it doesn't get updated to the nearest enabled date.

This PR fixes the issue by getting nearest enabled date in case the initial central date becomes disabled.

Caveat

I introduced 10ms timeout in the test. await el.completeUpdate nor await el.{internal_node_getter}.completeUpdate didn't work because the date picker waits for its child node to be updated before it calls this._calendarNode.initCentralDate(). I even tried to wait the calendar node to complete updates multiple times but no luck. Please enlighten me if I can avoid using timeout.

Copy link

changeset-bot bot commented Nov 15, 2024

🦋 Changeset detected

Latest commit: 46a2b01

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lion/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@okadurin
Copy link
Collaborator

Please add a changeset

@okadurin
Copy link
Collaborator

Caveat

Just in case you want to avoid using setTimeout the test could be updated with closeCalendar/openCalendar as follows:

      it('should update the central date of Calendar if updated validator made the current central date disabled', async () => {
        const initialValidators = [new MaxDate(new Date('2000/01/01'))];
        const updatedValidators = [new MaxDate(new Date('2020/01/01'))];

        const el = await fixture(html`
          <lion-input-datepicker .validators="${initialValidators}"></lion-input-datepicker>
        `);
        const elObj = new DatepickerInputObject(el);
        await elObj.openCalendar();
        expect(getProtectedMembersDatepicker(el).calendarNode.centralDate.toString()).to.equal(
          new Date('2000/01/01').toString(),
        );

        await elObj.closeCalendar();
        el.validators = updatedValidators;
        await elObj.openCalendar();
        expect(getProtectedMembersDatepicker(el).calendarNode.centralDate.toString()).to.equal(
          new Date('2020/01/01').toString(),
        );
      });

@tlouisse
Copy link
Member

I approved the pr 🥳 Do you not forget the changeset, to squash all commits and use a commit message like fix(calendar): align central date with dynamic disabled dates?

@ryubro ryubro merged commit a51e28d into master Nov 21, 2024
7 checks passed
@ryubro ryubro deleted the fix/datepicker-central-date-issue branch November 21, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants