Duration Input
A text field for an amount of time: reads 1h 30m, 90m, 1.5h or 1:30 and stores seconds.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | number | null | null | The duration in seconds, or null for none. In markup, a number of seconds (value="5400"). |
name | string | — | Form field name. The form receives the duration in seconds. |
unit | DurationUnit | m | The unit of a bare number such as 90: w, d, h, m (the default) or s. Arrow Up/Down step by it when there is no step. |
format | DurationFormat | short | How the duration is written once the field is left: short (1h 30m), long (1 hour, 30 minutes) or clock (1:30). |
largest-unit | DurationUnit | d | The largest unit written: with h, two days read 48h. Days by default. |
smallest-unit | DurationUnit | s | The smallest unit written; what is left below it is rounded. Seconds by default. |
day-hours | number | 24 | Hours in a day, d. Time tracking often uses 8. |
week-days | number | 7 | Days in a week, w. Time tracking often uses 5. |
min | number | undefined | — | The shortest valid duration, in seconds. |
max | number | undefined | — | The longest valid duration, in seconds. |
step | number | undefined | — | Seconds the value is rounded to when the field is left (900 rounds to 15 minutes), and the amount Arrow Up/Down add. |
placeholder | string | — | Text shown while the field is empty. Defaults to the translatable e.g. 1h 30m. |
required | boolean | false | Requires a duration before the form can be submitted. |
readonly | boolean | false | Prevents editing while keeping the value in form submission. |
disabled | boolean | false | Prevents interaction and excludes the value from form submission. |
error | boolean | false | Applies the visual error state and sets aria-invalid, showing error-text. |
help | string | — | Helper text shown below the field. |
error-text | string | — | Message shown below the field while error is set. |
aria-label | string | null | null | Accessible name forwarded to the text field. |
Slots
| Name | Description |
|---|---|
icon | Replaces the clock icon before the text. |
Events
| Name | Type | Description |
|---|---|---|
input | InputEvent | Re-dispatched while typing, and when Arrow Up/Down changes the value. |
change | Event | Re-dispatched when the edited text is committed, after the value is rounded to step, and when Arrow Up/Down changes the value. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
icon | The box around the clock icon. |
preview | The preview after the text while typing (= 1 hour, 30 minutes). |
supporting-text | The help text or error message below the field. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-duration-input--min-height | pixel | 36px | The field's height. |
--c2-duration-input--border | border | 1px solid #bcbcc6 | The field's border. |
--c2-duration-input--border-radius | border-radius | 6px | The field's corner radius. |
--c2-duration-input--color | color | #18181b | The text colour. |
--c2-duration-input--background | color | #ffffff | The field's background. |
--c2-duration-input--font-size | font-size | 14px | The text size. |
--c2-duration-input--font-family | font-family | inherit | The text font. |
--c2-duration-input--line-height | pixel | 20px | The text line height. |
--c2-duration-input__value--padding | padding | 6px 12px 6px 10px | Space inside the field. |
--c2-duration-input__value--gap | pixel | 8px | Space between the icon, the text and the preview. |
--c2-duration-input__placeholder--color | color | #71717a | The placeholder colour. |
--c2-duration-input__icon--color | color | #71717a | The clock icon's colour. |
--c2-duration-input__icon--size | pixel | 16px | The clock icon's size. |
--c2-duration-input__preview--color | color | #71717a | The colour of the preview after the text. |
--c2-duration-input__preview--font-size | font-size | 12px | The size of the preview after the text. |
--c2-duration-input__hover--border | border | 1px solid #a1a1aa | The border on hover. |
--c2-duration-input__focus--border | border | 1px solid #0265dc | The border while focused. |
--c2-duration-input__focus--outline | outline | none | The outline while focused. |
--c2-duration-input__focus--outline-offset | pixel | 0px | The outline offset while focused. |
--c2-duration-input__error--border | border | 1px solid #dc2626 | The border while invalid. |
--c2-duration-input__error__focus--outline | outline | none | The outline while invalid and focused. |
--c2-duration-input__read-only--background | color | #fafafa | The background while read-only. |
--c2-duration-input__disabled--opacity | opacity | 0.38 | The opacity while disabled. |
--c2-duration-input__supporting-text--gap | pixel | 4px | Space between the field and its supporting text. |
--c2-duration-input__supporting-text--font-size | font-size | 12px | The supporting text's size. |
--c2-duration-input__supporting-text--line-height | pixel | 16px | The supporting text's line height. |
--c2-duration-input__supporting-text--color | color | #71717a | The help text's colour. |
--c2-duration-input__supporting-text__error--color | color | #dc2626 | The error message's colour. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under duration-input, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
placeholder | e.g. 1h 30m | — |
preview | = {0} | {0} duration |
badInput | Enter a duration like 1h 30m | — |
valueMissing | Enter a duration | — |
rangeUnderflow | Enter {0} or more | {0} min |
rangeOverflow | Enter {0} or less | {0} max |
weekWords | w wk wks week weeks | — |
dayWords | d day days | — |
hourWords | h hr hrs hour hours | — |
minuteWords | m min mins minute minutes | — |
secondWords | s sec secs second seconds | — |