Skip to content

Component ​

ts
import { DurationInput } from 'semantic-duration-input'

Props ​

PropTypeDefault
modelValuenumber | string | nullnullThe duration, see valueFormat
valueFormat'minutes' | 'seconds' | 'ms' | 'iso' | { toModel, fromModel }'minutes'How v-model stores the duration, see Value formats
precision'minute' | 'second''minute''second' accepts 30s and h:mm:ss and keeps seconds
localesDurationLocale[][en, de]Which unit names and separator words are accepted, see Locales
localeDurationLocalefirst of localesLanguage of the normalized text and the messages
displayStyle'short' | 'long''short'1d 2h 30min vs 1 day 2 hours 30 minutes
displayUnitsUnitName[]['day', 'hour', 'minute'] (+ 'second')Units used in the normalized text, including custom ones
implicitUnitsbooleantrue1h30 means 1h 30min
defaultUnitUnitName–Unit for a bare number, e.g. 'minute'
customUnitsCustomUnits–Units of your own and other lengths for day and week, see Custom units
min / maxnumber | string–Inclusive bounds: a number in the model's unit, or text like '8h' (out_of_range)
stepnumber | string | false'15m'Arrow-key step
snapToStepbooleanfalseRound to the nearest step on blur/Enter
clampbooleanfalseClamp to min/max instead of reporting out_of_range
validateOn'eager' | 'blur' | 'input''eager'When errors are shown, see Behaviour
requiredbooleanfalseEmpty input is an empty error
disabledbooleanfalse
readonlybooleanfalseRead-only: no stepping, reverting or presets menu
presets(number | string | { label?, value })[]–Suggestions menu, see Presets. Built-in field only
size'sm' | 'md' | 'lg''md'Field size. With as, any value is passed on
variant'outline' | 'soft' | 'ghost''outline'Field look. With as, any value is passed on
previewbooleanfalseShows the normalized value inside the field while typing, and announces it to screen readers. Built-in field only
formatPreview(seconds, { normalized, text, value, locale }) => string | null–Renders the preview instead of the normalized text, see Custom preview
messages{ [key]: string } | false–Overrides the error texts, or false to hide them, see Error messages
ui{ root?, field?, input?, leading?, trailing?, preview?, message?, menu?, option? }–Extra classes per part, see Styling
unstyledbooleanfalseDrops all default classes
asComponent | string–Renders another input component, see Integrations
invalidProps(state) => props–Maps the invalid state onto the as component's props

Attributes ​

  • Built-in field: class and style go to the root element. name goes to a hidden input carrying the model value (see Forms). All other attributes (id, placeholder, data-*, ...) go to the <input>.
  • With as or the renderless slot: class and style go to the as component or into inputProps, together with the other attributes.

Events ​

EventPayload
update:modelValuevalue | nullThe model changed
errorcode | nullThe shown error changed (see validateOn). Codes: empty, invalid_format, unknown_unit, missing_unit, out_of_range

Slots ​

Slot
leadingBefore the input: an icon, a unit hint. With as, all named slots are passed on to that component
trailingAfter the input: a unit hint, a clear button
defaultRenderless mode, see the slot props

Exposed methods ​

Through a template ref:

MethodReturns
focus()Focuses the input
blur()Blurs the input, which normalizes the text
commit()booleanNormalizes the text, shows any error and writes the value, like blur. Returns whether the text was valid
validate()booleanShows the current error, whatever validateOn is, and returns whether the text is valid
revert()booleanGoes back to the last committed value. Returns whether anything changed
stepBy(direction, seconds?)Steps like the arrow keys, e.g. stepBy(-2) or stepBy(1, 3600)

Plugin ​

ts
import { plugin } from 'semantic-duration-input'

app.use(plugin, defaults?)

Registers <DurationInput> globally. The optional defaults apply to every instance, see App-wide defaults. They are provided under the DURATION_INPUT_DEFAULTS injection key, which you can also provide yourself for a subtree.

Types ​

Exported from semantic-duration-input, besides everything from /core:

Type
DurationInputPropsThe props above
DurationInputDefaultsApp-wide defaults: the props except min, max, required, disabled and readonly
DurationInputUi, DurationInputPartThe ui prop and its part names
DurationInputSize, DurationInputVariant, DurationInputVariantsBuilt-in sizes and looks
DurationPreset, DurationPresetItemA presets entry, and a resolved one as given to the slot
DurationInputSlotPropsProps of the renderless slot
InvalidPropsFn, InvalidStateAn invalidProps function and what it receives
DurationInputOptions, ValidateOnOptions of useDurationInput
PreviewFormatter, PreviewContextA formatPreview function and what it receives

Released under the MIT License.