carbon-react 123.2.2 → 123.4.0

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.
@@ -33,6 +33,13 @@ export interface DatePickerProps {
33
33
  open?: boolean;
34
34
  /** Callback triggered when a Day is clicked */
35
35
  onDayClick?: (date: Date, ev: React.MouseEvent<HTMLDivElement>) => void;
36
+ /** Sets the picker open state */
37
+ setOpen: (isOpen: boolean) => void;
38
+ /** Id passed to tab guard element */
39
+ pickerTabGuardId?: string;
36
40
  }
37
- export declare const DatePicker: React.ForwardRefExoticComponent<DatePickerProps & React.RefAttributes<HTMLDivElement>>;
41
+ export declare const DatePicker: {
42
+ ({ inputElement, minDate, maxDate, selectedDays, disablePortal, onDayClick, pickerMouseDown, pickerProps, open, setOpen, pickerTabGuardId, }: DatePickerProps): React.JSX.Element | null;
43
+ displayName: string;
44
+ };
38
45
  export default DatePicker;
@@ -1,5 +1,5 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React, { useMemo } from "react";
2
+ import React, { useEffect, useMemo, useRef } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import DayPicker from "react-day-picker";
5
5
  import { flip, offset } from "@floating-ui/dom";
@@ -9,13 +9,15 @@ import useLocale from "../../../../hooks/__internal__/useLocale";
9
9
  import Navbar from "../navbar";
10
10
  import Weekday from "../weekday";
11
11
  import StyledDayPicker from "./day-picker.style";
12
+ import Events from "../../../../__internal__/utils/helpers/events";
13
+ import { defaultFocusableSelectors } from "../../../../__internal__/focus-trap/focus-trap-utils";
12
14
 
13
15
  /** there is an issue with typescript-to-proptypes package that means we need to override these types */
14
16
 
15
17
  const popoverMiddleware = [offset(3), flip({
16
18
  fallbackStrategy: "initialPlacement"
17
19
  })];
18
- const DatePicker = /*#__PURE__*/React.forwardRef(({
20
+ export const DatePicker = ({
19
21
  inputElement,
20
22
  minDate,
21
23
  maxDate,
@@ -24,8 +26,10 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
24
26
  onDayClick,
25
27
  pickerMouseDown,
26
28
  pickerProps,
27
- open
28
- }, ref) => {
29
+ open,
30
+ setOpen,
31
+ pickerTabGuardId
32
+ }) => {
29
33
  const l = useLocale();
30
34
  const {
31
35
  localize,
@@ -58,6 +62,28 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
58
62
  width: "abbreviated"
59
63
  }).substring(0, isGivenLocale("de") ? 2 : 3));
60
64
  }, [l, localize]);
