Skip to content

Commit

Permalink
enhancement(Timepicker) implemented options auto submit, user input c…
Browse files Browse the repository at this point in the history
  • Loading branch information
gselderslaghs committed Jan 24, 2025
1 parent 43d453c commit b03a26a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/timepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export interface TimepickerOptions extends BaseOptions {
* @default false
*/
showClearBtn: boolean;
/**
* Autosubmit timepicker selection to input field
* @default true
*/
autoSubmit: true;
/**
* Default time to set on the timepicker 'now' or '13:14'.
* @default 'now';
Expand Down Expand Up @@ -69,6 +74,11 @@ export interface TimepickerOptions extends BaseOptions {
* @default null
*/
onSelect: (hour: number, minute: number) => void;
/**
* Callback function for interaction with input field.
* @default null
*/
onInputInteraction: (() => void) | null;
}

const _defaults: TimepickerOptions = {
Expand All @@ -81,6 +91,7 @@ const _defaults: TimepickerOptions = {
defaultTime: 'now', // default time, 'now' or '13:14' e.g.
fromNow: 0, // Millisecond offset from the defaultTime
showClearBtn: false,
autoSubmit: true,
// internationalization
i18n: {
cancel: 'Cancel',
Expand All @@ -90,7 +101,8 @@ const _defaults: TimepickerOptions = {
twelveHour: true, // change to 12 hour AM/PM clock from 24 hour
vibrate: true, // vibrate the device when dragging clock hand
// Callbacks
onSelect: null
onSelect: null,
onInputInteraction: null
};

type Point = {
Expand Down Expand Up @@ -237,12 +249,14 @@ export class Timepicker extends Component<TimepickerOptions> {

_handleInputClick = () => {
this.inputHours.focus();
if (typeof this.options.onInputInteraction === 'function') this.options.onInputInteraction.call(this);
};

_handleInputKeydown = (e: KeyboardEvent) => {
if (Utils.keys.ENTER.includes(e.key)) {
e.preventDefault();
this.inputHours.focus();
if (typeof this.options.onInputInteraction === 'function') this.options.onInputInteraction.call(this);
}
};

Expand Down Expand Up @@ -301,7 +315,7 @@ export class Timepicker extends Component<TimepickerOptions> {
} else {
// this.minutesView.classList.add('timepicker-dial-out');
setTimeout(() => {
this.done();
if (this.options.autoSubmit) this.done();
}, this.options.duration / 2);
}

Expand Down

0 comments on commit b03a26a

Please sign in to comment.