Calendar depicts a navigable calendar that can show a selected date, and have the client select another date.

Vertical Layout

March 2025
Su Mo Tu We Th Fr Sa
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
Today, Saturday, March 8, 2025
March 2025
Su Mo Tu We Th Fr Sa
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
Today, Saturday, March 8, 2025
March 2025
Su Mo Tu We Th Fr Sa
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
Today, Saturday, March 8, 2025
Show Markup
<form class="coral-Form coral-Form--vertical u-columnMedium">
  <section class="coral-Form-fieldset">
    <div class="coral-Form-fieldwrapper">
      <label id="label-vertical-0" class="coral-Form-fieldlabel">Label</label>
      <coral-calendar class="coral-Form-field" name="name" labelledby="label-vertical-0"></coral-calendar>
    </div>
  
    <div class="coral-Form-fieldwrapper">
      <label id="label-vertical-1" class="coral-Form-fieldlabel">Required</label>
      <coral-calendar class="coral-Form-field" name="name" labelledby="label-vertical-1" required></coral-calendar>
      <coral-icon class="coral-Form-fieldinfo" icon="infoCircle" size="S" id="coral-form-vertical-calendar-fieldinfo"></coral-icon>
      <coral-tooltip variant="info" placement="right" target="#coral-form-vertical-calendar-fieldinfo">Required Information</coral-tooltip>
    </div>
  
    <div class="coral-Form-fieldwrapper">
      <label id="label-vertical-2" class="coral-Form-fieldlabel">Invalid</label>
      <coral-calendar class="coral-Form-field" name="name" labelledby="label-vertical-2" invalid></coral-calendar>
      <coral-icon class="coral-Form-fielderror" icon="infoCircle" size="S" id="coral-form-vertical-calendar-fielderror"></coral-icon>
      <coral-tooltip variant="error" placement="right" target="#coral-form-vertical-calendar-fielderror">Error Message</coral-tooltip>
    </div>
  </section>
</form>

Aligned Layout

March 2025
Su Mo Tu We Th Fr Sa
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
Today, Saturday, March 8, 2025
March 2025
Su Mo Tu We Th Fr Sa
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
Today, Saturday, March 8, 2025
March 2025
Su Mo Tu We Th Fr Sa
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
Today, Saturday, March 8, 2025
Show Markup
<form class="coral-Form coral-Form--aligned u-columnLarge">
  <section class="coral-Form-fieldset">
    <div class="coral-Form-fieldwrapper">
      <label id="label-aligned-0" class="coral-Form-fieldlabel">Label</label>
      <coral-calendar class="coral-Form-field" name="name" labelledby="label-aligned-0"></coral-calendar>
    </div>
  
    <div class="coral-Form-fieldwrapper">
      <label id="label-aligned-1" class="coral-Form-fieldlabel">Required</label>
      <coral-calendar class="coral-Form-field" name="name" labelledby="label-aligned-1" required></coral-calendar>
      <coral-icon class="coral-Form-fieldinfo" icon="infoCircle" size="S" id="coral-form-aligned-calendar-fieldinfo"></coral-icon>
      <coral-tooltip variant="info" placement="right" target="#coral-form-aligned-calendar-fieldinfo">Required Information</coral-tooltip>
    </div>
  
    <div class="coral-Form-fieldwrapper">
      <label id="label-aligned-2" class="coral-Form-fieldlabel">Invalid</label>
      <coral-calendar class="coral-Form-field" name="name" labelledby="label-aligned-2" invalid></coral-calendar>
      <coral-icon class="coral-Form-fielderror" icon="infoCircle" size="S" id="coral-form-aligned-calendar-fielderror"></coral-icon>
      <coral-tooltip variant="error" placement="right" target="#coral-form-aligned-calendar-fielderror">Error Message</coral-tooltip>
    </div>
  </section>
</form>

The following examples demonstrate usage of the JavaScript API's for Coral.Calendar.

October 2014
Su Mo Tu We Th Fr Sa
28 29 30 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8
Thursday, October 23, 2014 selected

The following JavaScript manually initializes the component on page initialization and adds it to the DOM.

