Date Input #
Date Input component is a combination of Date Picker and Input components. You can find usage examples using following links:
Examples #
Basic usage #
Input props #
You can pass properties to VaDateInput
Parsing #
You can pass the parse function to VaDateInput which will parse input text like you want to. This way you can use any format that you want. For example, you can use date-fns to parse date string. By default we parse this input using standard Date.parse
method.
Advanced formatting #
If you need specific format for multiple or range modes you can use.
View #
You can set specific view for date picker. With view
prop you can define how date picker will displayed, year and month that will be shown.
You can easily use your format functions for all VaDateInputs using Global Config feature.
import { createVuestic } from 'vuestic-ui'
createApp(App)
.use(createVuestic({
config: {
icons: [ /* ... */ ],
components: {
VaDateInput: {
formatDate: (date) => {
// ...
},
parseDate: (str) => {
// ...
}
}
},
colors: { /* ... */ },
},
}))
.mount('#app')
Validation #
Validation works the same way as VaInput
validation, except rules functions should accept Date
instead of string
.
Mode #
You can use date input in three different ways. By default date input uses auto
mode. This means that mode
will be chosen based on modelValue
. There is three modes: single
, multiple
and range
. Different modes require different model values.
Single mode
Multiple mode
Range mode
Formatting #
You can pass the format function to VaDateInput which will format input text like you want to. This way you can use any format that you want. For example, you can use date-fns.
Date Manual Input #
You can add manual-input
attribute to allow user input text from keyboard manually.
IsOpen #
IsOpen prop allows you to force show dropdown as opened.
Reset on close #
There is a prop resetOnClose
for range mode. If user selected incomplete range and closed dropdown, then used last complete value.
Reset on close
Don't reset on close
API #
Props #
Name | Description | Types | Default |
---|---|---|---|
allowedDays | Function that accepts date and return |
| - |
allowedMonths | Function that accepts date and return |
| - |
allowedYears | Function that accepts date and return |
| - |
anchor |
| - | |
anchorSelector | Anchor CSS selector instead of passing slot |
|
|
ariaLabel | The aria-label of the anchor slot |
|
|
ariaNextPeriodLabel | The aria-label of the "next period" button |
|
|
ariaPreviousPeriodLabel | The aria-label of the "previous period" button |
|
|
ariaResetLabel | The aria-label of the "reset" button |
|
|
ariaSelectedDateLabel | The aria-label of the input of the component if aria-label is not set |
|
|
ariaSwitchViewLabel | The aria-label of the "switch view" button |
|
|
ariaToggleDropdownLabel | The aria-label of the "toggle dropdown list" button |
|
|
autoPlacement | If dropdown doesn't fit viewport, it will be placed automatically to fit viewport |
|
|
background | The color name of the background color |
| - |
child:middleButton |
| - | |
child:nextButton |
| - | |
child:prevButton |
| - | |
clearable | Adds a button to reset the input field value |
|
|
clearableIcon | Sets the cleaning button icon. |
|
|
clearValue | Default input field value |
| - |
closeOnAnchorClick | Dropdown will be closed when anchor is clicked |
|
|
closeOnChange |
|
| |
closeOnClickOutside | Dropdown will be closed when clicked outside dropdown content and anchor |
|
|
closeOnContentClick | Dropdown will be closed when clicked inside dropdown content |
|
|
closeOnFocusOutside |
|
| |
color | Sets input color |
|
|
contentClass |
|
| |
counter |
| - | |
cursor | Dropdown will be rendered relative to cursor position |
|
|
delimiter | The delimiter used when turning model value to string |
|
|
dirty | Sets the dirty state of the component |
|
|
disabled | Disable the input |
|
|
endYear | Last year that user can choose. By default is current year plus 50 years |
|
|
error | Sets input state to error |
| - |
errorCount | Number of error messages displayed |
|
|
errorMessages | Displays a list of error messages or message if using a string |
| - |
firstWeekday | Name of first weekday. Can be |
|
|
format | Function that accepts picker value and should transform it to text for input |
| - |
formatDate | Function that accepts picker value and transforms it to the string |
| (d) => d.toLocaleDateString() |
formatValue |
| - | |
hideWeekDays | Hide weekday names on top of day picker |
|
|
highlightToday | If |
|
|
highlightWeekend | If |
|
|
hoverOutTimeout | Time in |
|
|
hoverOverTimeout | Time in |
|
|
icon | Sets an icon. |
|
|
immediateValidation | Sets the validation to be performed when the component is mounted |
|
|
innerLabel |
|
| |
inputAriaDescribedby |
| - | |
inputAriaLabel |
|
| |
inputAriaLabelledby |
| - | |
isContentHoverable | If true, dropdown content will be hoverable |
|
|
isOpen | Value for dropdown. If |
| - |
keepAnchorWidth | If true, dropdown content will have exact same width as anchor |
|
|
label | Sets input label |
|
|
leftIcon | Sets the icon position to the left. |
|
|
loading | Indicates that something is loading (spinner icon). |
|
|
manualInput | Allows user to manually input date in VaInput |
|
|
messages | Displays a list of messages or message if using a string |
|
|
mode | Specify if picker value is single date, multiple dates or date range. |
|
|
modelValue | Date, date array or date period |
| - |
monthNames | Array of 12 month names |
|
|
name | Applies |
| - |
offset | Dropdown content will be moved by main and cross axis according to current |
|
|
parse | Function that transforms input field text to date, date array or date period |
| - |
parseDate | Function that transforms input field text to date |
| - |
placeholder | Sets input placeholder |
|
|
placement | Sets the placement of the dropdown content. More about placements |
|
|
preset | Named preset combination of component props. |
| - |
rangeDelimiter | The delimiter used when turning model value to string |
|
|
readonly | Puts input in readonly state |
|
|
requiredMark | Adds required mark to the label |
|
|
resetOnClose | If true, range value will be reset to previous valid value |
|
|
role | Sets the |
|
|
rules | Accepts an array of functions that take an input value as an argument and return either true / false or a string with an error message |
|
|
showOtherMonths | If |
|
|
startYear | First year that user can choose. By default is 1970 |
|
|
stateful | Add possibility to work with component without setting |
|
|
stickToEdges | Dropdown will not be rendered outside of viewport. It will be moved in opposite direction. |
|
|
success | Sets input state to success |
|
|
target | Navigation target, More info here. |
| - |
teleport | Element where content will be rendered |
| - |
trigger | Action that will triggered when open and close dropdown. |
|
|
type | This prop will specify which value user should choose |
|
|
verticalScrollOnOverflow |
|
| |
view | This prop specify which year and month will be shown to user. Also, you can specify type and show year, month or day picker |
| - |
weekdayNames | Array of 7 weekday names |
|
|
weekends | Function that accepts date and return |
| - |
weekendsColor | Color of the weekend cells (theme string or HEX string). |
| - |
Events #
Name | Description |
---|---|
blur | On blur. |
clear | Emitted if select value has been cleared |
click:day | The event is triggered when clicked the day cell |
click:month | The event is triggered when clicked the month cell |
click:year | The event is triggered when clicked the year cell |
focus | On focus. |
hover:day | The event is triggered when the mouse hover the day cell |
hover:month | The event is triggered when the mouse hover the month cell |
hover:year | The event is triggered when the mouse hover the year cell |
update:dirty | Fires when the dirty state changes |
update:error | Fires when the error state changes |
update:errorMessages | Fires when the error messages change |
update:isOpen | The event is triggered when the component needs to toggle the 'is-open' |
update:modelValue | The event is triggered when the component needs to change the model. Is also used by |
update:text | The event is triggered when the component needs to change the input text |
update:view | The event is triggered when the component needs to change the view |
Slots #
Name | Description |
---|---|
append | |
appendInner | |
buttonNext | |
buttonPrev | |
day | |
header | |
month | |
prepend | |
prependInner | |
weekday | |
year |
Css Variables #
Name | Default Value |
---|---|
--va-date-input-width | var(--va-form-element-min-width-small) |