Inline Mode
Display the timepicker directly on your page without a modal
What is Inline Mode?
#Inline mode displays the timepicker clock directly in your page layout, always visible without requiring a click to open. Perfect for dashboards, settings pages, or when you want the time selection to be immediately accessible.
- No modal or backdrop - stays in document flow
- Always visible - no click needed to open
- Works with all themes and customization options
- Perfect for embedded forms and settings panels
Basic Usage
#Set ui.inline.enabled to true and pass the element to render into, or its selector, as ui.inline.container. The picker renders there when you call create().
HTML Structure
<input type="text" id="timepicker" /><div id="timepicker-container"></div>
JavaScript
import { TimepickerUI } from 'timepicker-ui';const input = document.querySelector('#timepicker');const picker = new TimepickerUI(input, {ui: {inline: {enabled: true,container: '#timepicker-container'}}});picker.create();
containeris required. The constructor throws if it is missing or the element is not found.showButtons(defaultfalse) shows the OK and Cancel buttons. OK writes the time to the input and firesconfirm/onConfirm. Cancel resets the picker to the input's value and firescancel/onCancel. The picker stays on the page in both cases.autoUpdate(defaultfalse) writes the time to the input while the user changes it.- Focus is not trapped in inline mode unless you set
behavior.focusTrapyourself.
Configuration Options
#Combine inline mode with other options for complete customization:
12-hour Inline Picker
const picker = new TimepickerUI(input, {ui: {inline: { enabled: true, container: '#timepicker-container' },theme: 'basic'},clock: { type: '12h' }});picker.create();
24-hour Inline with Theme
const picker = new TimepickerUI(input, {ui: {inline: { enabled: true, container: '#timepicker-container' },theme: 'cyberpunk'},clock: { type: '24h' }});picker.create();
Inline with Time Restrictions
const picker = new TimepickerUI(input, {ui: {inline: { enabled: true, container: '#timepicker-container' }},clock: {type: '24h',disabledTime: {hours: [0, 1, 2, 3, 4, 5, 22, 23],minutes: [15, 30, 45]}}});picker.create();
Styling Inline Mode
#In inline mode the picker's root (.tp-ui-modal) gets the tp-ui--inline class. Its card, .tp-ui-wrapper, stays in the page flow, is centered, and fills the container up to 328px. These inline rules use !important, so your overrides need it too.
Card Border Instead of Shadow
.tp-ui--inline .tp-ui-wrapper {box-shadow: none !important;border: 1px solid #e0e0e0;}
Sidebar Integration
.sidebar .tp-ui--inline .tp-ui-wrapper {margin: 20px auto !important;}
Embedded in a host component
#Set ui.inline.embedded to true when the picker sits inside your own dialog, popover or form. The picker then behaves as part of that component instead of a standalone card:
- The root is
role="group"with an accessible name, not a dialog. It has noaria-modal. - The card has no shadow and no minimum height. The
max-widthof 328px stays. - Focus is not trapped, whatever
behavior.focusTrapsays, and the picker does not take focus when it mounts. - The picker's wrapper is not a tab stop, so Tab does not stop on it before the controls inside. New in 4.7.0.
- The hour, minute and second fields have no
nameattribute, so they are not sent when the picker sits inside a<form>. Your own input holds the value. New in 4.7.0. embeddedis ignored unlessenabledistrue. The default isfalse.
const dialog = document.querySelector('dialog');const input = document.querySelector('#time');let picker = null;openButton.addEventListener('click', () => {dialog.showModal();if (picker) return;picker = new TimepickerUI(input, {ui: {inline: {enabled: true,container: '#dialog-picker',embedded: true,autoUpdate: true}}});picker.create();});
A picker created in a hidden container, such as a closed <dialog>, lays out its clock face or wheel the first time it is shown. Before 4.7.0 the clock face measured itself on creation and got a size of 0 there, so create the picker once the container is visible, as above. See the live example.
Hide the title
#Set ui.inline.showTitle to false when your page or host component already shows a heading. The title ( "Select time" or "Enter Time") is hidden visually but still names the picker for screen readers, and the header keeps its top spacing. The root gets the class tp-ui--title-hidden. The default is true, and the option is ignored unless enabled is true. New in 4.7.0.
const picker = new TimepickerUI(input, {ui: {inline: {enabled: true,container: '#timepicker-container',embedded: true,showTitle: false}}});picker.create();
Embedded card surface
#An embedded card takes its background, corners and backdrop filter from three variables. Set them on the root or on a parent element. They fall back to --tp-bg, --tp-radius-md and --tp-backdrop-filter. New in 4.7.0.
.my-dialog .tp-ui--embedded {--tp-embedded-bg: transparent;--tp-embedded-radius: 0;--tp-embedded-backdrop-filter: none;}
Switch views from your own footer
#A host component can drive the view itself with setView() and getView(), for example with a button in its own footer. The picker emits switch:view with the new view.
const toggle = document.querySelector('#view-toggle');toggle.addEventListener('click', () => {picker.setView(picker.getView() === 'clock' ? 'keyboard' : 'clock');});picker.on('switch:view', ({ view }) => {toggle.textContent = view === 'clock' ? 'Keyboard' : 'Clock';});
React Example
#Using inline mode in React components. container takes the element from a ref, so the container needs no id:
import { useEffect, useRef } from 'react';import { TimepickerUI } from 'timepicker-ui';function InlineTimepicker() {const inputRef = useRef<HTMLInputElement>(null);const containerRef = useRef<HTMLDivElement>(null);useEffect(() => {if (!inputRef.current || !containerRef.current) return;const picker = new TimepickerUI(inputRef.current, {ui: {inline: {enabled: true,container: containerRef.current,autoUpdate: true},theme: 'm3-green'},clock: { type: '12h' }});picker.create();return () => {picker.destroy();};}, []);return (<div className="p-8"><input ref={inputRef} type="text" aria-label="Selected time" readOnly /><div ref={containerRef} /></div>);}
- Best Practices
- When using inline mode, make sure to provide enough space in your layout for the clock face (minimum 280x280px recommended). Consider using CSS media queries to adjust the size on smaller screens.
- Mobile optimization tips