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(editor): new Date Editor input clear button wasn't working #1487

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/common/src/editors/__tests__/dateEditor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ describe('DateEditor', () => {
editor.calendarInstance!.actions!.clickDay!(new MouseEvent('click'), { HTMLInputElement: editorInputElm, selectedDates: [] } as unknown as VanillaCalendar);
editor.calendarInstance!.actions!.changeToInput!(new MouseEvent('click'), { HTMLInputElement: editorInputElm, selectedDates: [], hide: jest.fn() } as unknown as VanillaCalendar);

expect(editor.calendarInstance?.settings.selected.dates).toEqual([]);
expect(editorInputElm.value).toBe('');
expect(editor.isValueChanged()).toBe(true);
expect(editor.isValueTouched()).toBe(true);
Expand All @@ -298,6 +299,7 @@ describe('DateEditor', () => {
clearBtnElm.click();

expect(editorInputElm.value).toBe('');
expect(editor.calendarInstance?.settings.selected.dates).toEqual([]);
expect(editor.isValueChanged()).toBe(true);
expect(editor.isValueTouched()).toBe(true);
});
Expand Down
13 changes: 12 additions & 1 deletion packages/common/src/editors/dateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export class DateEditor implements Editor {
if (!(this.columnEditor.editorOptions as any)?.hideClearButton) {
closeButtonGroupElm.appendChild(this._clearButtonElm);
this._editorInputGroupElm.appendChild(closeButtonGroupElm);
this._bindEventService.bind(this._clearButtonElm, 'click', () => this._lastTriggeredByClearDate = true);
this._bindEventService.bind(this._clearButtonElm, 'click', () => {
this.clear();
this.handleOnDateChange();
});
}

setTimeout(() => {
Expand Down Expand Up @@ -230,6 +233,14 @@ export class DateEditor implements Editor {
this._inputElm?.remove();
}

clear() {
this._lastTriggeredByClearDate = true;
if (this.calendarInstance) {
this.calendarInstance.settings.selected.dates = [];
this._inputElm.value = '';
}
}

disable(isDisabled = true) {
const prevIsDisabled = this.disabled;
this.disabled = isDisabled;
Expand Down
Loading