Q2 Calendar

Updated:

Provides an input field that triggers a popover date picker.

Documentation

Attributes API

The q2-calendar element has several properties that support text localization. Those properties are indicated by the localizable badge below.

PropertyAttributeTypeDefaultDescription
assumeassumestring

Use assume to detect the year automatically based on today's date when the user presses the Escape key or the Blur mouse event occurs.

Type

type Assume = 'current' | 'future' | 'past';

Example

Always assume the current year:

element.assume = 'current';

Assume the next year if the type mm/dd is later than today:

element.assume = 'future';

Assume the previous year if the type mm/dd is earlier than today:

element.assume = 'past';
calendarLabelcalendar-labelstring

A label shown at the top of the popover date picker.

Example

element.calendarLabel = "Transfer date";
cutoffTimecutoff-timestring

Specifies a time of day after which a date is no longer valid.

Must be a valid ISO date string.

Example

// 2:00 PM local US Central Daylight Time
element.cutoffTime = '2020-10-15T14:00:00.000-05:00';

// UTC time 19:00
element.cutoffTime = '2020-10-15T19:00:00.000Z';
daysOfWeekChecksumdays-of-week-checksumnumber


The most concise way to define valid days of the week. Each day of the week has a checksum value:

  • Sunday = 1
  • Monday = 2
  • Tuesday = 4
  • Wednesday = 8
  • Thursday = 16
  • Friday = 32
  • Saturday = 64

Sum the checksum values of your desired valid days, and set daysOfWeekChecksum to that summed value.

Example

element.daysOfWeekChecksum = 127; // All days of the week are valid
element.daysOfWeekChecksum = 62; // Only weekdays are valid
element.daysOfWeekChecksum = 65; // Only Saturday and Sunday are valid
disableddisabledbooleanfalse

When true, the field is disabled.

Example

element.disabled = true;
disabledMsgdisabled-msgstring
Localizable

Text that appears within the q2-calendar field when it is disabled.

Example

element.disabledMsg = "Please select an account first";
disclaimerdisclaimerstring

Text that appears at the bottom of the popover date picker.

Example

element.disclaimer = "Weekend delivery may incur additional fees";
displayFormatdisplay-formatstring

Determines the display format of the date field value. Must follow the date-fns token specification.

Example

element.displayFormat = "MM-dd-yyyy";
endDateend-datestring

Defines the last selectable date in the date picker popover.

Must be a valid ISO date string.

Example

element.endDate = "2019-04-12";
hideLabelhide-labelbooleanfalse

Hides the field's <label> element from view.

Only use when a visible label is impractical.

Example

element.hideLabel = true;
invalidinvalidbooleanfalse

This property is used to show error styles when the calendar is in an errant state.

Example

element.invalid = true;
invalidDatesarray

Defines an explicit date blacklist.

Each entry must be a valid ISO date string.

When explicit date definition like invalidDates is used, other date validity methods like daysOfWeekChecksum are overridden.

Example

element.invalidDates = ['2019-11-23', '2019-12-25'];
labellabelstring

The visible label for the q2-calendar input field.

Example

element.label = "Select a date";
optionaloptionalbooleantrue

When true, appends "(optional)" to the q2-calendar field label and sets aria-required="false".

Example

element.optional = true;
popDirectionpop-directionstring

Use popDirection to force the direction of the pop-up that the calendar displays. If no value is passed the component auto-detects based on the available space below it. The component auto-detection will drop down unless it detects there is not sufficient height left to do so, in which case it will pop up.

Type

type PopDirection = "up" | "down";

Example

element.popDirection = 'up';
startDatestart-datestring

Defines the first selectable date in the date picker popover.

Must be a valid ISO date string.

Example

element.startDate = "2019-02-21";
typeabletypeablebooleanfalse

When true, the user can type in the field.

Example

element.typeable = true;
validDatesarray

Defines a date whitelist.

Each entry must be a valid ISO date string.

When explicit date definition like validDates is used, other date validitity methods like daysOfWeekChecksum are overridden.

Example

element.validDates = ['2019-11-23', '2019-12-25'];
valuevaluestring

The value of the q2-calendar element, e.g. the selected date.

Example

element.value = "2019-1-30";

How to change or clear value using javascript

// change date
element.value = '2022-12-21';

// clear date
element.value = null;

Events API

The q2-calendar element exposes events that can be used to send and receive data from the component.

EventDetails
change

Emitted when a date is selected.

Type

type ChangeEvent = CustomEvent<{ value: string }>;

Example

element.onchange = (event) => {
  this.value = event.detail.value;
}

The lists below contain references to all the CSS variables available for use in the q2-calendar component.

The following CSS variables are available to override the default theme styles of the q2-calendarcomponent.

    The following CSS variables are used by the q2-calendar component and available for theming.