@atlaskit/calendar 13.1.17 → 13.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/calendar.js +46 -12
  3. package/dist/cjs/internal/components/date.js +50 -22
  4. package/dist/cjs/internal/components/header.js +26 -11
  5. package/dist/cjs/internal/components/week-days.js +7 -0
  6. package/dist/cjs/internal/components/week-header.js +14 -16
  7. package/dist/cjs/internal/hooks/use-get-weeks.js +6 -2
  8. package/dist/cjs/internal/hooks/use-handle-date-change.js +6 -1
  9. package/dist/cjs/internal/hooks/use-locale.js +5 -1
  10. package/dist/cjs/internal/styles/date.js +25 -27
  11. package/dist/es2019/calendar.js +45 -14
  12. package/dist/es2019/internal/components/date.js +50 -22
  13. package/dist/es2019/internal/components/header.js +26 -11
  14. package/dist/es2019/internal/components/week-days.js +7 -0
  15. package/dist/es2019/internal/components/week-header.js +5 -6
  16. package/dist/es2019/internal/hooks/use-get-weeks.js +6 -2
  17. package/dist/es2019/internal/hooks/use-handle-date-change.js +4 -1
  18. package/dist/es2019/internal/hooks/use-locale.js +3 -1
  19. package/dist/es2019/internal/styles/date.js +3 -1
  20. package/dist/esm/calendar.js +47 -13
  21. package/dist/esm/internal/components/date.js +50 -22
  22. package/dist/esm/internal/components/header.js +26 -11
  23. package/dist/esm/internal/components/week-days.js +7 -0
  24. package/dist/esm/internal/components/week-header.js +14 -16
  25. package/dist/esm/internal/hooks/use-get-weeks.js +6 -2
  26. package/dist/esm/internal/hooks/use-handle-date-change.js +6 -1
  27. package/dist/esm/internal/hooks/use-locale.js +5 -1
  28. package/dist/esm/internal/styles/date.js +24 -27
  29. package/dist/types/calendar.d.ts +1 -1
  30. package/dist/types/internal/components/date.d.ts +5 -0
  31. package/dist/types/internal/components/header.d.ts +5 -0
  32. package/dist/types/internal/components/week-days.d.ts +4 -0
  33. package/dist/types/internal/hooks/use-get-weeks.d.ts +2 -1
  34. package/dist/types/internal/hooks/use-handle-date-change.d.ts +2 -1
  35. package/dist/types/internal/hooks/use-locale.d.ts +1 -0
  36. package/dist/types/internal/types.d.ts +1 -0
  37. package/dist/types/types.d.ts +4 -2
  38. package/dist/types-ts4.5/calendar.d.ts +1 -1
  39. package/dist/types-ts4.5/internal/components/date.d.ts +5 -0
  40. package/dist/types-ts4.5/internal/components/header.d.ts +5 -0
  41. package/dist/types-ts4.5/internal/components/week-days.d.ts +4 -0
  42. package/dist/types-ts4.5/internal/hooks/use-get-weeks.d.ts +2 -1
  43. package/dist/types-ts4.5/internal/hooks/use-handle-date-change.d.ts +5 -1
  44. package/dist/types-ts4.5/internal/hooks/use-locale.d.ts +1 -0
  45. package/dist/types-ts4.5/internal/types.d.ts +1 -0
  46. package/dist/types-ts4.5/types.d.ts +4 -2
  47. package/package.json +12 -4
  48. package/report.api.md +4 -1
  49. package/tmp/api-report-tmp.d.ts +4 -1
  50. package/dist/cjs/version.json +0 -5
  51. package/dist/es2019/version.json +0 -5
  52. package/dist/esm/version.json +0 -5
@@ -1,9 +1,10 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  /** @jsx jsx */
3
- import { forwardRef, memo, useMemo } from 'react';
3
+ import { forwardRef, memo, useMemo, useState } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
5
  import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next/usePlatformLeafEventHandler';
6
6
  import noop from '@atlaskit/ds-lib/noop';
7
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
8
  import { Box, Stack, xcss } from '@atlaskit/primitives';
8
9
  import GlobalTheme from '@atlaskit/theme/components';
