timepicker-ui
4.6.0GitHub
timepicker-ui
Getting Started / Migrate to v4

Migration Guide v3 to v4

Breaking Changes

Complete guide for upgrading from v3.x to v4.0.0

Important Notice

Version 4.0.0 introduces breaking changes in the options structure. There is NO backward compatibility - all v3.x code will break and must be updated.

Migration typically takes 15-60 minutes depending on your codebase size.

Migrating from v2.x?

If you're still using version 2.x, please see the Legacy Migration Guide v2 to v3 first, then follow this guide to upgrade to v4.

Option names from 4.5.0

The v4 side of this guide uses the option names from 4.5.0. Some options had other names in 4.0 to 4.4. Those names still work until 5.0 and are listed in Renamed in 4.5.0.

What Changed?

#

The previous flat structure with 40+ fields has been reorganized into 5 logical groups to improve code clarity, maintainability, and developer experience:

clock
Clock behavior configuration
ui
UI appearance and behavior
labels
Text labels customization
behavior
General behavior settings
callbacks
Event handler callbacks

Before & After

#

Old API (v3.x) - Flat Structure

index.ts
const timepicker = new TimepickerUI('#input', {
clockType: '12h',
amLabel: 'AM',
pmLabel: 'PM',
okLabel: 'OK',
cancelLabel: 'Cancel',
timeLabel: 'Select time',
animation: true,
backdrop: true,
theme: 'basic',
incrementHours: 1,
incrementMinutes: 5,
focusTrap: true,
delayHandler: 300,
mobile: false,
editable: false,
onOpen: (event) => console.log('opened', event),
onConfirm: (event) => console.log('confirmed', event),
});

New API (v4) - Grouped Structure

index.ts
const timepicker = new TimepickerUI('#input', {
clock: {
type: '12h',
incrementHours: 1,
incrementMinutes: 5,
},
ui: {
animation: true,
backdrop: true,
theme: 'basic',
initialView: 'clock',
editable: false,
},
labels: {
am: 'AM',
pm: 'PM',
ok: 'OK',
cancel: 'Cancel',
clockTitle: 'Select time',
},
behavior: {
focusTrap: true,
delayHandler: 300,
},
callbacks: {
onOpen: (event) => console.log('opened', event),
onConfirm: (event) => console.log('confirmed', event),
},
});

Complete Field Mapping

#

Clock Options

v3.x (Flat)v4.5 (Grouped)
clockTypeclock.type
incrementHoursclock.incrementHours
incrementMinutesclock.incrementMinutes
autoSwitchToMinutesclock.autoSwitchToMinutes
disabledTimeclock.disabledTime
currentTime: trueclock.defaultTime: 'now'
currentTime: { time, updateInput }clock.defaultTime: { time, updateInput }

UI Options

v3.x (Flat)v4.5 (Grouped)
themeui.theme
animationui.animation
backdropui.backdrop
mobile: trueui.initialView: 'keyboard'
enableSwitchIconui.viewSwitch
editableui.editable
enableScrollbarui.allowPageScroll
cssClassui.cssClass
appendModalSelectorui.appendTo
iconTemplateui.keyboardIcon
iconTemplateMobileui.clockIcon
inlineui.inline
inline: { containerId: 'x' }ui.inline: { container: '#x' }

Label Options

v3.x (Flat)v4.5 (Grouped)
amLabellabels.am
pmLabellabels.pm
okLabellabels.ok
cancelLabellabels.cancel
timeLabellabels.clockTitle
mobileTimeLabellabels.keyboardTitle
hourMobileLabellabels.hour
minuteMobileLabellabels.minute

Behavior Options

v3.x (Flat)v4.5 (Grouped)
focusInputAfterCloseModalbehavior.returnFocus
focusTrapbehavior.focusTrap
delayHandlerbehavior.delayHandler
idbehavior.id

Callback Options

