Skip to content

Commit

Permalink
fix(date): change date only when previous and selected are both not e…
Browse files Browse the repository at this point in the history
…mpty, null or undefined
  • Loading branch information
mmarinkov committed Sep 13, 2024
1 parent 8502f0a commit bc69750
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/components/bal-date/bal-date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ export class Date implements ComponentInterface, Loggable, BalAriaFormLinking {

private onInputChange = (ev: BalEvents.BalInputDateChange) => {
stopEventBubbling(ev)
if (ev.detail) {
if (!(BalDate.isEmptyDate(ev.detail) && BalDate.isEmptyDate(this.value))) {
this.value = ev.detail
this.balChange.emit(this.value)
}
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/utils/date/date.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,14 @@ describe('balDate', () => {
expect(BalDate.fromISO(date2).isBeforeOrEqual(date1)).toBeFalsy()
})
})
describe('isEmptyDate', () => {
test('should return if date is empty, null or undefined', () => {
const date = BalDate.fromISO('2001-02-01')
expect(BalDate.isEmptyDate(null)).toBeTruthy()
expect(BalDate.isEmptyDate('')).toBeTruthy()
expect(BalDate.isEmptyDate(undefined)).toBeTruthy()
expect(date).toBeFalsy()
})
})
})
})
4 changes: 4 additions & 0 deletions packages/core/src/utils/date/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export class BalDate {
return weekdays
}

public static isEmptyDate(value: any): boolean {
return value === undefined || value === null || value === ''
}

constructor(private dt: DateTime) {}

public get isValid() {
Expand Down

0 comments on commit bc69750

Please sign in to comment.