Timepicker

The Timepicker component is a form element that allows users to select a time from a time picker interface. It is used to input a time in a user-friendly way.

Design system docs Examples Default Timepicker

The default Timepicker is a form element with a label, placeholder, and description. It provides an intuitive interface for time selection.

<div style={{ display: 'flex', minHeight: 200 }}>
<dap-ds-timepicker 
  label="Meeting time"
  description="Choose the meeting start time"
>
</dap-ds-timepicker>
</div>
Sizes
<div style={{ display: 'flex', minHeight: 200 }}>
<dap-ds-stack>
<dap-ds-timepicker 
  size="xs"
  label="Meeting time"
  feedback="This is a feedback message"
  feedbacktype="negative"
  description="Choose the meeting start time"
>
</dap-ds-timepicker>
<dap-ds-timepicker 
  size="sm"
  label="Meeting time"
  feedback="This is a feedback message"
  feedbacktype="negative"
  description="Choose the meeting start time"
>
</dap-ds-timepicker>
<dap-ds-timepicker 
  size="lg"
  label="Meeting time"
  feedback="This is a feedback message"
  feedbacktype="negative"
  description="Choose the meeting start time"
>
</dap-ds-timepicker>
</dap-ds-stack>
</div>
Validation

The timepicker will emit a dds-valid-time custom event if the input is a valid time, and a dds-invalid-time custom event if the input is not a valid time. You can listen for these events to validate the input, and check the error type with the type property of the event detail.

HTML

Js

timepicker.addEventListener('dds-valid-time', e => {
  console.log('Valid Value:', e.detail)
  timepicker.feedback = 'valid'
  timepicker.status = 'valid'
  timepicker.feedbackType = 'positive'
})

timepicker.addEventListener('dds-invalid-time', e => {
  console.log('dds-invalid-time', event.detail.value)

  timepicker2.status = 'error'
  timepicker2.feedbackType = 'negative'

  if(event.detail.type === 'invalid') {
    timepicker2.feedback = 'Invalid time'
  }

  if(event.detail.type === 'out-of-range') {
    timepicker2.feedback = 'Time is out of range'
  }
})

timepicker.addEventListener('dds-change', e => {
  console.log('Value:', e.detail)
})

React

import { DapDSButtonReact, DapDSTimePickerReact } from 'dap-design-system/dist/react'
import { Controller, useForm } from 'react-hook-form';

function App() {
  const {
    control,
    handleSubmit,
    setValue,
    setError,
    formState: { errors },
  } = useForm()

  const onSubmit = (data: any) => {
    console.log('data', data)
  }
  
  return (
    <div className="App">
    <form onSubmit={handleSubmit(onSubmit)} noValidate>
      <Controller
        name="timepicker"
        control={control}
        render={({ field: { value } }) => (
          <DapDSTimePickerReact
            id="timepicker"
            label="Meeting time"
            description="Choose the meeting start time"
            required
            name="timepicker"
            value={value}
            feedback={errors?.timepicker?.message?.toString()}
            feedbackType={errors?.timepicker ? 'negative' : 'positive'}
            onDdsChange={(e) => {
              console.log(e)
              setValue('timepicker', e.detail.value, { shouldValidate: true })}
            }
            onDdsInvalidTime={(e) => {
              console.log(e)
              if (e.detail.type === 'invalid') {
                setError('timepicker', { message: 'Invalid time format' })
              }

              if (e.detail.type === 'out-of-range') {
                setError('timepicker', { message: 'Time out of range' })
              }
            }}
            onDdsValidTime={(e) => {
              console.log(e)
              setError('timepicker', { message: '' })
            }}
          >
          </DapDSTimePickerReact>
        )}
        rules={{
          validate: {
            required: value => {
              if (!value) return '*Required'
            },
          },
        }}
      />
      <DapDSButtonReact htmlType="submit">Submit</DapDSButtonReact>
    </form>
    </div>
  );
}

export default App;
Localization

The locale property can be used to set the locale of the timepicker. The default locale is the current locale of the browser. The available locales are en and hu.

<div style={{ display: 'flex', minHeight: 200 }}>
<dap-ds-stack>
  <dap-ds-timepicker 
    locale="hu"
    label="Találkozó időpontja"
    feedback="Érvénytelen időpont"
    feedbacktype="negative"
    description="Válassz találkozó időpontot"
  >
  </dap-ds-timepicker>
  <dap-ds-timepicker 
    locale="en"
    label="Meeting time"
    feedback="Invalid time"
    feedbacktype="negative"
    description="Choose the meeting start time"
  >
  </dap-ds-timepicker>
</dap-ds-stack>
</div>
Time Format

