Theme
Version
GitHub PyPI Discord
On this page

TimeInput

Use CTimeInput when a browser-native time editor is the shortest path. It preserves platform keyboard, touch picker, validation, reset, and Form behavior while keeping the application value locale-neutral.

Collect one time

Compose the control in CField for its visible label, description, error, and shared state. A standalone input needs an accessible name through attrs or an external native label.

<c-CField required>
  <c-fill name="label">Start time</c-fill>
  <c-fill name="default"><c-CTimeInput name="start" /></c-fill>
</c-CField>
Collect one time
Show code
import citry_ui
from citry import Component, citry

citry.register_library(citry_ui)


class BasicTimeInput(Component):
    template = """
      <c-CField required>
        <c-fill name="label">Start time</c-fill>
        <c-fill name="description">Choose when the session starts.</c-fill>
        <c-fill name="default"><c-CTimeInput name="start" /></c-fill>
      </c-CField>
    """


preview = BasicTimeInput()
preview  # noqa: B018

Python composition accepts an exact zone-free datetime.time. Localized text, offset-aware times, fractional seconds, and noncanonical strings are rejected.

Constrain a periodic time range

min, max, and positive integer step map to native time constraints. A minimum later than the maximum deliberately expresses a wrapped interval such as 23:00 through 02:00.

Constrain a native time
Show code
import citry_ui
from citry import Component, citry

# ruff: noqa: E501 - embedded Citry templates remain readable

citry.register_library(citry_ui)


class TimeInputConstraints(Component):
    template = """
      <section style="display:grid;gap:1rem;max-width:22rem">
        <label>Office appointment <c-CTimeInput name="office" min="09:00" max="17:00" c-step="900" value="09:30" /></label>
        <label>Overnight window <c-CTimeInput name="overnight" min="23:00" max="02:00" value="23:30" /></label>
      </section>
    """


preview = TimeInputConstraints()
preview  # noqa: B018

The server must validate submitted values again; the component never silently clamps or rounds.

Use Forms and client control

name contributes exactly one canonical value. Disabled inputs are omitted; readonly inputs remain submitted. Client value accepts a canonical string or null, and omission releases control at the latest accepted value.

Submit and reset a time
Show code
import citry_ui
from citry import Component, citry

# ruff: noqa: E501 - embedded Citry templates remain readable

citry.register_library(citry_ui)


class TimeInputForm(Component):
    template = """
      <form x-data="{result:'Submit to inspect FormData'}" @submit.prevent="result=JSON.stringify(Object.fromEntries(new FormData($event.target)))">
        <c-CField required>
          <c-fill name="label">Delivery time</c-fill>
          <c-fill name="default"><c-CTimeInput name="delivery" value="14:30" /></c-fill>
        </c-CField>
        <c-CButton type="submit">Submit</c-CButton>
        <c-CButton type="reset" variant="outline">Reset</c-CButton>
        <output x-text="result">Submit to inspect FormData</output>
      </form>
    """


preview = TimeInputForm()
preview  # noqa: B018

Understand locale behavior

The DOM value and FormData stay HH:MM or HH:MM:SS; the browser chooses the visible segment order, hour cycle, picker, and native validation prose. Use CTimePicker when Citry i18n must own the visible choice labels.

Compare states and styles

Outline, filled, and plain variants combine with sm, md, and lg sizes. Public variables style the native control without replacing its semantics.

Compare TimeInput states
Show code
import citry_ui
from citry import Component, citry

citry.register_library(citry_ui)


class TimeInputStates(Component):
    template = """
      <section style="display:grid;grid-template-columns:repeat(auto-fit,minmax(12rem,1fr));gap:1rem">
        <label>Outline <c-CTimeInput value="09:00" /></label>
        <label>Filled <c-CTimeInput value="10:15" variant="filled" size="sm" /></label>
        <label>Plain readonly <c-CTimeInput value="11:30" variant="plain" size="lg" readonly /></label>
        <label>Invalid <c-CTimeInput value="12:45" invalid /></label>
        <label>Disabled <c-CTimeInput value="13:00" disabled /></label>
      </section>
    """


preview = TimeInputStates()
preview  # noqa: B018

CTimeInput owns no translation keys. Labels and errors belong to the application; the platform owns the native editor and its prose.

API reference

Inputs

CTimeInput server inputs

Server inputs are passed in a template through <c-CTimeInput ... /> or in Python through CTimeInput(...).