v3.x (Flat)v4.5 (Grouped)
onOpencallbacks.onOpen
onCancelcallbacks.onCancel
onConfirmcallbacks.onConfirm
onUpdatecallbacks.onUpdate
onSelectHourcallbacks.onSelectHour
onSelectMinutecallbacks.onSelectMinute
onSelectAM, onSelectPMcallbacks.onSelectPeriod (data.type is 'AM' or 'PM')
onErrorcallbacks.onError

Accessing & Updating Options

#

Accessing Options in Code

v3.x

index.ts
const options = timepicker.options;
console.log(options.clockType); // '12h'
console.log(options.amLabel); // 'AM'

v4.0.0

index.ts
const options = timepicker.options;
console.log(options.clock.type); // '12h'
console.log(options.labels.am); // 'AM'

Updating Options

v3.x - NO LONGER WORKS

index.ts
timepicker.update({
options: {
clockType: '24h',
animation: false,
},
});

v4.5 - REQUIRED

index.ts
timepicker.setOptions({
clock: { type: '24h' },
ui: { animation: false },
});

Before 4.5.0, pass the same groups to timepicker.update({ options }). It still works until 5.0.

TypeScript Support

#

Version 4.0.0 provides improved TypeScript types for the new grouped structure:

index.ts
import type {
TimepickerOptions, // Main grouped options type
ClockOptions, // Clock group
UIOptions, // UI group
LabelsOptions, // Labels group
BehaviorOptions, // Behavior group
CallbacksOptions, // Callbacks group
} from 'timepicker-ui';
const options: TimepickerOptions = {
clock: {
type: '12h',
incrementMinutes: 5,
},
ui: {
theme: 'basic',
animation: true,
},
labels: {
ok: 'Confirm',
cancel: 'Close',
},
};
const timepicker = new TimepickerUI('#input', options);

Note: OptionTypes Is Deprecated

OptionTypes is still exported, but it describes the old flat v3 options and is deprecated in favour of TimepickerOptions. It is removed in 5.0.

Benefits of the New Structure

#
Better Organization
Related options are grouped together logically
Improved Discoverability
Easier to find related settings
Autocomplete by Group
Suggestions list only the options of the current group
Reduced Cognitive Load
Smaller, focused option groups
Future-Proof
Easier to add new options without cluttering
Cleaner API
No more 40+ flat fields to navigate

Common Migration Examples

#

Basic Setup

index.ts
// v4.0.0
const timepicker = new TimepickerUI('#input', {
clock: { type: '12h' },
});

Advanced Setup

index.ts
// v4.5
const timepicker = new TimepickerUI('#input', {
clock: {
type: '24h',
incrementMinutes: 15,
disabledTime: {
ranges: ['00:00 - 06:00', '22:00 - 23:59'],
},
},
ui: {
theme: 'm3-green',
animation: true,
backdrop: true,
initialView: 'clock',
editable: true,
},
labels: {
clockTitle: 'Pick a time',
ok: 'Confirm',
cancel: 'Dismiss',
},
behavior: {
focusTrap: true,
delayHandler: 300,
returnFocus: true,
},
callbacks: {
onOpen: () => console.log('Opened'),
onConfirm: (data) => console.log('Time selected:', data),
onCancel: () => console.log('Cancelled'),
},
});

Inline Mode

index.ts
// v4.5
const timepicker = new TimepickerUI('#input', {
ui: {
inline: {
enabled: true,
container: '#timepicker-container',
showButtons: false,
autoUpdate: true,
},
},
behavior: {
focusTrap: false, // Automatically set if not specified
},
});

FAQ

#
Will my v3.x code break?
Yes. v4.0.0 is a major breaking change. You MUST update all code to use grouped options.
Is there a migration layer?
No. There is NO backward compatibility. All old flat structure code will break.
Can I mix flat and grouped structures?
No. Only grouped structure is supported in v4.0.0.
How long will migration take?
Depending on your codebase size, it should take 15-60 minutes using find-and-replace.

Need Help?

#

If you encounter issues during migration:

Esc