Skip to content

Commit 1e16782

Browse files
committed
feat(TimePicker): add inputOnChangeDelay option for manual time input
- Add 750ms default delay before processing manual time input changes - Implement debounced input handling to prevent excessive updates while typing - Add timeout cleanup in dispose method to prevent memory leaks - Update configuration options and type definitions - Update time-picker.md documentation with new option
1 parent 54b66b4 commit 1e16782

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

docs/content/forms/time-picker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ const timePickerList = timePickerElementList.map(timePickerEl => {
223223
| `footer` | boolean | `true` | Toggle visibility of footer element. |
224224
| `hours` | array, function, null | `null` | Specify a list of available hours using an array, or customize the filtering of hours through a function. |
225225
| `indicator` | boolean | `true` | Toggle visibility or set the content of the input indicator. |
226+
| `inputOnChangeDelay` | number | `750` | Delay in milliseconds before processing manual time input changes. |
226227
| `inputReadOnly` | boolean | `false` | Toggle the readonly state for the component. |
227228
| `invalid` | boolean | `false` | Toggle the invalid state for the component. |
228229
| `locale` | string | `'default'` | Sets the default locale for components. If not set, it is inherited from the navigator.language. |

js/src/time-picker.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const Default = {
8484
footer: true,
8585
hours: null,
8686
indicator: true,
87+
inputOnChangeDelay: 750,
8788
inputReadOnly: false,
8889
invalid: false,
8990
locale: 'default',
@@ -110,6 +111,7 @@ const DefaultType = {
110111
footer: 'boolean',
111112
hours: '(array|function|null)',
112113
indicator: 'boolean',
114+
inputOnChangeDelay: 'number',
113115
inputReadOnly: 'boolean',
114116
invalid: 'boolean',
115117
locale: 'string',
@@ -145,6 +147,7 @@ class TimePicker extends BaseComponent {
145147
this._input = null
146148
this._menu = null
147149
this._timePickerBody = null
150+
this._inputTimeout = null
148151

149152
this._localizedTimePartials = getLocalizedTimePartials(
150153
this._config.locale,
@@ -220,6 +223,10 @@ class TimePicker extends BaseComponent {
220223
this._popper.destroy()
221224
}
222225

226+
if (this._inputTimeout) {
227+
clearTimeout(this._inputTimeout)
228+
}
229+
223230
super.dispose()
224231
}
225232

@@ -308,15 +315,21 @@ class TimePicker extends BaseComponent {
308315
})
309316

310317
EventHandler.on(this._input, EVENT_INPUT, event => {
311-
if (isValidTime(event.target.value)) {
312-
this._date = this._convertStringToDate(event.target.value)
313-
314-
EventHandler.trigger(this._element, EVENT_TIME_CHANGE, {
315-
timeString: this._date ? this._date.toTimeString() : null,
316-
localeTimeString: this._date ? this._date.toLocaleTimeString() : null,
317-
date: this._date
318-
})
318+
if (this._inputTimeout) {
319+
clearTimeout(this._inputTimeout)
319320
}
321+
322+
this._inputTimeout = setTimeout(() => {
323+
if (isValidTime(event.target.value)) {
324+
this._date = this._convertStringToDate(event.target.value)
325+
326+
EventHandler.trigger(this._element, EVENT_TIME_CHANGE, {
327+
timeString: this._date ? this._date.toTimeString() : null,
328+
localeTimeString: this._date ? this._date.toLocaleTimeString() : null,
329+
date: this._date
330+
})
331+
}
332+
}, this._config.inputOnChangeDelay)
320333
})
321334

322335
if (this._config.type === 'dropdown') {

0 commit comments

Comments
 (0)