The timepicker supports various time formats. You can set a custom time format with the format attribute. The format attribute accepts a string separated with '|' character, or you can set the separator character with the formatSeparator attribute.

<div style={{ display: 'flex', minHeight: 200 }}>
<dap-ds-stack>
  <dap-ds-timepicker 
    format="HH:mm"
    label="24-hour format"
    description="Time in 24-hour format"
  >
  </dap-ds-timepicker>
  <dap-ds-timepicker 
    format="hh:mm A"
    label="12-hour format"
    description="Time in 12-hour format with AM/PM"
  >
  </dap-ds-timepicker>
</dap-ds-stack>
</div>
Time Range

You can set minimum and maximum time constraints using the min and max attributes to restrict the time selection within a specific range.

<div style={{ display: 'flex', minHeight: 200 }}>
<dap-ds-stack>
  <dap-ds-timepicker 
    minTime="09:00"
    maxTime="17:00"
    label="Business hours"
    description="Select time between 9 AM and 5 PM"
  >
  </dap-ds-timepicker>
</dap-ds-stack>
</div>
Step Intervals

The step attribute allows you to set the time increment for the time picker. This is useful for setting specific intervals like 15 minutes, 30 minutes, or 1 hour.

<div style={{ display: 'flex', minHeight: 200 }}>
<dap-ds-stack>
  <dap-ds-timepicker
    step="20"
    label="20-minute intervals"
    description="Time selection in 20-minute increments"
  >
  </dap-ds-timepicker>
  <dap-ds-timepicker
    step="1"
    label="1-minute intervals"
    description="Time selection in 1-minute increments"
  >
  </dap-ds-timepicker>
</dap-ds-stack>
</div>
Seconds Support

The timepicker supports seconds selection with the showSeconds attribute. You can control the seconds increment using the secondsStep attribute. Remember to update the format attribute to include seconds (e.g., HH:mm:ss).

<div style={{ display: 'flex', minHeight: 300 }}>
<dap-ds-stack>
  <dap-ds-timepicker
    showSeconds
    secondsStep="5"
    format="HH:mm:ss"
    label="Time with seconds"
    description="5-second intervals"
    placeholder="HH:mm:ss"
  >
  </dap-ds-timepicker>
  <dap-ds-timepicker
    showSeconds
    secondsStep="1"
    format="HH:mm:ss"
    label="Time with seconds"
    description="1-second intervals"
    placeholder="HH:mm:ss"
  >
  </dap-ds-timepicker>
</dap-ds-stack>
</div>
Time Presets

You can provide quick time selection options using the presets property. Presets appear as buttons at the top of the time picker for faster selection of common times.

<div style={{ display: 'flex', minHeight: 300 }}>
<dap-ds-timepicker
  id="preset-timepicker"
  label="Meeting time"
  description="Quick select common meeting times"
  presets={[
    { label: 'Morning', value: '09:00' },
    { label: 'Lunch', value: '12:00' },
    { label: 'Afternoon', value: '15:00' },
    { label: 'Evening', value: '18:00' }
  ]}
>
</dap-ds-timepicker>
</div>
Disabled Times

You can disable specific times using the disabledTime callback function. This is useful for restricting selection to business hours or other custom time constraints. The callback receives hour, minute, and optionally second parameters, and should return true if the time should be disabled.

<div style={{ display: 'flex', minHeight: 300 }}>
<dap-ds-stack>
  <dap-ds-timepicker
    id="business-hours"
    label="Business hours"
    description="Only 9 AM - 5 PM available"
    disabledTime={(hour, minute) => {
      return hour < 9 || hour >= 17
    }}
  >
  </dap-ds-timepicker>
  <dap-ds-timepicker
    id="hidden-disabled"
    label="Business hours (hidden)"
    description="Only shows available times"
    disabledTime = {(hour, minute) => {
      return hour < 9 || hour >= 17
    }}
    hideDisabledTimes={true}
  >
  </dap-ds-timepicker>
</dap-ds-stack>
</div>
Hide Disabled Times

When using the disabledTime callback, you can set hideDisabledTimes to true to completely hide disabled time options instead of showing them as disabled. This creates a cleaner interface when many times are unavailable.

Importing
import { DapDSTimePicker } from 'dap-design-system'
Importing React
import { DapDSTimePickerReact } from 'dap-design-system/react'
Tree-Shakeable Imports

For optimal bundle sizes, use the tree-shakeable import syntax:

