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>
Importing
import { DapDSTimePicker } from 'dap-design-system/dist/dds'
Importing React
import { DapDSTimePickerReact } from 'dap-design-system/dist/react'
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.
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.
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.
Components Time grid <dap-ds-time-grid/> Attributes
PropertyTypeDefaultDescription
selectedHournumber12The currently selected hour (0-23).
selectedMinutenumber0The currently selected minute (0-59).
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.
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).