<script>
$(document).ready(function() {
  var calendar = new Coral.Calendar().set({
    id: 'myCalendar',
    min: new Date(2014,8,1),
    max: new Date(2014,11,31),
    valueAsDate: new Date(2014,9,23)
  });
  document.getElementById('constructorExample').appendChild(calendar);
})
</script>
<coral-calendar class="coral3-Calendar" valueformat="YYYY-MM-DD" role="region" id="myCalendar"><input handle="input" type="hidden" name="" value="2014-10-23">
<div class=" coral3-Calendar-calendarHeader">
<div handle="heading" class=" coral-Heading coral-Heading--2" id="coral-id-0" role="heading" aria-live="assertive" aria-atomic="true"></div>
<button is="coral-button" class="coral3-Button coral3-Calendar-prevMonth coral3-Button--minimal" size="M" variant="minimal" type="button" handle="prev" icon="chevronLeft" iconsize="XS" aria-label="Previous" title="Previous"><coral-icon class="coral3-Icon" icon="chevronLeft" size="XS"></coral-icon><coral-button-label></coral-button-label></button>
<button is="coral-button" class="coral3-Button coral3-Calendar-nextMonth coral3-Button--minimal" size="M" variant="minimal" type="button" handle="next" icon="chevronRight" iconsize="XS" aria-label="Next" title="Next"><coral-icon class="coral3-Icon" icon="chevronRight" size="XS"></coral-icon><coral-button-label></coral-button-label></button>
</div>
<div class=" coral3-Calendar-calendarBody" handle="body" role="grid" tabindex="0" aria-readonly="true"></div></coral-calendar>

Getting the value

The following will display the above component's value in an alert.
<script>
function displayValue() {
  var value = document.querySelector('#myCalendar').value;
  alert('The value is ' + value + '.');
}
</script>

Setting the value

The following will set the above component value to December 5th 2014.
<script>
  function setValue() {
    var calendar = document.querySelector('#myCalendar');
    calendar.valueAsDate = new Date(2014,11,5);
  }
</script>

Responding to user interaction

The following example shows how to detect changes performed by the user.
<script>
  $(document).ready(function () {
    var eventLog = $('#calendarLog');
    document.querySelector('#myCalendar').on('change', function(event) {
      var value = event.target.value;
      eventLog.log('Calendar new value: ' + value);
    });
  });
</script>

Working with locales

The following example sets up the component to use the appropriate date formatting for the specified page locale (e.g. <html lang="fr-FR">). Requires moment-with-locales.js.

<script>
$(document).ready(function() {
  moment.locale(document.documentElement.lang || window.navigator.language || 'en');
  var calendar = new Coral.Calendar().set({
    id: 'myCalendar',
    min: new Date(2014,8,1),
    max: new Date(2014,11,31),
    valueAsDate: new Date(2014,9,23),
    startDay: moment.localeData().firstDayOfWeek()
  });
})
</script>

Note: moment-with-locales.js provides support to close to 100 locales. If maintaining minimal footprint is critical to your product, it's possible to generate a custom version (moment-with-locales.custom.js) that limits support to a set of languages you can specify.

Log

Coral.Calendar API

Constructor

JavaScript:

new Coral.Calendar() or document.createElement('coral-calendar')

HTML Tag:

<coral-calendar>

Extends

Instance Properties

instance.disabled {Boolean}

Reflected
Whether this field is disabled or not.
Inherited From:
Default Value:
  • false
HTML Attribute:
  • disabled

instance.headerFormat {String}

The format used to display the current month and year. See http://momentjs.com/docs/#/displaying/ for valid format string options.
Default Value:
  • "MMMM YYYY"
HTML Attribute:
  • headerformat

instance.hidden {Boolean}

Reflected
Whether this component is hidden or not.
Inherited From:
Default Value:
  • false
HTML Attribute:
  • hidden

instance.invalid {Boolean}

Reflected
Whether the current value of this field is invalid or not.
Inherited From:
Default Value:
  • false
HTML Attribute:
  • invalid

instance.labelledBy {String}

Reference to a space delimited set of ids for the HTML elements that provide a label for the formField. Implementers should override this method to ensure that the appropriate descendant elements are labelled using the aria-labelledby attribute. This will ensure that the component is properly identified for accessibility purposes. It reflects the aria-labelledby attribute to the DOM.
Inherited From:
Default Value:
  • null
HTML Attribute:
  • labelledby

