@brightspace-ui/core 3.47.1 → 3.48.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,8 +30,12 @@ Note: All `*-value` properties should be in ISO 8601 calendar date format (`YYYY
30
30
  * `d2l-calendar-selected`: dispatched when a date is selected through click, space, or enter. `e.detail.date` is in ISO 8601 calendar date format (`YYYY-MM-DD`).
31
31
  <!-- docs: end hidden content -->
32
32
 
33
+ ### Methods
34
+
35
+ - `getShownValue()`: returns the date representing the year and month in view as an ISO 8601 calendar date format (`YYYY-MM-DD`).
36
+
33
37
  ## Accessibility
34
38
 
35
39
  The Daylight calendar (`d2l-calendar`) generally follows the W3C's best practice recommendations for a [Date picker dialog](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/datepicker-dialog/). Of note is the keyboard behaviour following the [grid pattern](https://www.w3.org/WAI/ARIA/apg/patterns/grid/).
36
40
 
37
- The W3C recommendations, specifically relating to `attributes` on the calendar's table elements, were followed as much as possible. At the time of development it was not possible to create a calendar with a `grid` role which had the desired appearance, functionality, and supported all browser/screen reader combinations that we support; the expected screen reader experience was replicated as much as possible (e.g., announcing the expected content).
41
+ The W3C recommendations, specifically relating to `attributes` on the calendar's table elements, were followed as much as possible. At the time of development it was not possible to create a calendar with a `grid` role which had the desired appearance, functionality, and supported all browser/screen reader combinations that we support; the expected screen reader experience was replicated as much as possible (e.g., announcing the expected content).
@@ -40,7 +40,8 @@ function getCalendarData() {
40
40
  return calendarData;
41
41
  }
42
42
 
43
- function getInitialFocusDate(selectedValue, minValue, maxValue) {
43
+ function getInitialFocusDate(initialValue, selectedValue, minValue, maxValue) {
44
+ if (initialValue) return getDateFromISODate(initialValue);
44
45
  if (selectedValue) return getDateFromISODate(selectedValue);
45
46
  else return getDateFromISODate(getClosestValidDate(minValue, maxValue, false));
46
47
  }
@@ -50,9 +51,9 @@ export function checkIfDatesEqual(date1, date2) {
50
51
  return date1.getTime() === date2.getTime();
51
52
  }
52
53
 
53
- export function getMinMaxDatesInView(selectedValue, minValue, maxValue) {
54
+ export function getMinMaxDatesInView(initialValue, selectedValue, minValue, maxValue) {
54
55
  getCalendarData();
55
- const date = getInitialFocusDate(selectedValue, minValue, maxValue);
56
+ const date = getInitialFocusDate(initialValue, selectedValue, minValue, maxValue);
56
57
  const dates = getDatesInMonthArray(date.getMonth(), date.getFullYear());
57
58
  return {
58
59
  maxValue: dates[dates.length - 1][6],
@@ -160,6 +161,11 @@ class Calendar extends LocalizeCoreElement(RtlMixin(LitElement)) {
160
161
  * @type {string}
161
162
  */
162
163
  label: { attribute: 'label', reflect: true, type: String },
164
+ /**
165
+ * ADVANCED: Initial date to override the logic for determining default date to initially show
166
+ * @type {string}
167
+ */
168
+ initialValue: { attribute: 'initial-value', type: String },
163
169
  /**
164
170
  * Maximum valid date that could be selected by a user
165
171
  * @type {string}
@@ -609,7 +615,9 @@ class Calendar extends LocalizeCoreElement(RtlMixin(LitElement)) {
609
615
  composed: false,
610
616
  detail: {
611
617
  maxValue: dates[dates.length - 1][6],
612
- minValue: dates[0][0]
618
+ month: this._shownMonth,
619
+ minValue: dates[0][0],
620
+ year: this._shownYear
613
621
  }
614
622
  }));
615
623
 
@@ -625,6 +633,10 @@ class Calendar extends LocalizeCoreElement(RtlMixin(LitElement)) {
625
633
  }
626
634
  }
627
635
 
636
+ getShownValue() {
637
+ return new Date(this._shownYear, this._shownMonth).toISOString();
638
+ }
639
+
628
640
  async reset(allowDisabled) {
629
641
  const date = this._getInitialFocusDate();
630
642
  await this._updateFocusDate(date, false, allowDisabled);
@@ -649,7 +661,7 @@ class Calendar extends LocalizeCoreElement(RtlMixin(LitElement)) {
649
661
  }
650
662
 
651
663
  _getInitialFocusDate() {
652
- const date = getInitialFocusDate(this.selectedValue, this.minValue, this.maxValue);
664
+ const date = getInitialFocusDate(this.initialValue, this.selectedValue, this.minValue, this.maxValue);
653
665
  this._shownMonth = date.getMonth();
654
666
  this._shownYear = date.getFullYear();
655
667
  return date;
@@ -62,8 +62,11 @@
62
62
  };
63
63
 
64
64
  const calendar = document.querySelector('#eventsCalendar');
65
- calendar.dayInfos = getEvents(getMinMaxDatesInView(calendar.selectedValue));
66
- calendar.addEventListener('d2l-calendar-view-change', e => calendar.dayInfos = getEvents(e.detail));
65
+ calendar.dayInfos = getEvents(getMinMaxDatesInView(undefined, calendar.selectedValue));
66
+ calendar.addEventListener('d2l-calendar-view-change', e => {
67
+ console.log(e);
68
+ calendar.dayInfos = getEvents(e.detail);
69
+ });
67
70
  </script>
68
71
  </template>
69
72
  </d2l-demo-snippet>
@@ -823,6 +823,11 @@
823
823
  "description": "Unique label text for calendar (necessary if multiple calendars on page)",
824
824
  "type": "string"
825
825
  },
826
+ {
827
+ "name": "initial-value",
828
+ "description": "ADVANCED: Initial date to override the logic for determining default date to initially show",
829
+ "type": "string"
830
+ },
826
831
  {
827
832
  "name": "max-value",
828
833
  "description": "Maximum valid date that could be selected by a user",
@@ -857,6 +862,12 @@
857
862
  "description": "Unique label text for calendar (necessary if multiple calendars on page)",
858
863
  "type": "string"
859
864
  },
865
+ {
866
+ "name": "initialValue",
867
+ "attribute": "initial-value",
868
+ "description": "ADVANCED: Initial date to override the logic for determining default date to initially show",
869
+ "type": "string"
870
+ },
860
871
  {
861
872
  "name": "maxValue",
862
873
  "attribute": "max-value",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.47.1",
3
+ "version": "3.48.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",