65
+ const ref = useRef(null);
66
+ useEffect(() => {
67
+ if (open) {
68
+ // this is a temporary fix for some axe issues that are baked into the library we use for the picker
69
+ const captionElement = ref.current?.querySelector(".DayPicker-Caption");
70
+ /* istanbul ignore else */
71
+ if (captionElement) {
72
+ captionElement.removeAttribute("role");
73
+ captionElement.removeAttribute("aria-live");
74
+ }
75
+
76
+ // focus the selected or today's date first
77
+ const selectedDay = ref.current?.querySelector(".DayPicker-Day--selected") || ref.current?.querySelector(".DayPicker-Day--today");
78
+ const firstDay = ref.current?.querySelector(".DayPicker-Day[tabindex='0']");
79
+
80
+ /* istanbul ignore else */
81
+ if (selectedDay && firstDay !== selectedDay) {
82
+ selectedDay?.setAttribute("tabindex", "0");
83
+ firstDay?.setAttribute("tabindex", "-1");
84
+ }
85
+ }
86
+ }, [open]);
61
87
  const handleDayClick = (date, modifiers, ev) => {
62
88
  if (!modifiers.disabled) {
63
89
  const {
@@ -72,6 +98,35 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
72
98
  onDayClick?.(date, ev);
73
99
  }
74
100
  };
101
+ const handleOnKeyDown = ev => {
102
+ if (Events.isEscKey(ev)) {
103
+ inputElement.current?.querySelector("input")?.focus();
104
+ setOpen(false);
105
+ }
106
+ if (ref.current?.querySelector(".DayPicker-NavBar button") === document.activeElement && Events.isTabKey(ev) && Events.isShiftKey(ev)) {
107
+ ev.preventDefault();
108
+ setOpen(false);
109
+ inputElement.current?.querySelector("input")?.focus();
110
+ }
111
+ };
112
+ const handleOnDayKeyDown = (_day, _modifiers, ev) => {
113
+ // we need to manually handle this as the picker may be in a Portal
114
+ /* istanbul ignore else */
115
+ if (Events.isTabKey(ev) && !Events.isShiftKey(ev)) {
116
+ ev.preventDefault();
117
+ setOpen(false);
118
+ const input = inputElement.current?.querySelector("input");
119
+
120
+ /* istanbul ignore else */
121
+ if (input) {
122
+ const elements = Array.from(document.querySelectorAll(defaultFocusableSelectors) || /* istanbul ignore next */[]);
123
+ const elementsInPicker = Array.from(ref.current?.querySelectorAll("button, [tabindex]") || /* istanbul ignore next */[]);
124
+ const filteredElements = elements.filter(el => Number(el.tabIndex) !== -1 && !elementsInPicker.includes(el));
125
+ const nextIndex = filteredElements.indexOf(input) + 1;
126
+ filteredElements[nextIndex]?.focus();
127
+ }
128
+ }
129
+ };
75
130
  const formatDay = date => `${weekdaysShort[date.getDay()]} ${date.getDate()} ${monthsShort[date.getMonth()]} ${date.getFullYear()}`;
76
131
  if (!open) {
77
132
  return null;
@@ -79,6 +134,9 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
79
134
  const localeUtils = {
80
135
  formatDay
81
136
  };
137
+ const handleTabGuardFocus = () => {
138
+ ref.current?.querySelector("button")?.focus();
139
+ };
82
140
  return /*#__PURE__*/React.createElement(Popover, {
83
141
  placement: "bottom-start",
84
142
  reference: inputElement,
@@ -86,8 +144,15 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
86
144
  disablePortal: disablePortal
87
145
  }, /*#__PURE__*/React.createElement(StyledDayPicker, {
88
146
  ref: ref,
89
- onMouseDown: pickerMouseDown
90
- }, /*#__PURE__*/React.createElement(DayPicker, _extends({
147
+ onMouseDown: pickerMouseDown,
148
+ onKeyDown: handleOnKeyDown
149
+ }, /*#__PURE__*/React.createElement("div", {
150
+ id: pickerTabGuardId
151
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
152
+ ,
153
+ tabIndex: 0,
154
+ onFocus: handleTabGuardFocus
155
+ }), /*#__PURE__*/React.createElement(DayPicker, _extends({
91
156
  month: selectedDays,
92
157
  months: monthsLong,
93
158
  firstDayOfWeek: weekStartsOn,
@@ -108,237 +173,9 @@ const DatePicker = /*#__PURE__*/React.forwardRef(({
108
173
  initialMonth: selectedDays || undefined,
109
174
  disabledDays: getDisabledDays(minDate, maxDate),
110
175
  locale: l.locale(),
111
- localeUtils: localeUtils
176
+ localeUtils: localeUtils,
177
+ onDayKeyDown: handleOnDayKeyDown
112
178
  }, pickerProps))));
113
- });
114
- DatePicker.propTypes = {
115
- "disablePortal": PropTypes.bool,
116
- "inputElement": PropTypes.shape({
117
- "current": function (props, propName) {
118
- if (props[propName] == null) {
119
- return null;
120
- } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
121
- return new Error("Expected prop '" + propName + "' to be of type Element");
122
- }
123
- }
124
- }).isRequired,
125
- "maxDate": PropTypes.string,
126
- "minDate": PropTypes.string,
127
- "onDayClick": PropTypes.func,
128
- "open": PropTypes.bool,
129
- "pickerMouseDown": PropTypes.func,
130
- "pickerProps": PropTypes.shape({
131
- "canChangeMonth": PropTypes.bool,
132
- "captionElement": PropTypes.oneOfType([PropTypes.element, PropTypes.func, PropTypes.shape({
133
- "childContextTypes": PropTypes.object,
134
- "contextType": PropTypes.shape({
135
- "Consumer": PropTypes.func.isRequired,
136
- "displayName": PropTypes.string,
137
- "Provider": PropTypes.func.isRequired
138
- }),
139
- "contextTypes": PropTypes.object,
140
- "defaultProps": PropTypes.shape({
141
- "classNames": PropTypes.object,
142
- "date": PropTypes.instanceOf(Date),
143
- "locale": PropTypes.string,
144
- "localeUtils": PropTypes.object,
145
- "months": PropTypes.arrayOf(PropTypes.string),
146
- "onClick": PropTypes.func
147
- }),
148
- "displayName": PropTypes.string,
149
- "getDerivedStateFromError": PropTypes.func,
150
- "getDerivedStateFromProps": PropTypes.func,
151
- "propTypes": PropTypes.shape({
152
- "classNames": PropTypes.func,
153
- "date": PropTypes.func,
154
- "locale": PropTypes.func,
155
- "localeUtils": PropTypes.func,
156
- "months": PropTypes.func,
157
- "onClick": PropTypes.func
158
- })
159
- })]),
160
- "className": PropTypes.string,
161
- "classNames": PropTypes.shape({
162
- "body": PropTypes.string.isRequired,
163
- "caption": PropTypes.string.isRequired,
164
- "container": PropTypes.string.isRequired,
165
- "day": PropTypes.string.isRequired,
166
- "disabled": PropTypes.string.isRequired,
167
- "footer": PropTypes.string.isRequired,
168
- "interactionDisabled": PropTypes.string.isRequired,
169
- "month": PropTypes.string.isRequired,
170
- "months": PropTypes.string.isRequired,
171
- "navBar": PropTypes.string.isRequired,
172
- "navButtonInteractionDisabled": PropTypes.string.isRequired,
173
- "navButtonNext": PropTypes.string.isRequired,
174
- "navButtonPrev": PropTypes.string.isRequired,
175
- "outside": PropTypes.string.isRequired,
176
- "selected": PropTypes.string.isRequired,
177
- "today": PropTypes.string.isRequired,
178
- "todayButton": PropTypes.string.isRequired,
179
- "week": PropTypes.string.isRequired,
180
- "weekday": PropTypes.string.isRequired,
181
- "weekdays": PropTypes.string.isRequired,
182
- "weekdaysRow": PropTypes.string.isRequired,
183
- "weekNumber": PropTypes.string.isRequired,
184
- "wrapper": PropTypes.string.isRequired
185
- }),
186
- "containerProps": PropTypes.object,
187
- "dir": PropTypes.string,
188
- "disabledDays": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.instanceOf(Date), PropTypes.shape({
189
- "from": PropTypes.instanceOf(Date),
190
- "to": PropTypes.instanceOf(Date)
191
- })])), PropTypes.func, PropTypes.instanceOf(Date), PropTypes.shape({
192
- "from": PropTypes.instanceOf(Date),
193
- "to": PropTypes.instanceOf(Date)
194
- })]),
195
- "enableOutsideDaysClick": PropTypes.bool,
196
- "firstDayOfWeek": PropTypes.number,
197
- "fixedWeeks": PropTypes.bool,
198
- "fromMonth": PropTypes.instanceOf(Date),
199
- "initialMonth": PropTypes.instanceOf(Date),
200
- "labels": PropTypes.shape({
201
- "nextMonth": PropTypes.string.isRequired,
202
- "previousMonth": PropTypes.string.isRequired
203
- }),
204
- "locale": PropTypes.string,
205
- "localeUtils": PropTypes.shape({
206
- "formatDate": PropTypes.func.isRequired,
207
- "formatDay": PropTypes.func.isRequired,
208
- "formatMonthTitle": PropTypes.func.isRequired,
209
- "formatWeekdayLong": PropTypes.func.isRequired,
210
- "formatWeekdayShort": PropTypes.func.isRequired,
211
- "getFirstDayOfWeek": PropTypes.func.isRequired,
212
- "getMonths": PropTypes.func.isRequired,
213
- "parseDate": PropTypes.func.isRequired
214
- }),
215
- "modifiers": PropTypes.shape({
216
- "outside": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.instanceOf(Date), PropTypes.shape({
217
- "from": PropTypes.instanceOf(Date),
218
- "to": PropTypes.instanceOf(Date)
219
- })])), PropTypes.func, PropTypes.instanceOf(Date), PropTypes.shape({
220
- "from": PropTypes.instanceOf(Date),
221
- "to": PropTypes.instanceOf(Date)
222
- })]),
223
- "today": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.instanceOf(Date), PropTypes.shape({
224
- "from": PropTypes.instanceOf(Date),
225
- "to": PropTypes.instanceOf(Date)
226
- })])), PropTypes.func, PropTypes.instanceOf(Date), PropTypes.shape({
227
- "from": PropTypes.instanceOf(Date),
228
- "to": PropTypes.instanceOf(Date)
229
- })])
230
- }),
231
- "modifiersStyles": PropTypes.object,
232
- "month": PropTypes.instanceOf(Date),
233
- "months": PropTypes.arrayOf(PropTypes.string),
234
- "navbarElement": PropTypes.oneOfType([PropTypes.element, PropTypes.func, PropTypes.shape({
235
- "childContextTypes": PropTypes.object,
236
- "contextType": PropTypes.shape({
237
- "Consumer": PropTypes.func.isRequired,
238
- "displayName": PropTypes.string,
239
- "Provider": PropTypes.func.isRequired
240
- }),
241
- "contextTypes": PropTypes.object,
242
- "defaultProps": PropTypes.shape({
243
- "className": PropTypes.string,
244
- "classNames": PropTypes.object,
245
- "dir": PropTypes.string,
246
- "labels": PropTypes.object,
247
- "locale": PropTypes.string,
248
- "localeUtils": PropTypes.object,
249
- "month": PropTypes.instanceOf(Date),
250
- "nextMonth": PropTypes.instanceOf(Date),
251
- "onNextClick": PropTypes.func,
252
- "onPreviousClick": PropTypes.func,
253
- "previousMonth": PropTypes.instanceOf(Date),
254
- "showNextButton": PropTypes.bool,
255
- "showPreviousButton": PropTypes.bool
256
- }),
257
- "displayName": PropTypes.string,
258
- "getDerivedStateFromError": PropTypes.func,
259
- "getDerivedStateFromProps": PropTypes.func,
260
- "propTypes": PropTypes.shape({
261
- "className": PropTypes.func,
262
- "classNames": PropTypes.func,
263
- "dir": PropTypes.func,
264
- "labels": PropTypes.func,
265
- "locale": PropTypes.func,
266
- "localeUtils": PropTypes.func,
267
- "month": PropTypes.func,
268
- "nextMonth": PropTypes.func,
269
- "onNextClick": PropTypes.func,
270
- "onPreviousClick": PropTypes.func,
271
- "previousMonth": PropTypes.func,
272
- "showNextButton": PropTypes.func,
273
- "showPreviousButton": PropTypes.func
274
- })
275
- })]),
276
- "numberOfMonths": PropTypes.number,
277
- "onBlur": PropTypes.func,
278
- "onCaptionClick": PropTypes.func,
279
- "onDayClick": PropTypes.func,
280
- "onDayKeyDown": PropTypes.func,
281
- "onDayMouseDown": PropTypes.func,
282
- "onDayMouseEnter": PropTypes.func,
283
- "onDayMouseLeave": PropTypes.func,
284
- "onDayMouseUp": PropTypes.func,
285
- "onDayTouchEnd": PropTypes.func,
286
- "onDayTouchStart": PropTypes.func,
287
- "onFocus": PropTypes.func,
288
- "onKeyDown": PropTypes.func,
289
- "onMonthChange": PropTypes.func,
290
- "onTodayButtonClick": PropTypes.func,
291
- "onWeekClick": PropTypes.func,
292
- "pagedNavigation": PropTypes.bool,
293
- "renderDay": PropTypes.func,
294
- "renderWeek": PropTypes.func,
295
- "reverseMonths": PropTypes.bool,
296
- "selectedDays": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.instanceOf(Date), PropTypes.shape({
297
- "from": PropTypes.instanceOf(Date),
298
- "to": PropTypes.instanceOf(Date)
299
- })])), PropTypes.func, PropTypes.instanceOf(Date), PropTypes.shape({
300
- "from": PropTypes.instanceOf(Date),
301
- "to": PropTypes.instanceOf(Date)
302
- })]),
303
- "showOutsideDays": PropTypes.bool,
304
- "showWeekDays": PropTypes.bool,
305
- "showWeekNumbers": PropTypes.bool,
306
- "tabIndex": PropTypes.number,
307
- "todayButton": PropTypes.string,
308
- "toMonth": PropTypes.instanceOf(Date),
309
- "weekdayElement": PropTypes.oneOfType([PropTypes.element, PropTypes.func, PropTypes.shape({
310
- "childContextTypes": PropTypes.object,
311
- "contextType": PropTypes.shape({
312
- "Consumer": PropTypes.func.isRequired,
313
- "displayName": PropTypes.string,
314
- "Provider": PropTypes.func.isRequired
315
- }),
316
- "contextTypes": PropTypes.object,
317
- "defaultProps": PropTypes.shape({
318
- "className": PropTypes.string,
319
- "locale": PropTypes.string,
320
- "localeUtils": PropTypes.object,
321
- "weekday": PropTypes.number,
322
- "weekdaysLong": PropTypes.arrayOf(PropTypes.string),
323
- "weekdaysShort": PropTypes.arrayOf(PropTypes.string)
324
- }),
325
- "displayName": PropTypes.string,
326
- "getDerivedStateFromError": PropTypes.func,
327
- "getDerivedStateFromProps": PropTypes.func,
328
- "propTypes": PropTypes.shape({
329
- "className": PropTypes.func,
330
- "locale": PropTypes.func,
331
- "localeUtils": PropTypes.func,
332
- "weekday": PropTypes.func,
333
- "weekdaysLong": PropTypes.func,
334
- "weekdaysShort": PropTypes.func
335
- })
336
- })]),
337
- "weekdaysLong": PropTypes.arrayOf(PropTypes.string),
338
- "weekdaysShort": PropTypes.arrayOf(PropTypes.string)
339
- }),
340
- "selectedDays": PropTypes.instanceOf(Date)
341
179
  };
