Skip to content

Commit 54b66b4

Browse files
committed
feat(DatePicker, DateRangePicker): add inputOnChangeDelay option with 750ms default
- Implement debounced input handling for manual date entry - Add configurable delay to prevent excessive updates while typing - Include timeout cleanup in dispose method for memory management - Update documentation with new option details
1 parent 658e345 commit 54b66b4

File tree

3 files changed

+46
-20
lines changed

3 files changed

+46
-20
lines changed

docs/content/forms/date-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ const datePickerList = datePickerElementList.map(datePickerEl => {
393393
| `indicator` | boolean | `true` | Toggle visibility or set the content of the input indicator. |
394394
| `inputDateFormat` | function, null | `null` | Custom function to format the selected date into a string according to a custom format. |
395395
| `inputDateParse` | function, null | `null` | Custom function to parse the input value into a valid Date object. |
396+
| `inputOnChangeDelay` | number | `750` | Delay in milliseconds before processing manual date input changes. |
396397
| `inputReadOnly` | boolean | `false` | Toggle the readonly state for the component. |
397398
| `invalid` | boolean | `false` | Toggle the invalid state for the component. |
398399
| `locale` | string | `'default'` | Sets the default locale for components. If not set, it is inherited from the navigator.language. |

docs/content/forms/date-range-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ const dateRangePickerList = dateRangePickerElementList.map(dateRangePickerEl =>
446446
| `indicator` | boolean | `true` | Toggle visibility or set the content of the input indicator. |
447447
| `inputDateFormat` | function, null | `null` | Custom function to format the selected date into a string according to a custom format. |
448448
| `inputDateParse` | function, null | `null` | Custom function to parse the input value into a valid Date object. |
449+
| `inputOnChangeDelay` | number | `750` | Delay in milliseconds before processing manual date input changes. |
449450
| `inputReadOnly` | boolean | `false` | Toggle the readonly state for the component. |
450451
| `invalid` | boolean | `false` | Toggle the invalid state for the component. |
451452
| `locale` | string | `'default'` | Sets the default locale for components. If not set, it is inherited from the navigator.language. |

js/src/date-range-picker.js

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ const Default = {
9494
footer: false,
9595
inputDateFormat: null,
9696
inputDateParse: null,
97+
inputOnChangeDelay: 750,
9798
inputReadOnly: false,
9899
invalid: false,
99100
indicator: true,
@@ -147,6 +148,7 @@ const DefaultType = {
147148
indicator: 'boolean',
148149
inputDateFormat: '(function|null)',
149150
inputDateParse: '(function|null)',
151+
inputOnChangeDelay: 'number',
150152
inputReadOnly: 'boolean',
151153
invalid: 'boolean',
152154
locale: 'string',
@@ -204,6 +206,8 @@ class DateRangePicker extends BaseComponent {
204206
this._timePickerEnd = null
205207
this._timePickerStart = null
206208
this._togglerElement = null
209+
this._startInputTimeout = null
210+
this._endInputTimeout = null
207211

208212
this._createDateRangePicker()
209213
this._createDateRangePickerCalendars()
@@ -272,6 +276,14 @@ class DateRangePicker extends BaseComponent {
272276
this._popper.destroy()
273277
}
274278

279+
if (this._startInputTimeout) {
280+
clearTimeout(this._startInputTimeout)
281+
}
282+
283+
if (this._endInputTimeout) {
284+
clearTimeout(this._endInputTimeout)
285+
}
286+
275287
super.dispose()
276288
}
277289

@@ -349,18 +361,24 @@ class DateRangePicker extends BaseComponent {
349361
})
350362

351363
EventHandler.on(this._startInput, EVENT_INPUT, event => {
352-
const date = this._parseDate(event.target.value)
353-
354-
// valid date or empty date
355-
if ((date instanceof Date && !Number.isNaN(date)) || (date === null)) {
356-
this._startDate = date
357-
this._calendarDate = date
358-
this._calendar.update(this._getCalendarConfig())
364+
if (this._startInputTimeout) {
365+
clearTimeout(this._startInputTimeout)
359366
}
360367

361-
EventHandler.trigger(this._element, EVENT_START_DATE_CHANGE, {
362-
date
363-
})
368+
this._startInputTimeout = setTimeout(() => {
369+
const date = this._parseDate(event.target.value)
370+
371+
// valid date or empty date
372+
if ((date instanceof Date && !Number.isNaN(date)) || (date === null)) {
373+
this._startDate = date
374+
this._calendarDate = date
375+
this._calendar.update(this._getCalendarConfig())
376+
}
377+
378+
EventHandler.trigger(this._element, EVENT_START_DATE_CHANGE, {
379+
date
380+
})
381+
}, this._config.inputOnChangeDelay)
364382
})
365383

366384
EventHandler.on(this._startInput.form, EVENT_SUBMIT, () => {
@@ -391,18 +409,24 @@ class DateRangePicker extends BaseComponent {
391409
})
392410

393411
EventHandler.on(this._endInput, EVENT_INPUT, event => {
394-
const date = this._parseDate(event.target.value)
395-
396-
// valid date or empty date
397-
if ((date instanceof Date && !Number.isNaN(date)) || (date === null)) {
398-
this._endDate = date
399-
this._calendarDate = date
400-
this._calendar.update(this._getCalendarConfig())
412+
if (this._endInputTimeout) {
413+
clearTimeout(this._endInputTimeout)
401414
}
402415

403-
EventHandler.trigger(this._element, EVENT_END_DATE_CHANGE, {
404-
date
405-
})
416+
this._endInputTimeout = setTimeout(() => {
417+
const date = this._parseDate(event.target.value)
418+
419+
// valid date or empty date
420+
if ((date instanceof Date && !Number.isNaN(date)) || (date === null)) {
421+
this._endDate = date
422+
this._calendarDate = date
423+
this._calendar.update(this._getCalendarConfig())
424+
}
425+
426+
EventHandler.trigger(this._element, EVENT_END_DATE_CHANGE, {
427+
date
428+
})
429+
}, this._config.inputOnChangeDelay)
406430
})
407431

408432
EventHandler.on(window, EVENT_RESIZE, () => {

0 commit comments

Comments
 (0)