import { DapDSTimePicker } from 'dap-design-system/components'
Attributes
PropertyTypeDefaultDescription
minTimestring'00:00'The minimum time of the timepicker. Format: 'HH:mm'.
maxTimestring'23:59'The maximum time of the timepicker. Format: 'HH:mm'.
stepnumber5The step interval in minutes. Defaults to 15.
placementstring'bottom-start'The placement of the dropdown of the timepicker.
openedbooleanfalseThe open state of the timepicker.
openTimeOnInputbooleanfalseWhether the time picker should open on typing.
sendEmptyEventOnInputbooleanfalseWhether the time picker should send an empty event on typing.
placeholderstringThe placeholder of the timepicker.
loadingbooleanfalseThe loading state of the timepicker.
formatstring'HH:mm'The format of the timepicker. Defaults to 'HH:mm'.
clearButtonstring'true'Whether the clear button should be shown. Defaults to 'true'.
clearButtonAriaLabelstringThe aria label of the clear button.
floatingStrategyFloatingStrategy'fixed'The floating strategy of the timepicker.
localestringThe locale of the timepicker.
closeOnSelectionbooleanfalseWhether the dropdown should close when a time is selected.
showSecondsbooleanfalseWhether to show the seconds column in the time picker.
secondsStepnumber1The step interval in seconds. Defaults to 1.
disabledTimefunctionCallback to determine if a time should be disabled.
hideDisabledTimesbooleanfalseWhether to hide disabled times or show them as disabled.
presetsTimePreset[]Array of preset time slots for quick selection.
valueDayjsThe value of the timepicker.
labelstringThe label of the timepicker.
descriptionstringThe description of the timepicker.
size'xs', 'sm' , 'lg'The size of the timepicker.
disabledbooleanThe disabled state of the timepicker.
requiredbooleanThe required state of the timepicker.
readonlybooleanThe readonly state of the timepicker.
autofocusbooleanThe autofocus state of the timepicker.
tooltipstringThe tooltip of the timepicker.
tooltipPlacement'top', 'right' , 'bottom' , 'left'The tooltip placement of the timepicker.
feedbackstringThe feedback of the timepicker.
feedbackType'negative', 'positive' , 'warning'The feedback type of the timepicker.
optionalbooleanThe optional state of the timepicker.
optionalLabelstringThe optional label of the timepicker.
subtlebooleanThe weight of the label. Default is false
autocompletestringThe autocomplete of the timepicker.
Slots

No slots available.

Events
Event NameDescriptionType
dds-changeFired when the timepicker value changes.{value: string }
dds-inputFired when the timepicker input value changes.{value: string }
dds-valid-timeFired when the timepicker input value is valid. Happens on manual input typing.{value: string }
dds-invalid-timeFired when the timepicker input value is invalid. Happens on manual input typing.{value: string, type: 'invalid' , 'out-of-range' }
dds-clearFired when the timepicker is cleared.{void }
dds-focusEmitted when the timepicker gains focus.{void }
dds-blurEmitted when the timepicker loses focus.{void }
CSS Parts
Part NameDescription
baseThe main timepicker container.
triggerThe trigger button of the timepicker.
labelThe label of the timepicker.
descriptionThe description of the timepicker.
feedbackThe feedback of the timepicker.
tooltipThe tooltip of the timepicker.
inputThe input of the timepicker.
clear-buttonThe clear button of the timepicker.
How to Use CSS Parts

You can style CSS parts using the ::part() pseudo-element selector:

/* Target a specific part */
.my-custom-dap-ds-timepicker::part(base) {
  /* Your custom styles */
}

/* Target multiple parts */
.my-custom-dap-ds-timepicker::part(base),
.my-custom-dap-ds-timepicker::part(trigger) {
  /* Shared styles */
}

Example usage:

<dap-ds-timepicker class="my-custom-dap-ds-timepicker">
  Timepicker
