-
Notifications
You must be signed in to change notification settings - Fork 295
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
Conversation
🦋 Changeset detectedLatest commit: 46a2b01 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
packages/ui/components/input-datepicker/test/lion-input-datepicker.test.js
Outdated
Show resolved
Hide resolved
Please add a changeset |
Just in case you want to avoid using 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(),
);
}); |
I approved the pr 🥳 Do you not forget the changeset, to squash all commits and use a commit message like |
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
norawait el.{internal_node_getter}.completeUpdate
didn't work because the date picker waits for its child node to be updated before it callsthis._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.