342
- export { DatePicker };
343
180
  DatePicker.displayName = "DatePicker";
344
181
  export default DatePicker;
@@ -1,4 +1,4 @@
1
- import styled from "styled-components";
1
+ import styled, { css } from "styled-components";
2
2
  import baseTheme from "../../../../style/themes/base";
3
3
  import addFocusStyling from "../../../../style/utils/add-focus-styling";
4
4
  const oldFocusStyling = `
@@ -185,9 +185,14 @@ const StyledDayPicker = styled.div`
185
185
  position: absolute;
186
186
  height: 346px;
187
187
  width: 352px;
188
- z-index: ${({
188
+ ${({
189
189
  theme
190
- }) => theme.zIndex.popover};
190
+ }) => css`
191
+ z-index: ${theme.zIndex.popover};
192
+ ${!theme.focusRedesignOptOut && `
193
+ margin-top: var(--spacing050);
194
+ `}
195
+ `}
191
196
 
192
197
  .DayPicker {
193
198
  z-index: 1000;
@@ -3,19 +3,38 @@ import PropTypes from "prop-types";
3
3
  import StyledButton from "./button.style";
4
4
  import StyledNavbar from "./navbar.style";
5
5
  import Icon from "../../../icon";
6
+ import Events from "../../../../__internal__/utils/helpers/events";
7
+ import useLocale from "../../../../hooks/__internal__/useLocale";
6
8
  export const Navbar = ({
7
9
  onPreviousClick,
8
10
  onNextClick,
9
11
  className
10
- }) => /*#__PURE__*/React.createElement(StyledNavbar, {
11
- className: className
12
- }, /*#__PURE__*/React.createElement(StyledButton, {
13
- onClick: () => onPreviousClick?.()
14
- }, /*#__PURE__*/React.createElement(Icon, {
15
- type: "chevron_left"
16
- })), /*#__PURE__*/React.createElement(StyledButton, {
17
- onClick: () => onNextClick?.()
18
- }, /*#__PURE__*/React.createElement(Icon, {
19
- type: "chevron_right"
20
- })));
12
+ }) => {
13
+ const locale = useLocale();
14
+ const {
15
+ previousMonthButton,
16
+ nextMonthButton
17
+ } = locale.date.ariaLabels;
18
+ const handleKeyDown = ev => {
19
+ if (Events.isLeftKey(ev) || Events.isRightKey(ev) || Events.isUpKey(ev) || Events.isDownKey(ev)) {
20
+ ev.stopPropagation();
21
+ ev.preventDefault();
22
+ }
23
+ };
24
+ return /*#__PURE__*/React.createElement(StyledNavbar, {
25
+ className: className
26
+ }, /*#__PURE__*/React.createElement(StyledButton, {
27
+ "aria-label": previousMonthButton(),
28
+ onClick: () => onPreviousClick?.(),
29
+ onKeyDown: handleKeyDown
30
+ }, /*#__PURE__*/React.createElement(Icon, {
31
+ type: "chevron_left"
32
+ })), /*#__PURE__*/React.createElement(StyledButton, {
33
+ "aria-label": nextMonthButton(),
34
+ onClick: () => onNextClick?.(),
35
+ onKeyDown: handleKeyDown
36
+ }, /*#__PURE__*/React.createElement(Icon, {
37
+ type: "chevron_right"
38
+ })));
39
+ };
21
40
  export default Navbar;