instance.max {String | Date}

The max selectable date in the Calendar view. When passed a string, it needs to be 'YYYY-MM-DD' formatted.
Default Value:
  • null
HTML Attribute:
  • max

instance.min {String | Date}

The minimal selectable date in the Calendar view. When passed a string, it needs to be 'YYYY-MM-DD' formatted.
Default Value:
  • null
HTML Attribute:
  • min

instance.name {String}

Reflected
Name used to submit the data in a form.
Inherited From:
Default Value:
  • ""
HTML Attribute:
  • name

instance.readOnly {Boolean}

Reflected
Whether this field is readOnly or not. Indicating that the user cannot modify the value of the control. This is ignored for checkbox, radio or fileupload.
Inherited From:
Default Value:
  • false
HTML Attribute:
  • readonly

instance.required {Boolean}

Reflected
Whether this field is required or not.
Inherited From:
Default Value:
  • false
HTML Attribute:
  • required

instance.startDay {Number}

Defines the start day for the week, 0 = Sunday, 1 = Monday etc., as depicted on the calendar days grid.
Default Value:
  • 0
HTML Attribute:
  • startday

instance.value {String}

The current value. When set to 'today', the value is coerced into the clients local date expressed as string formatted in accordance to the set valueFormat.
Default Value:
  • ""
HTML Attribute:
  • value

instance.valueAsDate {Date}

The value returned, or set, as a Date. If the value is '' it will return null.
Default Value:
  • null

instance.valueFormat {String}

Reflected
The format to use on expressing the selected date as a string on the value attribute. See http://momentjs.com/docs/#/displaying/ for valid format string options.
Default Value:
  • "YYYY-MM-DD"
HTML Attribute:
  • valueformat

Methods

instance.focus

sets focus to appropriate descendant

instance.get

Get the value of a property.
Parameters:
Name Type Description
property String The name of the property to fetch the value of.
Returns:
Property value. {*}
Inherited From:

instance.hide

Hide this component.
Returns:
this, chainable {Coral.Component}
Inherited From:

instance.off

Remove an event listener.
Parameters:
Name Type Optional Description
eventName String No
The event name to stop listening for.
selector String Yes
The selector that was used for event delegation.
func function No
The function that was passed to on().
useCapture Boolean Yes
Only remove listeners with useCapture set to the value passed in.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.on

Add an event listener.
Parameters:
Name Type Optional Default Description
eventName String No
The event name to listen for.
selector String Yes
The selector to use for event delegation.
func function No
The function that will be called when the event is triggered.
useCapture Boolean Yes
Whether or not to listen during the capturing or bubbling phase.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.remove

Non-destructively remove this element. It can be re-added by simply appending it to the document again. It will be garbage collected if there are no more references to it.
Inherited From:

instance.set

Set a single property.
Parameters:
Name Type Description
property String The name of the property to set.
value * The value to set the property to.
silent Boolean If true, events should not be triggered as a result of this set.
Returns:
this, chainable. {Coral.Component}
Inherited From:

instance.show

Show this component.
Returns:
this, chainable {Coral.Component}
Inherited From:

instance.trigger

Trigger an event.
Parameters:
Name Type Optional Default Description
eventName String No
The event name to trigger.
props Object Yes
Additional properties to make available to handlers as event.detail.
bubbles Boolean Yes
Set to false to prevent the event from bubbling.
cancelable Boolean Yes
Set to false to prevent the event from being cancelable.
Returns:
CustomEvent object {CustomEvent}
Inherited From:

Events

change

Triggered when the value has changed. This event is only triggered by user interaction.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:

coral-component:attached

Triggered when the component is attached to the DOM.
Callback Parameters:
Name Type Description
event Object Event object.
Inherited From:
Deprecated:
  • since 1.14.0, use MutationObserver instead.

    coral-component:detached

    Triggered when the component is detached to the DOM.
    Callback Parameters:
    Name Type Description
    event Object Event object.
    Inherited From:
    Deprecated:
    • since 1.14.0, use MutationObserver instead.

      coral-component:ready

      Triggerred when the component has been upgraded and is ready for use.
      Callback Parameters:
      Name Type Description
      event Object Event object.
      Inherited From:
      Deprecated:
      • since 1.9.0, use Coral.commons.ready() instead.