9
10
  import VisuallyHidden from '@atlaskit/visually-hidden';
@@ -26,7 +27,7 @@ const boxStyles = xcss({
26
27
  const analyticsAttributes = {
27
28
  componentName: 'calendar',
28
29
  packageName: "@atlaskit/calendar",
29
- packageVersion: "13.1.17"
30
+ packageVersion: "13.2.1"
30
31
  };
31
32
  const CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar({
32
33
  day,
@@ -80,6 +81,7 @@ const CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar({
80
81
  previouslySelected,
81
82
  defaultPreviouslySelected
82
83
  });
84
+ const [shouldSetFocus, setShouldSetFocus] = useState(false);
83
85
  const onChangeWithAnalytics = usePlatformLeafEventHandler({
84
86
  fn: onChange,
85
87
  action: 'changed',
@@ -94,6 +96,7 @@ const CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar({
94
96
  day: [dayValue, setDayValue],
95
97
  month: [monthValue, setMonthValue],
96
98
  year: [yearValue, setYearValue],
99
+ shouldSetFocus: [shouldSetFocus, setShouldSetFocus],
97
100
  onChange: onChangeWithAnalytics
98
101
  });
99
102
  const onSelectWithAnalytics = usePlatformLeafEventHandler({
@@ -124,6 +127,14 @@ const CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar({
124
127
  useCalendarRef(calendarRef, {
125
128
  navigate
126
129
  });
130
+ const {
131
+ monthsLong,
132
+ daysShort,
133
+ daysLong
134
+ } = useLocale({
135
+ locale,
136
+ weekStartDay
137
+ });
127
138
  const weeks = useGetWeeks({
128
139
  day: dayValue,
129
140
  month: monthValue,
@@ -135,17 +146,26 @@ const CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar({
135
146
  disabledDateFilter,
136
147
  minDate,
137
148
  maxDate,
149
+ daysLong,
138
150
  weekStartDay
139
151
  });
140
152
  const announceId = useUniqueId('announce');
141
153
  const announcerDate = useMemo(() => new Date(yearValue, monthValue - 1, dayValue).toString(), [dayValue, monthValue, yearValue]);
142
- const {
143
- monthsLong,
144
- daysShort
145
- } = useLocale({
146
- locale,
147
- weekStartDay
148
- });
154
+ const getNextHeading = () => {
155
+ // Next month is (currentMonth - 1) + 1, or just currentMonth in this
156
+ // instance.
157
+ const nextMonth = monthValue % 12;
158
+ const showNextYear = monthValue === 12;
159
+ return `${monthsLong[nextMonth]} ${showNextYear ? yearValue + 1 : yearValue}`;
160
+ };
161
+ const getPreviousHeading = () => {
162
+ // Previous month is (monthValue - 1) - 1. Need to add 12 so the modulo
163
+ // works as expected and stays positive.
164
+ const previousMonth = (monthValue + 12 - 2) % 12;
165
+ const showPreviousYear = monthValue === 1;
166
+ return `${monthsLong[previousMonth]} ${showPreviousYear ? yearValue - 1 : yearValue}`;
167
+ };
168
+ const headerId = useUniqueId('month-year-header');
149
169
  return (
150
170
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/no-static-element-interactions
151
171
  jsx("div", {
@@ -153,19 +173,19 @@ const CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar({
153
173
  style: style,
154
174
  onBlur: handleContainerBlur,
155
175
  onFocus: handleContainerFocus,
156
- onKeyDown: handleContainerKeyDown,
176
+ onKeyDown: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? undefined : handleContainerKeyDown,
157
177
  "data-testid": testId && `${testId}--container`,
158
178
  ref: ref
159
- }, jsx(VisuallyHidden, null, jsx("span", {
179
+ }, getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? null : jsx(VisuallyHidden, null, jsx("span", {
160
180
  id: announceId,
161
181
  "aria-live": "assertive",
162
182
  "aria-relevant": "text"
163
183
  }, announcerDate)), jsx(Box, {
164
184
  xcss: boxStyles,
165
185
  padding: "space.200",
166
- "aria-describedby": announceId,
186
+ "aria-describedby": getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? undefined : announceId,
167
187
  "aria-label": "calendar",
168
- tabIndex: tabIndex,
188
+ tabIndex: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? undefined : tabIndex,
169
189
  testId: testId && `${testId}--calendar`
170
190
  }, jsx(Stack, {
171
191
  space: "space.150"
@@ -177,12 +197,20 @@ const CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar({
177
197
  year: yearValue,
178
198
  nextMonthLabel: nextMonthLabel,
179
199
  previousMonthLabel: previousMonthLabel,
200
+ nextHeading: getNextHeading(),
201
+ previousHeading: getPreviousHeading(),
180
202
  handleClickNext: handleClickNext,
181
203
  handleClickPrev: handleClickPrev,
204
+ headerId: headerId,
182
205
  mode: mode,
206
+ tabIndex: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? tabIndex : undefined,
183
207
  testId: testId
184
208
  }), jsx(Box, {
185
- role: "grid"
209
+ role: "grid",
210
+ tabIndex: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? tabIndex : undefined,
211
+ onKeyDown: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? handleContainerKeyDown : undefined,
212
+ "aria-labelledby": getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? headerId : undefined,
213
+ testId: testId && `${testId}--calendar-dates`
186
214
  }, jsx(WeekHeaderComponent, {
187
215
  daysShort: daysShort,
188
216
  mode: mode,
@@ -191,6 +219,9 @@ const CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar({
191
219
  weeks: weeks,
192
220
  handleClickDay: handleClickDay,
193
221
  mode: mode,
222
+ monthsLong: monthsLong,
223
+ shouldSetFocus: shouldSetFocus,
224
+ tabIndex: tabIndex,
194
225
  testId: testId
195
226
  })))))
196
227
  );
@@ -2,19 +2,25 @@
2
2
  import { forwardRef, memo, useCallback, useEffect, useMemo, useRef } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
4
  import noop from '@atlaskit/ds-lib/noop';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
+ import { Grid } from '@atlaskit/primitives';
5
7
  import { dateCellStyles as getDateCellStyles } from '../styles/date';
6
8
  const Date = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Date({
7
9
  children: day,
8
10
  isDisabled = false,
9
11
  isFocused = false,
10
12
  isToday = false,
13
+ dayLong,
11
14
  month,
15
+ monthLong,
12
16
  onClick = noop,
13
17
  isPreviouslySelected = false,
14
18
  isSelected = false,
15
19
  isSibling = false,
16
20
  year,
17
21
  mode,
22
+ shouldSetFocus,
23
+ tabIndex,
18
24
  testId
19
25
  }, ref) {
20
26
  const dateRef = useRef({
@@ -31,6 +37,12 @@ const Date = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Date({
31
37
  isDisabled
32
38
  };
33
39
  }, [day, month, year, isDisabled]);
40
+ const focusRef = useRef(null);
41
+ useEffect(() => {
42
+ if (getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') && isFocused && shouldSetFocus && focusRef.current) {
43
+ focusRef.current.focus();
44
+ }
45
+ }, [isFocused, shouldSetFocus]);
34
46
  const handleClick = useCallback(() => {
35
47
  const {
36
48
  day: dayValue,
@@ -47,28 +59,44 @@ const Date = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Date({
47
59
  }
48
60
  }, [onClick]);
49
61
  const dateCellStyles = useMemo(() => css(getDateCellStyles(mode)), [mode]);
50
- return (
51
- // TODO: Determine if there is a better way to render the button (should
52
- // be fixed with introduction of keyboard accessibility of Calendar in
53
- // DSP-9939) (DSP-11588)
54
- jsx("button", {
55
- // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
56
- css: dateCellStyles,
57
- "aria-selected": isSelected ? 'true' : 'false',
58
- tabIndex: isSelected ? 0 : -1,
59
- type: "button",
60
- role: "gridcell",
61
- onClick: handleClick,
62
- ref: ref,
63
- "data-disabled": isDisabled || undefined,
64
- "data-focused": isFocused || undefined,
65
- "data-prev-selected": isPreviouslySelected || undefined,
66
- "data-selected": isSelected || undefined,
67
- "data-sibling": isSibling || undefined,
68
- "data-today": isToday || undefined,
69
- "data-testid": testId && isSelected ? `${testId}--selected-day` : undefined
70
- }, day)
71
- );
62
+ return getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? jsx(Grid, {
63
+ role: "gridcell",
64
+ alignItems: "center"
65
+ }, jsx("button", {
66
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
67
+ css: dateCellStyles,
68
+ "aria-current": isToday ? 'date' : undefined,
69
+ "aria-disabled": isDisabled || undefined,
70
+ "aria-label": `${day}, ${dayLong} ${monthLong} ${year}`,
71
+ "aria-pressed": isSelected ? 'true' : 'false',
72
+ tabIndex: isFocused ? tabIndex : -1,
73
+ type: "button",
74
+ onClick: handleClick,
75
+ ref: focusRef,
76
+ "data-disabled": isDisabled || undefined,
77
+ "data-focused": isFocused || undefined,
78
+ "data-prev-selected": isPreviouslySelected || undefined,
79
+ "data-selected": isSelected || undefined,
80
+ "data-sibling": isSibling || undefined,
81
+ "data-today": isToday || undefined,
82
+ "data-testid": testId && (isSelected ? `${testId}--selected-day` : `${testId}--day`)
83
+ }, day)) : jsx("button", {
84
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
85
+ css: dateCellStyles,
86
+ "aria-selected": isSelected ? 'true' : 'false',
87
+ tabIndex: isSelected ? 0 : -1,
88
+ type: "button",
89
+ role: "gridcell",
90
+ onClick: handleClick,
91
+ ref: ref,
92
+ "data-disabled": isDisabled || undefined,
93
+ "data-focused": isFocused || undefined,
94
+ "data-prev-selected": isPreviouslySelected || undefined,
95
+ "data-selected": isSelected || undefined,
96
+ "data-sibling": isSibling || undefined,
97
+ "data-today": isToday || undefined,
98
+ "data-testid": testId && (isSelected ? `${testId}--selected-day` : `${testId}--day`)
99
+ }, day);
72
100
  }));
73
101
  Date.displayName = 'Date';
74
102
 
@@ -5,20 +5,33 @@ import Button from '@atlaskit/button/standard-button';
5
5
  import Heading from '@atlaskit/heading';
6
6
  import ArrowleftIcon from '@atlaskit/icon/glyph/chevron-left-large';
7
7
  import ArrowrightIcon from '@atlaskit/icon/glyph/chevron-right-large';
8
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
9
  import { Box, Inline } from '@atlaskit/primitives';
9
10
  import { N700 } from '@atlaskit/theme/colors';
11
+ import useUniqueId from '../../internal/hooks/use-unique-id';
10
12
  const Header = /*#__PURE__*/memo(function Header({
11
13
  monthLongTitle,
12
14
  year,
13
- previousMonthLabel = 'Last month',
15
+ previousMonthLabel = getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? 'Previous month' : 'Last month',
16
+ previousHeading,
14
17
  nextMonthLabel = 'Next month',
18
+ nextHeading,
15
19
  handleClickPrev,
16
20
  handleClickNext,
21
+ headerId,
22
+ tabIndex,
17
23
  testId
18
24
  }) {
25
+ const announceId = useUniqueId('month-year-announce');
26
+ const renderedHeading = jsx(Heading, {
27
+ level: "h400",
28
+ as: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? 'h2' : 'div',
29
+ id: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? headerId : undefined,
30
+ testId: testId && `${testId}--current-month-year`
31
+ }, `${monthLongTitle} ${year}`);
19
32
  return jsx(Box, {
20
33
  paddingInline: "space.100",
21
- "aria-hidden": "true"
34
+ "aria-hidden": getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? undefined : 'true'
22
35
  }, jsx(Inline, {
23
36
  space: "space.0",
24
37
  alignBlock: "center",
@@ -26,27 +39,29 @@ const Header = /*#__PURE__*/memo(function Header({
26
39
  }, jsx(Button, {
27
40
  appearance: "subtle",
28
41
  spacing: "none",
29
- tabIndex: -1,
42
+ tabIndex: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? tabIndex : -1,
30
43
  onClick: handleClickPrev,
31
44
  testId: testId && `${testId}--previous-month`,
32
45
  iconBefore: jsx(ArrowleftIcon, {
33
- label: previousMonthLabel,
46
+ label: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? `${previousMonthLabel}, ${previousHeading}` : previousMonthLabel,
34
47
  size: "medium",
35
48
  primaryColor: `var(--ds-icon, ${N700})`,
36
49
  testId: testId && `${testId}--previous-month-icon`
37
50
  })
38
- }), jsx(Heading, {
39
- level: "h400",
40
- as: "div",
41
- testId: testId && `${testId}--current-month-year`
42
- }, `${monthLongTitle} ${year}`), jsx(Button, {
51
+ }), getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ?
52
+ // This is required to ensure that the new month/year is announced when the previous/next month buttons are activated
53
+ jsx(Box, {
54
+ "aria-live": "polite",
55
+ id: announceId,
56
+ testId: testId && `${testId}--current-month-year--container`
57
+ }, renderedHeading) : renderedHeading, jsx(Button, {
43
58
  appearance: "subtle",
44
59
  spacing: "none",
45
- tabIndex: -1,
60
+ tabIndex: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? tabIndex : -1,
46
61
  onClick: handleClickNext,
47
62
  testId: testId && `${testId}--next-month`,
48
63
  iconBefore: jsx(ArrowrightIcon, {
49
- label: nextMonthLabel,
64
+ label: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? `${nextMonthLabel}, ${nextHeading}` : nextMonthLabel,
50
65
  size: "medium",
51
66
  primaryColor: `var(--ds-icon, ${N700})`,
52
67
  testId: testId && `${testId}--next-month-icon`
@@ -8,6 +8,9 @@ const WeekDays = /*#__PURE__*/memo(function WeekDays({
8
8
  weeks,
9
9
  handleClickDay,
10
10
  mode,
11
+ monthsLong,
12
+ shouldSetFocus,
13
+ tabIndex,
11
14
  testId
12
15
  }) {
13
16
  return (
@@ -25,13 +28,17 @@ const WeekDays = /*#__PURE__*/memo(function WeekDays({
25
28
  isDisabled: weekDay.isDisabled,
26
29
  isFocused: weekDay.isFocused,
27
30
  isToday: weekDay.isToday,
31
+ dayLong: weekDay.weekDayName,
28
32
  month: weekDay.month,
33
+ monthLong: monthsLong[weekDay.month - 1],
29
34
  onClick: handleClickDay,
30
35
  isPreviouslySelected: weekDay.isPreviouslySelected,
31
36
  isSelected: weekDay.isSelected,
32
37
  isSibling: weekDay.isSiblingMonth,
33
38
  year: weekDay.year,
34
39
  mode: mode,
40
+ shouldSetFocus: shouldSetFocus,
41
+ tabIndex: tabIndex,
35
42
  testId: testId
36
43
  }, weekDay.day)))))
37
44
  );
@@ -2,6 +2,7 @@
2
2
  import { memo } from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import Text from '@atlaskit/ds-explorations/text';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
5
6
  import { Box, xcss } from '@atlaskit/primitives';
6
7
  import WeekDayGrid from './week-day-grid';
7
8
  const columnHeaderStyles = xcss({
@@ -20,15 +21,13 @@ const WeekHeader = /*#__PURE__*/memo(function WeekHeader({
20
21
  }) {
21
22
  return jsx(WeekDayGrid, {
22
23
  testId: testId && `${testId}--column-headers`
23
- }, daysShort.map(shortDay =>
24
- // TODO: Determine if there is a better way to render the button
25
- // (should be fixed with introduction of keyboard accessibility of
26
- // Calendar in DSP-9939) (DSP-11588)
27
- jsx(Box, {
24
+ }, daysShort.map(shortDay => jsx(Box, {
25
+ "aria-hidden": getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? 'true' : undefined,
28
26
  padding: "space.100",
29
27
  xcss: columnHeaderStyles,
30
28
  key: shortDay,
31
- role: "columnheader"
29
+ role: "columnheader",
30
+ testId: testId && `${testId}--column-header`
32
31
  }, jsx(Text, {
33
32
  fontWeight: "bold",
34
33
  fontSize: "size.050",
@@ -32,6 +32,7 @@ function useGetCalendarWithSixthWeek(calendar, {
32
32
  // eslint-disable-next-line @repo/internal/react/require-jsdoc
33
33
  export default function useGetWeeks({
34
34
  day,
35
+ daysLong,
35
36
  month,
36
37
  year,
37
38
  today,
@@ -74,8 +75,10 @@ export default function useGetWeeks({
74
75
  } else {
75
76
  week = weeks[weeks.length - 1];
76
77
  }
78
+ const weekDayOffset = (date.weekDay - weekStartDay) % 7;
77
79
 
78
80
  // Define a bunch of `const`s
81
+ const weekDayName = daysLong[weekDayOffset];
79
82
  const isDisabledByArray = disabled ? disabled.indexOf(dateAsString) > -1 : false;
80
83
  const isDisabledByFilter = disabledDateFilter ? disabledDateFilter(dateAsString) : false;
81
84
  const isDisabledByMin = minDate && JSDate ? JSDate < minDate : false;
@@ -96,9 +99,10 @@ export default function useGetWeeks({
96
99
  isSelected,
97
100
  isSiblingMonth,
98
101
  year: date.year,
99
- day: date.day
102
+ day: date.day,
103
+ weekDayName
100
104
  });
101
105
  });
102
106
  return weeks;
103
- }, [calendar, day, disabled, disabledDateFilter, minDate, maxDate, needJsDate, previouslySelected, selected, today, weekStartDay]);
107
+ }, [calendar, day, disabled, disabledDateFilter, minDate, maxDate, needJsDate, previouslySelected, selected, today, weekStartDay, daysLong]);
104
108
  }
@@ -36,6 +36,7 @@ export default function useHandleDateChange({
36
36
  day: [dayValue, setDayValue],
37
37
  month: [monthValue, setMonthValue],
38
38
  year: [yearValue, setYearValue],
39
+ shouldSetFocus: [shouldSetFocus, setShouldSetFocus],
39
40
  onChange
40
41
  }) {
41
42
  const dateRef = useRef({
@@ -61,6 +62,7 @@ export default function useHandleDateChange({
61
62
  month,
62
63
  day
63
64
  });
65
+ const isFocusableType = ['up', 'down', 'left', 'right'].includes(type);
64
66
  onChange({
65
67
  day,
66
68
  month,
@@ -71,7 +73,8 @@ export default function useHandleDateChange({
71
73
  setDayValue(day);
72
74
  setMonthValue(month);
73
75
  setYearValue(year);
74
- }, [onChange, setDayValue, setMonthValue, setYearValue]);
76
+ setShouldSetFocus(isFocusableType);
77
+ }, [onChange, setDayValue, setMonthValue, setYearValue, setShouldSetFocus]);
75
78
  const navigate = useCallback(type => {
76
79
  const {
77
80
  day,
@@ -8,8 +8,10 @@ export default function useLocale({
8
8
  const l10n = useMemo(() => createLocalizationProvider(locale), [locale]);
9
9
  const monthsLong = useMemo(() => l10n.getMonthsLong(), [l10n]);
10
10
  const daysShort = useMemo(() => l10n.getDaysShort(weekStartDay), [l10n, weekStartDay]);
11
+ const daysLong = useMemo(() => l10n.getDaysLong(weekStartDay), [l10n, weekStartDay]);
11
12
  return {
12
13
  monthsLong,
13
- daysShort
14
+ daysShort,
15
+ daysLong
14
16
  };
15
17
  }
@@ -1,3 +1,4 @@
1
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
1
2
  import { B100, B200, B400, B50, DN600, N0, N200, N30, N40, N500, N600, N700, N800, N900 } from '@atlaskit/theme/colors';
2
3
  const textColor = {
3
4
  light: `var(--ds-text, ${N900})`,
@@ -24,6 +25,7 @@ const borderColorFocused = {
24
25
  light: `var(--ds-border-focused, ${B200})`,
25
26
  dark: `var(--ds-border-focused, ${B100})`
26
27
  };
28
+ const focusBorderSelector = getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? '&:focus-visible' : '&[data-focused]';
27
29
  export const dateCellStyles = (mode = 'light') => ({
28
30
  all: 'unset',
29
31
  display: 'block',
@@ -66,7 +68,7 @@ export const dateCellStyles = (mode = 'light') => ({
66
68
  color: `var(--ds-text-disabled, ${N40})`,
67
69
  cursor: 'not-allowed'
68
70
  },
69
- '&[data-focused]': {
71
+ [focusBorderSelector]: {
70
72
  border: `2px solid ${borderColorFocused[mode]}`
71
73
  },
72
74
  '&:hover': {
@@ -4,10 +4,11 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
6
  /** @jsx jsx */
7
- import { forwardRef, memo, useMemo } from 'react';
7
+ import { forwardRef, memo, useMemo, useState } from 'react';
8
8
  import { jsx } from '@emotion/react';
9
9
  import { usePlatformLeafEventHandler } from '@atlaskit/analytics-next/usePlatformLeafEventHandler';
10
10
  import noop from '@atlaskit/ds-lib/noop';
11
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
11
12
  import { Box, Stack, xcss } from '@atlaskit/primitives';
12
13
  import GlobalTheme from '@atlaskit/theme/components';
13
14
  import VisuallyHidden from '@atlaskit/visually-hidden';
@@ -30,7 +31,7 @@ var boxStyles = xcss({
30
31
  var analyticsAttributes = {
31
32
  componentName: 'calendar',
32
33
  packageName: "@atlaskit/calendar",
33
- packageVersion: "13.1.17"
34
+ packageVersion: "13.2.1"
34
35
  };
35
36
  var CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar(_ref, ref) {
36
37
  var day = _ref.day,
@@ -106,6 +107,10 @@ var CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar(_ref, ref) {
106
107
  _useControlledDateSta7 = _slicedToArray(_useControlledDateSta.previous, 2),
107
108
  previouslySelectedValue = _useControlledDateSta7[0],
108
109
  setPreviouslySelectedValue = _useControlledDateSta7[1];
110
+ var _useState = useState(false),
111
+ _useState2 = _slicedToArray(_useState, 2),
112
+ shouldSetFocus = _useState2[0],
113
+ setShouldSetFocus = _useState2[1];
109
114
  var onChangeWithAnalytics = usePlatformLeafEventHandler(_objectSpread({
110
115
  fn: onChange,
111
116
  action: 'changed',
@@ -115,6 +120,7 @@ var CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar(_ref, ref) {
115
120
  day: [dayValue, setDayValue],
116
121
  month: [monthValue, setMonthValue],
117
122
  year: [yearValue, setYearValue],
123
+ shouldSetFocus: [shouldSetFocus, setShouldSetFocus],
118
124
  onChange: onChangeWithAnalytics
119
125
  }),
120
126
  navigate = _useHandleDateChange.navigate,
@@ -145,6 +151,13 @@ var CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar(_ref, ref) {
145
151
  useCalendarRef(calendarRef, {
146
152
  navigate: navigate
147
153
  });
154
+ var _useLocale = useLocale({
155
+ locale: locale,
156
+ weekStartDay: weekStartDay
157
+ }),
158
+ monthsLong = _useLocale.monthsLong,
159
+ daysShort = _useLocale.daysShort,
160
+ daysLong = _useLocale.daysLong;
148
161
  var weeks = useGetWeeks({
149
162
  day: dayValue,
150
163
  month: monthValue,
@@ -156,18 +169,28 @@ var CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar(_ref, ref) {
156
169
  disabledDateFilter: disabledDateFilter,
157
170
  minDate: minDate,
158
171
  maxDate: maxDate,
172
+ daysLong: daysLong,
159
173
  weekStartDay: weekStartDay
160
174
  });
161
175
  var announceId = useUniqueId('announce');
162
176
  var announcerDate = useMemo(function () {
163
177
  return new Date(yearValue, monthValue - 1, dayValue).toString();
164
178
  }, [dayValue, monthValue, yearValue]);
165
- var _useLocale = useLocale({
166
- locale: locale,
167
- weekStartDay: weekStartDay
168
- }),
169
- monthsLong = _useLocale.monthsLong,
170
- daysShort = _useLocale.daysShort;
179
+ var getNextHeading = function getNextHeading() {
180
+ // Next month is (currentMonth - 1) + 1, or just currentMonth in this
181
+ // instance.
182
+ var nextMonth = monthValue % 12;
183
+ var showNextYear = monthValue === 12;
184
+ return "".concat(monthsLong[nextMonth], " ").concat(showNextYear ? yearValue + 1 : yearValue);
185
+ };
186
+ var getPreviousHeading = function getPreviousHeading() {
187
+ // Previous month is (monthValue - 1) - 1. Need to add 12 so the modulo
188
+ // works as expected and stays positive.
189
+ var previousMonth = (monthValue + 12 - 2) % 12;
190
+ var showPreviousYear = monthValue === 1;
191
+ return "".concat(monthsLong[previousMonth], " ").concat(showPreviousYear ? yearValue - 1 : yearValue);
192
+ };
193
+ var headerId = useUniqueId('month-year-header');
171
194
  return (
172
195
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/no-static-element-interactions
173
196
  jsx("div", {
@@ -175,19 +198,19 @@ var CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar(_ref, ref) {
175
198
  style: style,
176
199
  onBlur: handleContainerBlur,
177
200
  onFocus: handleContainerFocus,
178
- onKeyDown: handleContainerKeyDown,
201
+ onKeyDown: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? undefined : handleContainerKeyDown,
179
202
  "data-testid": testId && "".concat(testId, "--container"),
180
203
  ref: ref
181
- }, jsx(VisuallyHidden, null, jsx("span", {
204
+ }, getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? null : jsx(VisuallyHidden, null, jsx("span", {
182
205
  id: announceId,
183
206
  "aria-live": "assertive",
184
207
  "aria-relevant": "text"
185
208
  }, announcerDate)), jsx(Box, {
186
209
  xcss: boxStyles,
187
210
  padding: "space.200",
188
- "aria-describedby": announceId,
211
+ "aria-describedby": getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? undefined : announceId,
189
212
  "aria-label": "calendar",
190
- tabIndex: tabIndex,
213
+ tabIndex: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? undefined : tabIndex,
191
214
  testId: testId && "".concat(testId, "--calendar")
192
215
  }, jsx(Stack, {
193
216
  space: "space.150"
@@ -199,12 +222,20 @@ var CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar(_ref, ref) {
199
222
  year: yearValue,
200
223
  nextMonthLabel: nextMonthLabel,
201
224
  previousMonthLabel: previousMonthLabel,
225
+ nextHeading: getNextHeading(),
226
+ previousHeading: getPreviousHeading(),
202
227
  handleClickNext: handleClickNext,
203
228
  handleClickPrev: handleClickPrev,
229
+ headerId: headerId,
204
230
  mode: mode,
231
+ tabIndex: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? tabIndex : undefined,
205
232
  testId: testId
206
233
  }), jsx(Box, {
207
- role: "grid"
234
+ role: "grid",
235
+ tabIndex: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? tabIndex : undefined,
236
+ onKeyDown: getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? handleContainerKeyDown : undefined,
237
+ "aria-labelledby": getBooleanFF('platform.design-system-team.calendar-keyboard-accessibility_967h1') ? headerId : undefined,
238
+ testId: testId && "".concat(testId, "--calendar-dates")
208
239
  }, jsx(WeekHeaderComponent, {
209
240
  daysShort: daysShort,
210
241
  mode: mode,
@@ -213,6 +244,9 @@ var CalendarWithMode = /*#__PURE__*/forwardRef(function Calendar(_ref, ref) {
213
244
  weeks: weeks,
214
245
  handleClickDay: handleClickDay,
215
246
  mode: mode,
247
+ monthsLong: monthsLong,
248
+ shouldSetFocus: shouldSetFocus,
249
+ tabIndex: tabIndex,
216
250
  testId: testId
217
251
  })))))
218
252
  );