@@ -13,6 +13,7 @@ import DateRangeContext from "../date-range/date-range.context";
13
13
  import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener";
14
14
  import Logger from "../../__internal__/utils/logger";
15
15
  import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
16
+ import guid from "../../__internal__/utils/helpers/guid";
16
17
  let deprecateInputRefWarnTriggered = false;
17
18
  const DateInput = /*#__PURE__*/React.forwardRef(({
18
19
  adaptiveLabelBreakpoint,
@@ -65,6 +66,7 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
65
66
  const [open, setOpen] = useState(false);
66
67
  const [selectedDays, setSelectedDays] = useState(checkISOFormatAndLength(value) ? parseISODate(value) : parseDate(format, value));
67
68
  const isInitialValue = useRef(true);
69
+ const pickerTabGuardId = useRef(guid());
68
70
  if (!deprecateInputRefWarnTriggered && inputRef) {
69
71
  deprecateInputRefWarnTriggered = true;
70
72
  Logger.deprecate("The `inputRef` prop in `DateInput` component is deprecated and will soon be removed. Please use `ref` instead.");
@@ -182,8 +184,16 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
182
184
  if (onKeyDown) {
183
185
  onKeyDown(ev);
184
186
  }
185
- if (Events.isTabKey(ev)) {
187
+ if (Events.isEscKey(ev)) {
186
188
  setOpen(false);
189
+ }
190
+ if (open && Events.isTabKey(ev)) {
191
+ if (Events.isShiftKey(ev)) {
192
+ setOpen(false);
193
+ } else if (!disablePortal) {
194
+ ev.preventDefault();
195
+ document?.querySelector(`[id="${pickerTabGuardId.current}"]`)?.focus();
196
+ }
187
197
  alreadyFocused.current = false;
188
198
  }
189
199
  };
@@ -311,7 +321,9 @@ const DateInput = /*#__PURE__*/React.forwardRef(({
311
321
  minDate: minDate,
312
322
  maxDate: maxDate,
313
323
  pickerMouseDown: handlePickerMouseDown,
314
- open: open
324
+ open: open,
325
+ setOpen: setOpen,
326
+ pickerTabGuardId: pickerTabGuardId.current
315
327
  }));
316
328
  });
317
329
  DateInput.propTypes = {
@@ -40,7 +40,6 @@ const Message = /*#__PURE__*/React.forwardRef(({
40
40
  className: className,
41
41
  transparent: transparent,
42
42
  variant: variant,
43
- role: "status",
44
43
  id: id,
45
44
  ref: refToPass
46
45
  }, marginProps, {
@@ -30,7 +30,11 @@ const enGB = {
30
30
  visuallyHiddenHint: formattedCount => `You can enter up to ${formattedCount} characters`
31
31
  },
32
32
  date: {
33
- dateFnsLocale: () => enGBDateLocale
33
+ dateFnsLocale: () => enGBDateLocale,
34
+ ariaLabels: {
35
+ previousMonthButton: () => "Previous month",
36
+ nextMonthButton: () => "Next month"
37
+ }
34
38
  },
35
39
  dialog: {
36
40
  ariaLabels: {
@@ -30,6 +30,10 @@ interface Locale {
30
30
  };
31
31
  date: {
32
32
  dateFnsLocale: () => DateFnsLocale;
33
+ ariaLabels: {
34
+ previousMonthButton: () => string;
35
+ nextMonthButton: () => string;
36
+ };
33
37
  };
34
38
  dialog: {
35
39
  ariaLabels: {
@@ -67,7 +67,11 @@ const plPL = {
67
67
  visuallyHiddenHint: formattedCount => `Można wprowadzić do ${formattedCount} znaków`
68
68
  },
69
69
  date: {
70
- dateFnsLocale: () => plDateLocale
70
+ dateFnsLocale: () => plDateLocale,
71
+ ariaLabels: {
72
+ previousMonthButton: () => "Poprzedni miesiąc",
73
+ nextMonthButton: () => "Następny miesiąc"
74
+ }
71
75
  },
72
76
  dialog: {
73
77
  ariaLabels: {
@@ -33,6 +33,13 @@ export interface DatePickerProps {
33
33
  open?: boolean;
34
34
  /** Callback triggered when a Day is clicked */
35
35
  onDayClick?: (date: Date, ev: React.MouseEvent<HTMLDivElement>) => void;
36
+ /** Sets the picker open state */
37
+ setOpen: (isOpen: boolean) => void;
38
+ /** Id passed to tab guard element */
39
+ pickerTabGuardId?: string;
36
40
  }
37
- export declare const DatePicker: React.ForwardRefExoticComponent<DatePickerProps & React.RefAttributes<HTMLDivElement>>;
41
+ export declare const DatePicker: {
42
+ ({ inputElement, minDate, maxDate, selectedDays, disablePortal, onDayClick, pickerMouseDown, pickerProps, open, setOpen, pickerTabGuardId, }: DatePickerProps): React.JSX.Element | null;
43
+ displayName: string;
44
+ };
38
45
  export default DatePicker;
@@ -14,6 +14,8 @@ var _useLocale = _interopRequireDefault(require("../../../../hooks/__internal__/
14
14
  var _navbar = _interopRequireDefault(require("../navbar"));
15
15
  var _weekday = _interopRequireDefault(require("../weekday"));
16
16
  var _dayPicker = _interopRequireDefault(require("./day-picker.style"));
17
+ var _events = _interopRequireDefault(require("../../../../__internal__/utils/helpers/events"));
18
+ var _focusTrapUtils = require("../../../../__internal__/focus-trap/focus-trap-utils");
17
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
21
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -23,7 +25,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
23
25
  const popoverMiddleware = [(0, _dom.offset)(3), (0, _dom.flip)({
24
26
  fallbackStrategy: "initialPlacement"
25
27
  })];
26
- const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
28
+ const DatePicker = ({
27
29
  inputElement,
28
30
  minDate,
29
31
  maxDate,
@@ -32,8 +34,10 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
32
34
  onDayClick,
33
35
  pickerMouseDown,
34
36
  pickerProps,
35
- open
36
- }, ref) => {
37
+ open,
38
+ setOpen,
39
+ pickerTabGuardId
40
+ }) => {
37
41
  const l = (0, _useLocale.default)();
38
42
  const {
39
43
  localize,
@@ -66,6 +70,28 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
66
70
  width: "abbreviated"
67
71
  }).substring(0, isGivenLocale("de") ? 2 : 3));
68
72
  }, [l, localize]);
73
+ const ref = (0, _react.useRef)(null);
74
+ (0, _react.useEffect)(() => {
75
+ if (open) {
76
+ // this is a temporary fix for some axe issues that are baked into the library we use for the picker
77
+ const captionElement = ref.current?.querySelector(".DayPicker-Caption");
78
+ /* istanbul ignore else */
79
+ if (captionElement) {
80
+ captionElement.removeAttribute("role");
81
+ captionElement.removeAttribute("aria-live");
82
+ }
83
+
84
+ // focus the selected or today's date first
85
+ const selectedDay = ref.current?.querySelector(".DayPicker-Day--selected") || ref.current?.querySelector(".DayPicker-Day--today");
86
+ const firstDay = ref.current?.querySelector(".DayPicker-Day[tabindex='0']");
87
+
88
+ /* istanbul ignore else */
89
+ if (selectedDay && firstDay !== selectedDay) {
90
+ selectedDay?.setAttribute("tabindex", "0");
91
+ firstDay?.setAttribute("tabindex", "-1");
92
+ }
93
+ }
94
+ }, [open]);
69
95
  const handleDayClick = (date, modifiers, ev) => {
70
96
  if (!modifiers.disabled) {
71
97
  const {
@@ -80,6 +106,35 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
80
106
  onDayClick?.(date, ev);
81
107
  }
82
108
  };
109
+ const handleOnKeyDown = ev => {
110
+ if (_events.default.isEscKey(ev)) {
111
+ inputElement.current?.querySelector("input")?.focus();
112
+ setOpen(false);
113
+ }
114
+ if (ref.current?.querySelector(".DayPicker-NavBar button") === document.activeElement && _events.default.isTabKey(ev) && _events.default.isShiftKey(ev)) {
115
+ ev.preventDefault();
116
+ setOpen(false);
117
+ inputElement.current?.querySelector("input")?.focus();
118
+ }
119
+ };
120
+ const handleOnDayKeyDown = (_day, _modifiers, ev) => {
121
+ // we need to manually handle this as the picker may be in a Portal
122
+ /* istanbul ignore else */
123
+ if (_events.default.isTabKey(ev) && !_events.default.isShiftKey(ev)) {
124
+ ev.preventDefault();
125
+ setOpen(false);
126
+ const input = inputElement.current?.querySelector("input");
127
+
128
+ /* istanbul ignore else */
129
+ if (input) {
130
+ const elements = Array.from(document.querySelectorAll(_focusTrapUtils.defaultFocusableSelectors) || /* istanbul ignore next */[]);
131
+ const elementsInPicker = Array.from(ref.current?.querySelectorAll("button, [tabindex]") || /* istanbul ignore next */[]);
132
+ const filteredElements = elements.filter(el => Number(el.tabIndex) !== -1 && !elementsInPicker.includes(el));
133
+ const nextIndex = filteredElements.indexOf(input) + 1;
134
+ filteredElements[nextIndex]?.focus();
135
+ }
136
+ }
137
+ };
83
138
  const formatDay = date => `${weekdaysShort[date.getDay()]} ${date.getDate()} ${monthsShort[date.getMonth()]} ${date.getFullYear()}`;
84
139
  if (!open) {
85
140
  return null;
@@ -87,6 +142,9 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
87
142
  const localeUtils = {
88
143
  formatDay
89
144
  };
145
+ const handleTabGuardFocus = () => {
146
+ ref.current?.querySelector("button")?.focus();
147
+ };
90
148
  return /*#__PURE__*/_react.default.createElement(_popover.default, {
91
149
  placement: "bottom-start",
92
150
  reference: inputElement,
@@ -94,8 +152,15 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
94
152
  disablePortal: disablePortal
95
153
  }, /*#__PURE__*/_react.default.createElement(_dayPicker.default, {
96
154
  ref: ref,
97
- onMouseDown: pickerMouseDown
98
- }, /*#__PURE__*/_react.default.createElement(_reactDayPicker.default, _extends({
155
+ onMouseDown: pickerMouseDown,
156
+ onKeyDown: handleOnKeyDown
157
+ }, /*#__PURE__*/_react.default.createElement("div", {
158
+ id: pickerTabGuardId
159
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
160
+ ,
161
+ tabIndex: 0,
162
+ onFocus: handleTabGuardFocus
163
+ }), /*#__PURE__*/_react.default.createElement(_reactDayPicker.default, _extends({
99
164
  month: selectedDays,
100
165
  months: monthsLong,
101
166
  firstDayOfWeek: weekStartsOn,
@@ -116,238 +181,11 @@ const DatePicker = /*#__PURE__*/_react.default.forwardRef(({
116
181
  initialMonth: selectedDays || undefined,
117
182
  disabledDays: (0, _utils.getDisabledDays)(minDate, maxDate),
118
183
  locale: l.locale(),
119
- localeUtils: localeUtils
184
+ localeUtils: localeUtils,
185
+ onDayKeyDown: handleOnDayKeyDown
120
186
  }, pickerProps))));
121
- });
122
- exports.DatePicker = DatePicker;
123
- DatePicker.propTypes = {
124
- "disablePortal": _propTypes.default.bool,
125
- "inputElement": _propTypes.default.shape({
126
- "current": function (props, propName) {
127
- if (props[propName] == null) {
128
- return null;
129
- } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
130
- return new Error("Expected prop '" + propName + "' to be of type Element");
131
- }
132
- }
133
- }).isRequired,
134
- "maxDate": _propTypes.default.string,
135
- "minDate": _propTypes.default.string,
136
- "onDayClick": _propTypes.default.func,
137
- "open": _propTypes.default.bool,
138
- "pickerMouseDown": _propTypes.default.func,
139
- "pickerProps": _propTypes.default.shape({
140
- "canChangeMonth": _propTypes.default.bool,
141
- "captionElement": _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func, _propTypes.default.shape({
142
- "childContextTypes": _propTypes.default.object,
143
- "contextType": _propTypes.default.shape({
144
- "Consumer": _propTypes.default.func.isRequired,
145
- "displayName": _propTypes.default.string,
146
- "Provider": _propTypes.default.func.isRequired
147
- }),
148
- "contextTypes": _propTypes.default.object,
149
- "defaultProps": _propTypes.default.shape({
150
- "classNames": _propTypes.default.object,
151
- "date": _propTypes.default.instanceOf(Date),
152
- "locale": _propTypes.default.string,
153
- "localeUtils": _propTypes.default.object,
154
- "months": _propTypes.default.arrayOf(_propTypes.default.string),
155
- "onClick": _propTypes.default.func
156
- }),
157
- "displayName": _propTypes.default.string,
158
- "getDerivedStateFromError": _propTypes.default.func,
159
- "getDerivedStateFromProps": _propTypes.default.func,
160
- "propTypes": _propTypes.default.shape({
161
- "classNames": _propTypes.default.func,
162
- "date": _propTypes.default.func,
163
- "locale": _propTypes.default.func,
164
- "localeUtils": _propTypes.default.func,
165
- "months": _propTypes.default.func,
166
- "onClick": _propTypes.default.func
167
- })
168
- })]),
169
- "className": _propTypes.default.string,
170
- "classNames": _propTypes.default.shape({
171
- "body": _propTypes.default.string.isRequired,
172
- "caption": _propTypes.default.string.isRequired,
173
- "container": _propTypes.default.string.isRequired,
174
- "day": _propTypes.default.string.isRequired,
175
- "disabled": _propTypes.default.string.isRequired,
176
- "footer": _propTypes.default.string.isRequired,
177
- "interactionDisabled": _propTypes.default.string.isRequired,
178
- "month": _propTypes.default.string.isRequired,
179
- "months": _propTypes.default.string.isRequired,
180
- "navBar": _propTypes.default.string.isRequired,
181
- "navButtonInteractionDisabled": _propTypes.default.string.isRequired,
182
- "navButtonNext": _propTypes.default.string.isRequired,
183
- "navButtonPrev": _propTypes.default.string.isRequired,
184
- "outside": _propTypes.default.string.isRequired,
185
- "selected": _propTypes.default.string.isRequired,
186
- "today": _propTypes.default.string.isRequired,
187
- "todayButton": _propTypes.default.string.isRequired,
188
- "week": _propTypes.default.string.isRequired,
189
- "weekday": _propTypes.default.string.isRequired,
190
- "weekdays": _propTypes.default.string.isRequired,
191
- "weekdaysRow": _propTypes.default.string.isRequired,
192
- "weekNumber": _propTypes.default.string.isRequired,
193
- "wrapper": _propTypes.default.string.isRequired
194
- }),
195
- "containerProps": _propTypes.default.object,
196
- "dir": _propTypes.default.string,
197
- "disabledDays": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.instanceOf(Date), _propTypes.default.shape({
198
- "from": _propTypes.default.instanceOf(Date),
199
- "to": _propTypes.default.instanceOf(Date)
200
- })])), _propTypes.default.func, _propTypes.default.instanceOf(Date), _propTypes.default.shape({
201
- "from": _propTypes.default.instanceOf(Date),
202
- "to": _propTypes.default.instanceOf(Date)
203
- })]),
204
- "enableOutsideDaysClick": _propTypes.default.bool,
205
- "firstDayOfWeek": _propTypes.default.number,
206
- "fixedWeeks": _propTypes.default.bool,
207
- "fromMonth": _propTypes.default.instanceOf(Date),
208
- "initialMonth": _propTypes.default.instanceOf(Date),
209
- "labels": _propTypes.default.shape({
210
- "nextMonth": _propTypes.default.string.isRequired,
211
- "previousMonth": _propTypes.default.string.isRequired
212
- }),
213
- "locale": _propTypes.default.string,
214
- "localeUtils": _propTypes.default.shape({
215
- "formatDate": _propTypes.default.func.isRequired,
216
- "formatDay": _propTypes.default.func.isRequired,
217
- "formatMonthTitle": _propTypes.default.func.isRequired,
218
- "formatWeekdayLong": _propTypes.default.func.isRequired,
219
- "formatWeekdayShort": _propTypes.default.func.isRequired,
220
- "getFirstDayOfWeek": _propTypes.default.func.isRequired,
221
- "getMonths": _propTypes.default.func.isRequired,
222
- "parseDate": _propTypes.default.func.isRequired
223
- }),
224
- "modifiers": _propTypes.default.shape({
225
- "outside": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.instanceOf(Date), _propTypes.default.shape({
226
- "from": _propTypes.default.instanceOf(Date),
227
- "to": _propTypes.default.instanceOf(Date)
228
- })])), _propTypes.default.func, _propTypes.default.instanceOf(Date), _propTypes.default.shape({
229
- "from": _propTypes.default.instanceOf(Date),
230
- "to": _propTypes.default.instanceOf(Date)
231
- })]),
232
- "today": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.instanceOf(Date), _propTypes.default.shape({
233
- "from": _propTypes.default.instanceOf(Date),
234
- "to": _propTypes.default.instanceOf(Date)
235
- })])), _propTypes.default.func, _propTypes.default.instanceOf(Date), _propTypes.default.shape({
236
- "from": _propTypes.default.instanceOf(Date),
237
- "to": _propTypes.default.instanceOf(Date)
238
- })])
239
- }),
240
- "modifiersStyles": _propTypes.default.object,
241
- "month": _propTypes.default.instanceOf(Date),
242
- "months": _propTypes.default.arrayOf(_propTypes.default.string),
243
- "navbarElement": _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func, _propTypes.default.shape({
244
- "childContextTypes": _propTypes.default.object,
245
- "contextType": _propTypes.default.shape({
246
- "Consumer": _propTypes.default.func.isRequired,
247
- "displayName": _propTypes.default.string,
248
- "Provider": _propTypes.default.func.isRequired
249
- }),
250
- "contextTypes": _propTypes.default.object,
251
- "defaultProps": _propTypes.default.shape({
252
- "className": _propTypes.default.string,
253
- "classNames": _propTypes.default.object,
254
- "dir": _propTypes.default.string,
255
- "labels": _propTypes.default.object,
256
- "locale": _propTypes.default.string,
257
- "localeUtils": _propTypes.default.object,
258
- "month": _propTypes.default.instanceOf(Date),
259
- "nextMonth": _propTypes.default.instanceOf(Date),
260
- "onNextClick": _propTypes.default.func,
261
- "onPreviousClick": _propTypes.default.func,
262
- "previousMonth": _propTypes.default.instanceOf(Date),
263
- "showNextButton": _propTypes.default.bool,
264
- "showPreviousButton": _propTypes.default.bool
265
- }),
266
- "displayName": _propTypes.default.string,
267
- "getDerivedStateFromError": _propTypes.default.func,
268
- "getDerivedStateFromProps": _propTypes.default.func,
269
- "propTypes": _propTypes.default.shape({
270
- "className": _propTypes.default.func,
271
- "classNames": _propTypes.default.func,
272
- "dir": _propTypes.default.func,
273
- "labels": _propTypes.default.func,
274
- "locale": _propTypes.default.func,
275
- "localeUtils": _propTypes.default.func,
276
- "month": _propTypes.default.func,
277
- "nextMonth": _propTypes.default.func,
278
- "onNextClick": _propTypes.default.func,
279
- "onPreviousClick": _propTypes.default.func,
280
- "previousMonth": _propTypes.default.func,
281
- "showNextButton": _propTypes.default.func,
282
- "showPreviousButton": _propTypes.default.func
283
- })
284
- })]),
285
- "numberOfMonths": _propTypes.default.number,
286
- "onBlur": _propTypes.default.func,
287
- "onCaptionClick": _propTypes.default.func,
288
- "onDayClick": _propTypes.default.func,
289
- "onDayKeyDown": _propTypes.default.func,
290
- "onDayMouseDown": _propTypes.default.func,
291
- "onDayMouseEnter": _propTypes.default.func,
292
- "onDayMouseLeave": _propTypes.default.func,
293
- "onDayMouseUp": _propTypes.default.func,
294
- "onDayTouchEnd": _propTypes.default.func,
295
- "onDayTouchStart": _propTypes.default.func,
296
- "onFocus": _propTypes.default.func,
297
- "onKeyDown": _propTypes.default.func,
298
- "onMonthChange": _propTypes.default.func,
299
- "onTodayButtonClick": _propTypes.default.func,
300
- "onWeekClick": _propTypes.default.func,
301
- "pagedNavigation": _propTypes.default.bool,
302
- "renderDay": _propTypes.default.func,
303
- "renderWeek": _propTypes.default.func,
304
- "reverseMonths": _propTypes.default.bool,
305
- "selectedDays": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.instanceOf(Date), _propTypes.default.shape({
306
- "from": _propTypes.default.instanceOf(Date),
307
- "to": _propTypes.default.instanceOf(Date)
308
- })])), _propTypes.default.func, _propTypes.default.instanceOf(Date), _propTypes.default.shape({
309
- "from": _propTypes.default.instanceOf(Date),
310
- "to": _propTypes.default.instanceOf(Date)
311
- })]),
312
- "showOutsideDays": _propTypes.default.bool,
313
- "showWeekDays": _propTypes.default.bool,
314
- "showWeekNumbers": _propTypes.default.bool,
315
- "tabIndex": _propTypes.default.number,
316
- "todayButton": _propTypes.default.string,
317
- "toMonth": _propTypes.default.instanceOf(Date),
318
- "weekdayElement": _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.func, _propTypes.default.shape({
319
- "childContextTypes": _propTypes.default.object,
320
- "contextType": _propTypes.default.shape({
321
- "Consumer": _propTypes.default.func.isRequired,
322
- "displayName": _propTypes.default.string,
323
- "Provider": _propTypes.default.func.isRequired
324
- }),
325
- "contextTypes": _propTypes.default.object,
326
- "defaultProps": _propTypes.default.shape({
327
- "className": _propTypes.default.string,
328
- "locale": _propTypes.default.string,
329
- "localeUtils": _propTypes.default.object,
330
- "weekday": _propTypes.default.number,
331
- "weekdaysLong": _propTypes.default.arrayOf(_propTypes.default.string),
332
- "weekdaysShort": _propTypes.default.arrayOf(_propTypes.default.string)
333
- }),
334
- "displayName": _propTypes.default.string,
335
- "getDerivedStateFromError": _propTypes.default.func,
336
- "getDerivedStateFromProps": _propTypes.default.func,
337
- "propTypes": _propTypes.default.shape({
338
- "className": _propTypes.default.func,
339
- "locale": _propTypes.default.func,
340
- "localeUtils": _propTypes.default.func,
341
- "weekday": _propTypes.default.func,
342
- "weekdaysLong": _propTypes.default.func,
343
- "weekdaysShort": _propTypes.default.func
344
- })
345
- })]),
346
- "weekdaysLong": _propTypes.default.arrayOf(_propTypes.default.string),
347
- "weekdaysShort": _propTypes.default.arrayOf(_propTypes.default.string)
348
- }),
349
- "selectedDays": _propTypes.default.instanceOf(Date)
350
187
  };