</dap-ds-timepicker>
.my-custom-dap-ds-timepicker::part(base) {
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.

CSS Custom Properties
Property NameDescription
--dds-timepicker-backgroundThe background color of the timepicker. Defaults to var(--dds-fields-background-default).
--dds-timepicker-border-colorThe border color of the timepicker. Defaults to var(--dds-border-neutral-base).
--dds-timepicker-border-widthThe border width of the timepicker. Defaults to var(--dds-border-width-base, 1px).
--dds-timepicker-border-radiusThe border radius of the timepicker. Defaults to var(--dds-radius-base).
--dds-timepicker-text-colorThe text color of the timepicker. Defaults to var(--dds-text-neutral-base).
--dds-timepicker-placeholder-colorThe placeholder text color. Defaults to var(--dds-text-neutral-subtle).
--dds-timepicker-disabled-backgroundThe background color when disabled. Defaults to var(--dds-background-neutral-stronger).
--dds-timepicker-disabled-textThe text color when disabled. Defaults to var(--dds-text-neutral-disabled).
--dds-timepicker-error-borderThe border color for error state. Defaults to var(--dds-border-negative-base).
--dds-timepicker-success-borderThe border color for success state. Defaults to var(--dds-border-positive-base).
--dds-timepicker-icon-colorThe color of the icons. Defaults to var(--dds-text-icon-neutral-subtle).
--dds-timepicker-clear-icon-colorThe color of the clear icon. Defaults to var(--dds-button-subtle-icon-neutral-enabled).
--dds-timepicker-popup-backgroundThe background color of the popup. Defaults to var(--dds-background-neutral-subtle).
--dds-timepicker-popup-shadowThe box shadow of the popup. Defaults to 0 4px 6px -1px rgb(0 0 0 / 8%), 0 2px 4px -1px rgb(0 0 0 / 6%).
--dds-timepicker-padding-xsThe padding for extra small size. Defaults to var(--dds-spacing-200).
--dds-timepicker-padding-smThe padding for small size. Defaults to var(--dds-spacing-200).
--dds-timepicker-padding-lgThe padding for large size. Defaults to var(--dds-spacing-300).
--dds-timepicker-padding-horizontalThe horizontal padding. Defaults to var(--dds-spacing-300).
--dds-timepicker-padding-verticalThe vertical padding. Defaults to var(--dds-spacing-200).
--dds-timepicker-gapThe gap between elements. Defaults to var(--dds-spacing-100).
--dds-timepicker-icon-gapThe gap between icons. Defaults to var(--dds-spacing-200).
--dds-timepicker-action-gapThe gap between action elements. Defaults to var(--dds-spacing-200).
--dds-timepicker-action-paddingThe padding for action elements. Defaults to var(--dds-spacing-300).
--dds-timepicker-clear-icon-widthThe width of the clear icon. Defaults to var(--dds-spacing-800).
--dds-timepicker-dropdown-icon-rightThe right position of the dropdown icon. Defaults to var(--dds-spacing-600).
--dds-timepicker-min-widthThe minimum width of the timepicker. Defaults to 7.5rem.
How to Use CSS Custom Properties

CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:

Method 1: Inline styles (Quick customization)

<dap-ds-timepicker
  style="--dds-timepicker-background: value; --dds-timepicker-border-color: value;">
  Timepicker
</dap-ds-timepicker>

Method 2: CSS classes (Reusable styles)

.my-custom-dap-ds-timepicker {
  --dds-timepicker-background: value;
  --dds-timepicker-border-color: value;
  --dds-timepicker-border-width: value;
}
<dap-ds-timepicker class="my-custom-dap-ds-timepicker">
  Timepicker
</dap-ds-timepicker>

Method 3: Global theme customization

/* Apply to all instances */
dap-ds-timepicker {
  --dds-timepicker-background: value;
  --dds-timepicker-border-color: value;
}

CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.

Components Time grid <dap-ds-time-grid/> Attributes
PropertyTypeDefaultDescription
selectedHournumber12The currently selected hour (0-23).
selectedMinutenumber0The currently selected minute (0-59).
selectedSecondnumber0
minTimestring'00:00'The minimum selectable time (format: 'HH:mm').
maxTimestring'23:59'The maximum selectable time (format: 'HH:mm').
stepnumber5The step interval in minutes.
localestring'en'The locale for time formatting.
showSecondsbooleanfalse
secondsStepnumber1
disabledTime`(
hour: number,
minute: number,
second?: number,
) => boolean , undefined`
hideDisabledTimesbooleanfalse
presetsTimePreset[], undefined
Slots

No slots available.

Events
Event NameDescriptionType
dds-changeFired when time selection changes.{detail: TimeSelection }
dds-closeFired when the time grid should close.{void }
CSS Parts
Part NameDescription
time-gridThe main time grid container.
hour-sectionThe hour selection section.
minute-sectionThe minute selection section.
time-buttonIndividual time selection buttons.
section-header-titleThe title of the section header.
section-header-dividerThe divider between the section header and the time buttons.
time-columnThe time column container.
CSS Custom Properties
Property NameDescription
--dds-time-grid-gapThe gap between time sections (default: var(--dds-spacing-400)).
--dds-time-grid-paddingThe padding around the time grid (default: var(--dds-spacing-0)).
--dds-time-grid-column-gapThe gap between time buttons in columns (default: var(--dds-spacing-200)).
--dds-time-grid-border-radiusThe border radius of the time grid (default: var(--dds-radius-base)).
--dds-time-grid-backgroundThe background color of the time grid (default: var(--dds-background-neutral-subtle)).
--dds-time-grid-transitionThe transition timing for the time grid (default: all 0.2s ease-in-out).
--dds-time-grid-max-widthThe maximum width of the time grid (default: 400px).
--dds-time-grid-column-max-heightThe maximum height of time columns (default: 240px).