InputTypeDefaultEffect
valueCTimeInputValue | None (CTimeInputValue)NoneSets the initial and reset canonical time or empty value.
namestr | NoneNoneSets the native Form field name.
formstr | NoneNoneAssociates the input with an external native Form ID.
idstr | NonegeneratedSets the public native input ID.
minCTimeInputValue | None (CTimeInputValue)NoneSets the inclusive native minimum and may start a wrapped range.
maxCTimeInputValue | None (CTimeInputValue)NoneSets the inclusive native maximum and may end a wrapped range.
stepint60Sets the exact positive native step in seconds.
requiredbool | NoneNoneEnables native empty-value validity outside Field; Field owns it inside Field.
disabledbool | NoneNoneBlocks interaction and Form participation outside Field; Form disabledness also wins.
readonlybool | NoneNoneKeeps a focusable submitted value while blocking native edits.
invalidbool | NoneNoneAdds application invalid state to revealed native validity.
autocompletestr | NoneNoneSets a native autofill hint.
variant"outline" | "filled" | "plain" (CTimeInputVariant)"outline"Selects outer native-control treatment.
size"sm" | "md" | "lg" (CTimeInputSize)"md"Selects coordinated sizing.
class_CClassValue | None (CClassValue)NoneAdds classes to the native root and merges with attrs.
styleCStyleValue | None (CStyleValue)NoneAdds styles to the native root and merges with attrs.
attrsMapping[str, object] | NoneNoneAdds copied allowed native attributes without replacing owned identity state constraints or runtime markers.

CTimeInput client inputs

Client inputs are passed in the browser through the $c-props="{ ... }" attribute on <c-CTimeInput />.

InputTypeOmitted behaviorEffect
valuecanonical string | nullReleases control at the latest accepted value.Controls the exact native value while supplied.
mincanonical string | nullUses the server minimum.Replaces or removes the inclusive minimum.
maxcanonical string | nullUses the server maximum.Replaces or removes the inclusive maximum.
steppositive integerUses the server step.Replaces the native seconds step.
requiredbooleanUses server or Field state.Controls standalone required validity.
disabledbooleanUses server or owner state.Controls interaction and Form participation.
readonlybooleanUses server or owner state.Controls focusable nonmutable state.
invalidbooleanUses server or Field state.Controls application invalid state.
variant"outline" | "filled" | "plain" (CTimeInputVariant)Uses the server input.Controls presentation.
size"sm" | "md" | "lg" (CTimeInputSize)Uses the server input.Controls coordinated sizing.

Slots

-

Events

-

Methods

-

CSS

CSS variables to theme the components. Set them on an ancestor or the component itself.

CTimeInput CSS variables

Apply these variables to CTimeInput or one of its ancestors.

VariableTypePurposeDefault
--cui-time-input-backgroundcolorNative control background.Canvas
--cui-time-input-foregroundcolorNative time text and indicator foreground.CanvasText
--cui-time-input-border-colorcolorResting border.Mixed CanvasText.
--cui-time-input-hover-border-colorcolorHover border.Stronger mixed CanvasText.
--cui-time-input-focus-colorcolorFocus border and outline.Highlight
--cui-time-input-invalid-border-colorcolorInvalid border.Theme error.
--cui-time-input-disabled-backgroundcolorDisabled background.Muted Canvas.
--cui-time-input-radiuslengthOuter corner radius.0.5rem
--cui-time-input-heightlengthMinimum block size.2.5rem
--cui-time-input-inline-paddinglengthLogical inline inset.0.75rem
--cui-time-input-block-paddinglengthLogical block inset.0.5rem
--cui-time-input-font-sizelengthTime text size.1rem
--cui-time-input-min-inline-sizelengthPreferred minimum width before container clamping.10rem

Attributes

HTML attributes defined on the components that you can refer to for CSS, inspection, and testing. Read-only.

CTimeInput attributes

AttributeElementTypeMeaning
typeNative root input"time"Selects browser-owned wall-clock editing and picker behavior.
valueNative root inputcanonical time | absentCarries the initial and reset time.
minNative root inputcanonical time | absentSets inclusive native minimum validity.
maxNative root inputcanonical time | absentSets inclusive native maximum validity.
stepNative root inputpositive integerSets the seconds step grid.
aria-invalidNative root input"true" | absentMirrors application or revealed native invalidity.
data-emptyNative root inputpresent | absentMirrors an empty canonical value.
data-requiredNative root inputpresent | absentMirrors effective requiredness.
data-disabledNative root inputpresent | absentMirrors effective disabledness.
data-readonlyNative root inputpresent | absentMirrors effective readonly state.
data-invalidNative root inputpresent | absentMirrors application or revealed native invalidity.
data-variantNative root inputCTimeInputVariant (CTimeInputVariant)Mirrors visual treatment.
data-sizeNative root inputCTimeInputSize (CTimeInputSize)Mirrors coordinated sizing.

Selectors

Selectors for the DOM nodes in the components that you can use for CSS, inspection, and testing.

CTimeInput selectors

SelectorElementPurpose
[data-citry-ui-part="time-input"]Native root inputStable styling state Form focus event and attrs destination.

Interfaces

Aliases and data shapes referenced above.

Input type aliases

InterfaceDefinition
CTimeInputValuetime | str
CTimeInputVariantLiteral["outline", "filled", "plain"]
CTimeInputSizeLiteral["sm", "md", "lg"]
CClassValuestr | Mapping[str, bool] | Sequence[CClassValue]
CStyleValuestr | Mapping[str, object] | Sequence[CStyleValue]

Translation keys

-