timepicker-ui
4.6.0GitHub
timepicker-ui
Features / Clear Button

Clear Button

Reset time selection with a dedicated button in the picker footer

Available since v4.2.0

The clear button is off by default. Turn it on with ui.clearButton: true. It resets the clock hands to 12:00, disables the confirm button, and optionally empties the input value.

Basic Usage

#

Set ui.clearButton: true to show the button:

index.ts
const picker = new TimepickerUI(input, {
ui: { clearButton: true }
});
picker.create();

Disable Clear Button

#

ui.clearButton is false by default. Leave it out, or set it to false, to hide the button:

index.ts
new TimepickerUI(input, {
ui: { clearButton: false }
}).create();

Clear Behavior Options

#

Pass an object to ui.clearButton to control what happens when the user clicks Clear. The object form also shows the button. It is new in 4.5.0 and replaces clearBehavior.clearInput, which still works until 5.0:

index.ts
new TimepickerUI(input, {
ui: {
clearButton: { clearInput: false } // Keep the input value after clearing
}
}).create();
OptionTypeDefaultDescription
clearInputbooleantrueWhether clearing also empties the input field value

Custom Label

#

Customize the button text with labels.clear:

index.ts
new TimepickerUI(input, {
ui: { clearButton: true },
labels: { clear: 'Reset' }
}).create();

Clear Event

#

Listen for the clear event via EventEmitter or callback:

EventEmitter

index.ts
picker.on('clear', (data) => {
console.log('Cleared! Previous value:', data.previousValue);
});

Callback option

index.ts
new TimepickerUI(input, {
ui: { clearButton: true },
callbacks: {
onClear: (data) => {
console.log('Cleared! Previous value:', data.previousValue);
}
}
}).create();

Behavior Details

#
  • Clock hands reset to the 12:00 (neutral) position
  • Confirm (OK) button becomes disabled until a new time is selected
  • Clear button auto-disables when no time is selected
  • Screen reader announces "Time cleared" (labels.announceCleared) for accessibility

TypeScript Types

#
index.ts
import type { ClearEventData, UIOptions } from 'timepicker-ui';
// ClearEventData: { previousValue: string | null }
// UIOptions['clearButton']: boolean | { clearInput?: boolean }
Esc