188
+ exports.DatePicker = DatePicker;
351
189
  DatePicker.displayName = "DatePicker";
352
190
  var _default = DatePicker;
353
191
  exports.default = _default;
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _styledComponents = _interopRequireDefault(require("styled-components"));
7
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
8
8
  var _base = _interopRequireDefault(require("../../../../style/themes/base"));
9
9
  var _addFocusStyling = _interopRequireDefault(require("../../../../style/utils/add-focus-styling"));
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
11
13
  const oldFocusStyling = `
12
14
  outline: solid 3px var(--colorsSemanticFocus500);
13
15
  `;
@@ -192,9 +194,14 @@ const StyledDayPicker = _styledComponents.default.div`
192
194
  position: absolute;
193
195
  height: 346px;
194
196
  width: 352px;
195
- z-index: ${({
197
+ ${({
196
198
  theme
197
- }) => theme.zIndex.popover};
199
+ }) => (0, _styledComponents.css)`
200
+ z-index: ${theme.zIndex.popover};
201
+ ${!theme.focusRedesignOptOut && `
202
+ margin-top: var(--spacing050);
203
+ `}
204
+ `}
198
205
 
199
206
  .DayPicker {
200
207
  z-index: 1000;
@@ -9,22 +9,41 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _button = _interopRequireDefault(require("./button.style"));
10
10
  var _navbar = _interopRequireDefault(require("./navbar.style"));
11
11
  var _icon = _interopRequireDefault(require("../../../icon"));
12
+ var _events = _interopRequireDefault(require("../../../../__internal__/utils/helpers/events"));
13
+ var _useLocale = _interopRequireDefault(require("../../../../hooks/__internal__/useLocale"));
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
  const Navbar = ({
14
16
  onPreviousClick,
15
17
  onNextClick,
16
18
  className
17
- }) => /*#__PURE__*/_react.default.createElement(_navbar.default, {
18
- className: className
19
- }, /*#__PURE__*/_react.default.createElement(_button.default, {
20
- onClick: () => onPreviousClick?.()
21
- }, /*#__PURE__*/_react.default.createElement(_icon.default, {
22
- type: "chevron_left"
23
- })), /*#__PURE__*/_react.default.createElement(_button.default, {
24
- onClick: () => onNextClick?.()
25
- }, /*#__PURE__*/_react.default.createElement(_icon.default, {
26
- type: "chevron_right"
27
- })));
19
+ }) => {
20
+ const locale = (0, _useLocale.default)();
21
+ const {
22
+ previousMonthButton,
23
+ nextMonthButton
24
+ } = locale.date.ariaLabels;
25
+ const handleKeyDown = ev => {
26
+ if (_events.default.isLeftKey(ev) || _events.default.isRightKey(ev) || _events.default.isUpKey(ev) || _events.default.isDownKey(ev)) {
27
+ ev.stopPropagation();
28
+ ev.preventDefault();
29
+ }
30
+ };
31
+ return /*#__PURE__*/_react.default.createElement(_navbar.default, {
32
+ className: className
33
+ }, /*#__PURE__*/_react.default.createElement(_button.default, {
34
+ "aria-label": previousMonthButton(),
35
+ onClick: () => onPreviousClick?.(),
36
+ onKeyDown: handleKeyDown
37
+ }, /*#__PURE__*/_react.default.createElement(_icon.default, {
38
+ type: "chevron_left"
39
+ })), /*#__PURE__*/_react.default.createElement(_button.default, {
40
+ "aria-label": nextMonthButton(),
41
+ onClick: () => onNextClick?.(),
42
+ onKeyDown: handleKeyDown
43
+ }, /*#__PURE__*/_react.default.createElement(_icon.default, {
44
+ type: "chevron_right"
45
+ })));
46
+ };
28
47
  exports.Navbar = Navbar;
29
48
  var _default = Navbar;
30
49
  exports.default = _default;
@@ -18,6 +18,7 @@ var _dateRange = _interopRequireDefault(require("../date-range/date-range.contex
18
18
  var _useClickAwayListener = _interopRequireDefault(require("../../hooks/__internal__/useClickAwayListener"));
19
19
  var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
20
20
  var _useFormSpacing = _interopRequireDefault(require("../../hooks/__internal__/useFormSpacing"));
21
+ var _guid = _interopRequireDefault(require("../../__internal__/utils/helpers/guid"));
21
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
24
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -74,6 +75,7 @@ const DateInput = /*#__PURE__*/_react.default.forwardRef(({
74
75
  const [open, setOpen] = (0, _react.useState)(false);
75
76
  const [selectedDays, setSelectedDays] = (0, _react.useState)((0, _utils.checkISOFormatAndLength)(value) ? (0, _utils.parseISODate)(value) : (0, _utils.parseDate)(format, value));
76
77
  const isInitialValue = (0, _react.useRef)(true);
78
+ const pickerTabGuardId = (0, _react.useRef)((0, _guid.default)());
77
79
  if (!deprecateInputRefWarnTriggered && inputRef) {
78
80
  deprecateInputRefWarnTriggered = true;
79
81
  _logger.default.deprecate("The `inputRef` prop in `DateInput` component is deprecated and will soon be removed. Please use `ref` instead.");
@@ -191,8 +193,16 @@ const DateInput = /*#__PURE__*/_react.default.forwardRef(({
191
193
  if (onKeyDown) {
192
194
  onKeyDown(ev);
193
195
  }
194
- if (_events.default.isTabKey(ev)) {
196
+ if (_events.default.isEscKey(ev)) {
195
197
  setOpen(false);
198
+ }
199
+ if (open && _events.default.isTabKey(ev)) {
200
+ if (_events.default.isShiftKey(ev)) {
201
+ setOpen(false);
202
+ } else if (!disablePortal) {
203
+ ev.preventDefault();
204
+ document?.querySelector(`[id="${pickerTabGuardId.current}"]`)?.focus();
205
+ }
196
206
  alreadyFocused.current = false;
197
207
  }
198
208
  };
@@ -320,7 +330,9 @@ const DateInput = /*#__PURE__*/_react.default.forwardRef(({
320
330
  minDate: minDate,
321
331
  maxDate: maxDate,
322
332
  pickerMouseDown: handlePickerMouseDown,
323
- open: open
333
+ open: open,
334
+ setOpen: setOpen,
335
+ pickerTabGuardId: pickerTabGuardId.current
324
336
  }));
325
337
  });
326
338
  exports.DateInput = DateInput;
@@ -49,7 +49,6 @@ const Message = /*#__PURE__*/_react.default.forwardRef(({
49
49
  className: className,
50
50
  transparent: transparent,
51
51
  variant: variant,
52
- role: "status",
53
52
  id: id,
54
53
  ref: refToPass
55
54
  }, marginProps, {
@@ -36,7 +36,11 @@ const enGB = {
36
36
  visuallyHiddenHint: formattedCount => `You can enter up to ${formattedCount} characters`
37
37
  },
38
38
  date: {
39
- dateFnsLocale: () => _dateFnsLocales.enGB
39
+ dateFnsLocale: () => _dateFnsLocales.enGB,
40
+ ariaLabels: {
41
+ previousMonthButton: () => "Previous month",
42
+ nextMonthButton: () => "Next month"
43
+ }
40
44
  },
41
45
  dialog: {
42
46
  ariaLabels: {
@@ -30,6 +30,10 @@ interface Locale {
30
30
  };
31
31
  date: {
32
32
  dateFnsLocale: () => DateFnsLocale;
33
+ ariaLabels: {
34
+ previousMonthButton: () => string;
35
+ nextMonthButton: () => string;
36
+ };
33
37
  };
34
38
  dialog: {
35
39
  ariaLabels: {
@@ -74,7 +74,11 @@ const plPL = {
74
74
  visuallyHiddenHint: formattedCount => `Można wprowadzić do ${formattedCount} znaków`
75
75
  },
76
76
  date: {
77
- dateFnsLocale: () => _dateFnsLocales.pl
77
+ dateFnsLocale: () => _dateFnsLocales.pl,
78
+ ariaLabels: {
79
+ previousMonthButton: () => "Poprzedni miesiąc",
80
+ nextMonthButton: () => "Następny miesiąc"
81
+ }
78
82
  },
79
83
  dialog: {
80
84
  ariaLabels: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "123.2.2",
3
+ "version": "123.4.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",