@simplybusiness/mobius-datepicker 7.0.0 → 7.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6c33527: Add accessibility changes
8
+
9
+ ### Patch Changes
10
+
11
+ - e587a8f: placeholder text style on date picker
12
+ - Updated dependencies [f902a17]
13
+ - Updated dependencies [d3d22b2]
14
+ - Updated dependencies [4e7ea0b]
15
+ - @simplybusiness/mobius@6.1.0
16
+
3
17
  ## 7.0.0
4
18
 
5
19
  ### Major Changes
package/dist/cjs/index.js CHANGED
@@ -144,7 +144,7 @@ var init_useFocusTrap = __esm({
144
144
  if (containerRef.current) {
145
145
  const element = containerRef.current;
146
146
  const focusableElements = containerRef.current.querySelectorAll(
147
- '.rdp-nav_button, [tabindex="0"]'
147
+ '[tabindex="0"], .mobius-date-picker__nav-button'
148
148
  );
149
149
  const firstElement = focusableElements[0];
150
150
  const lastElement = focusableElements[focusableElements.length - 1];
@@ -153,7 +153,9 @@ var init_useFocusTrap = __esm({
153
153
  if (event.shiftKey && document.activeElement === firstElement) {
154
154
  event.preventDefault();
155
155
  lastElement.focus();
156
- } else if (!event.shiftKey && document.activeElement && document.activeElement.className.indexOf("rdp-day") > -1) {
156
+ } else if (!event.shiftKey && document.activeElement && document.activeElement.className.indexOf(
157
+ "mobius-date-picker__day-button"
158
+ ) > -1) {
157
159
  event.preventDefault();
158
160
  firstElement.focus();
159
161
  }
@@ -203,18 +205,55 @@ var init_timezoneOffset = __esm({
203
205
  }
204
206
  });
205
207
 
208
+ // src/components/DatePicker/CustomComponents/CaptionLabel.tsx
209
+ var import_jsx_runtime2, CaptionLabel;
210
+ var init_CaptionLabel = __esm({
211
+ "src/components/DatePicker/CustomComponents/CaptionLabel.tsx"() {
212
+ "use strict";
213
+ import_jsx_runtime2 = require("react/jsx-runtime");
214
+ CaptionLabel = (props) => {
215
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { ...props });
216
+ };
217
+ }
218
+ });
219
+
220
+ // src/components/DatePicker/CustomComponents/ChevronComponent.tsx
221
+ var import_icons, import_mobius, import_jsx_runtime3, ChevronComponent;
222
+ var init_ChevronComponent = __esm({
223
+ "src/components/DatePicker/CustomComponents/ChevronComponent.tsx"() {
224
+ "use strict";
225
+ import_icons = require("@simplybusiness/icons");
226
+ import_mobius = require("@simplybusiness/mobius");
227
+ import_jsx_runtime3 = require("react/jsx-runtime");
228
+ ChevronComponent = ({ orientation }) => {
229
+ if (orientation === "left") {
230
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mobius.Icon, { icon: import_icons.chevronLeft });
231
+ }
232
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mobius.Icon, { icon: import_icons.chevronRight });
233
+ };
234
+ }
235
+ });
236
+
237
+ // src/components/DatePicker/CustomComponents/index.tsx
238
+ var init_CustomComponents = __esm({
239
+ "src/components/DatePicker/CustomComponents/index.tsx"() {
240
+ "use strict";
241
+ init_CaptionLabel();
242
+ init_ChevronComponent();
243
+ }
244
+ });
245
+
206
246
  // src/components/DatePicker/DatePickerModal.tsx
207
247
  var DatePickerModal_exports = {};
208
248
  __export(DatePickerModal_exports, {
209
249
  default: () => DatePickerModal_default
210
250
  });
211
- var import_icons, import_mobius, import_dedupe, import_date_fns3, import_react2, import_react_day_picker, import_jsx_runtime2, PARENT_NODE, ChevronComponent, startWeekday, DatePickerModal, DatePickerModal_default;
251
+ var import_mobius2, import_dedupe, import_date_fns3, import_react2, import_react_day_picker, import_jsx_runtime4, startWeekday, DatePickerModal, DatePickerModal_default;
212
252
  var init_DatePickerModal = __esm({
213
253
  "src/components/DatePicker/DatePickerModal.tsx"() {
214
254
  "use strict";
215
255
  "use client";
216
- import_icons = require("@simplybusiness/icons");
217
- import_mobius = require("@simplybusiness/mobius");
256
+ import_mobius2 = require("@simplybusiness/mobius");
218
257
  import_dedupe = __toESM(require("classnames/dedupe"));
219
258
  import_date_fns3 = require("date-fns");
220
259
  import_react2 = require("react");
@@ -223,16 +262,8 @@ var init_DatePickerModal = __esm({
223
262
  init_utils();
224
263
  init_getStartWeekday();
225
264
  init_timezoneOffset();
226
- import_jsx_runtime2 = require("react/jsx-runtime");
227
- PARENT_NODE = typeof document !== "undefined" && document.body;
228
- ChevronComponent = ({
229
- orientation
230
- }) => {
231
- if (orientation === "left") {
232
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mobius.Icon, { icon: import_icons.chevronLeft });
233
- }
234
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mobius.Icon, { icon: import_icons.chevronRight });
235
- };
265
+ init_CustomComponents();
266
+ import_jsx_runtime4 = require("react/jsx-runtime");
236
267
  startWeekday = getStartWeekday(
237
268
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
238
269
  typeof navigator !== "undefined" ? navigator?.language : void 0
@@ -250,18 +281,14 @@ var init_DatePickerModal = __esm({
250
281
  const minDate = min ? toLocal(min) : void 0;
251
282
  const maxDate = max ? toLocal(max) : void 0;
252
283
  const hiddenId = `screen-reader-title-${(0, import_react2.useId)()}`;
253
- if (isOpen && PARENT_NODE) {
254
- PARENT_NODE?.setAttribute("aria-hidden", "true");
255
- }
256
284
  const handleSelected = (selectedDate) => {
257
- if (PARENT_NODE) PARENT_NODE?.removeAttribute("aria-hidden");
258
285
  onSelected(selectedDate);
259
286
  };
260
287
  const handleDayPickerSelect = (selectedDate) => {
261
288
  if (!selectedDate) return;
262
289
  handleSelected(dateObjToString(selectedDate));
263
290
  };
264
- (0, import_mobius.useOnClickOutside)(modalRef, () => {
291
+ (0, import_mobius2.useOnClickOutside)(modalRef, () => {
265
292
  if (modalRef.current && isOpen) {
266
293
  handleSelected();
267
294
  }
@@ -269,7 +296,7 @@ var init_DatePickerModal = __esm({
269
296
  const modalClasses = (0, import_dedupe.default)("mobius-date-picker__modal", {
270
297
  "--is-open": isOpen
271
298
  });
272
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FocusTrap, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
299
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FocusTrap, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
273
300
  "div",
274
301
  {
275
302
  ref: modalRef,
@@ -278,10 +305,11 @@ var init_DatePickerModal = __esm({
278
305
  "aria-describedby": hiddenId,
279
306
  "data-testid": "modal-container",
280
307
  children: [
281
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_mobius.VisuallyHidden, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { id: hiddenId, children: "Please select a date from the calendar" }) }),
282
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
308
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_mobius2.VisuallyHidden, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { id: hiddenId, children: "Please select a date from the calendar" }) }),
309
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
283
310
  import_react_day_picker.DayPicker,
284
311
  {
312
+ autoFocus: true,
285
313
  mode: "single",
286
314
  ...minDate && { startMonth: minDate },
287
315
  ...maxDate && { endMonth: maxDate },
@@ -297,7 +325,8 @@ var init_DatePickerModal = __esm({
297
325
  weekStartsOn: startWeekday,
298
326
  formatters: { formatWeekdayName: weekdayAsOneLetter },
299
327
  components: {
300
- Chevron: ChevronComponent
328
+ Chevron: ChevronComponent,
329
+ CaptionLabel
301
330
  },
302
331
  classNames: {
303
332
  root: "mobius-date-picker__root",
@@ -341,7 +370,7 @@ module.exports = __toCommonJS(index_exports);
341
370
 
342
371
  // src/components/DatePicker/DatePicker.tsx
343
372
  var import_icons2 = require("@simplybusiness/icons");
344
- var import_mobius2 = require("@simplybusiness/mobius");
373
+ var import_mobius3 = require("@simplybusiness/mobius");
345
374
  var import_dedupe2 = __toESM(require("classnames/dedupe"));
346
375
  var import_react3 = require("react");
347
376
 
@@ -355,7 +384,7 @@ var isTouchDevice = () => {
355
384
 
356
385
  // src/components/DatePicker/DatePicker.tsx
357
386
  init_utils();
358
- var import_jsx_runtime3 = require("react/jsx-runtime");
387
+ var import_jsx_runtime5 = require("react/jsx-runtime");
359
388
  var DatePickerModal2 = (0, import_react3.lazy)(() => Promise.resolve().then(() => (init_DatePickerModal(), DatePickerModal_exports)));
360
389
  var getValidationState = (props) => {
361
390
  const { validationState, isInvalid } = props;
@@ -391,7 +420,7 @@ var DatePicker = (props) => {
391
420
  });
392
421
  const errorMessageText = isInvalidProp ? formatErrorMessageText(textFieldVal, props.min, props.max) : errorMessage;
393
422
  const touchDevice = isTouchDevice();
394
- const validationClasses = (0, import_mobius2.useValidationClasses)({
423
+ const validationClasses = (0, import_mobius3.useValidationClasses)({
395
424
  validationState,
396
425
  isInvalid: isInvalidProp
397
426
  });
@@ -408,6 +437,7 @@ var DatePicker = (props) => {
408
437
  validationClasses
409
438
  );
410
439
  const validate = () => {
440
+ if (isOpen) return;
411
441
  const isValidInput = inputRef.current?.checkValidity();
412
442
  if (!isValidInput) {
413
443
  setIsValid(false);
@@ -435,9 +465,13 @@ var DatePicker = (props) => {
435
465
  setIsValid(true);
436
466
  onChange?.(selectedDate);
437
467
  }
468
+ inputRef.current?.focus();
438
469
  setIsOpen(false);
439
470
  };
440
471
  const handleBlur = (event) => {
472
+ if (isOpen && event.relatedTarget && containerRef.current?.contains(event.relatedTarget)) {
473
+ return;
474
+ }
441
475
  validate();
442
476
  if (!textFieldVal) {
443
477
  setIsValid(false);
@@ -457,8 +491,8 @@ var DatePicker = (props) => {
457
491
  validate();
458
492
  }, [isOpen]);
459
493
  if (touchDevice) {
460
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: containerClasses, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
461
- import_mobius2.TextField,
494
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: containerClasses, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
495
+ import_mobius3.TextField,
462
496
  {
463
497
  ref: inputRef,
464
498
  type: "date",
@@ -473,9 +507,9 @@ var DatePicker = (props) => {
473
507
  }
474
508
  ) });
475
509
  }
476
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: containerClasses, ref: containerRef, children: [
477
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
478
- import_mobius2.TextField,
510
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: containerClasses, ref: containerRef, children: [
511
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
512
+ import_mobius3.TextField,
479
513
  {
480
514
  ref: inputRef,
481
515
  type: "date",
@@ -488,22 +522,22 @@ var DatePicker = (props) => {
488
522
  isInvalid: isInvalidProp,
489
523
  ...otherProps,
490
524
  errorMessage: errorMessage || errorMessageText,
491
- suffixOutside: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
492
- import_mobius2.Button,
525
+ suffixOutside: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
526
+ import_mobius3.Button,
493
527
  {
494
528
  className: popoverToggleClasses,
495
529
  onClick: togglePopoverVisibility,
496
530
  isDisabled,
497
531
  size: "sm",
498
532
  children: [
499
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mobius2.Icon, { size: "sm", icon: import_icons2.calendarDay }),
500
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mobius2.VisuallyHidden, { children: "Pick date" })
533
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mobius3.Icon, { size: "sm", icon: import_icons2.calendarDay }),
534
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_mobius3.VisuallyHidden, { children: "Pick date" })
501
535
  ]
502
536
  }
503
537
  )
504
538
  }
505
539
  ),
506
- isOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react3.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
540
+ isOpen && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react3.Suspense, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
507
541
  DatePickerModal2,
508
542
  {
509
543
  date: textFieldVal,
@@ -1,12 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  // src/components/DatePicker/DatePickerModal.tsx
4
- import { chevronLeft, chevronRight } from "@simplybusiness/icons";
5
- import {
6
- Icon,
7
- VisuallyHidden,
8
- useOnClickOutside
9
- } from "@simplybusiness/mobius";
4
+ import { VisuallyHidden, useOnClickOutside } from "@simplybusiness/mobius";
10
5
  import classNames from "classnames/dedupe";
11
6
  import { parseISO } from "date-fns";
12
7
  import { useId, useRef as useRef2 } from "react";
@@ -21,7 +16,7 @@ var useFocusTrap = () => {
21
16
  if (containerRef.current) {
22
17
  const element = containerRef.current;
23
18
  const focusableElements = containerRef.current.querySelectorAll(
24
- '.rdp-nav_button, [tabindex="0"]'
19
+ '[tabindex="0"], .mobius-date-picker__nav-button'
25
20
  );
26
21
  const firstElement = focusableElements[0];
27
22
  const lastElement = focusableElements[focusableElements.length - 1];
@@ -30,7 +25,9 @@ var useFocusTrap = () => {
30
25
  if (event.shiftKey && document.activeElement === firstElement) {
31
26
  event.preventDefault();
32
27
  lastElement.focus();
33
- } else if (!event.shiftKey && document.activeElement && document.activeElement.className.indexOf("rdp-day") > -1) {
28
+ } else if (!event.shiftKey && document.activeElement && document.activeElement.className.indexOf(
29
+ "mobius-date-picker__day-button"
30
+ ) > -1) {
34
31
  event.preventDefault();
35
32
  firstElement.focus();
36
33
  }
@@ -92,17 +89,25 @@ function toLocal(utcDateString) {
92
89
  return new Date(utcDate.getTime() + utcDate.getTimezoneOffset() * 6e4);
93
90
  }
94
91
 
95
- // src/components/DatePicker/DatePickerModal.tsx
96
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
97
- var PARENT_NODE = typeof document !== "undefined" && document.body;
98
- var ChevronComponent = ({
99
- orientation
100
- }) => {
92
+ // src/components/DatePicker/CustomComponents/CaptionLabel.tsx
93
+ import { jsx as jsx2 } from "react/jsx-runtime";
94
+ var CaptionLabel = (props) => {
95
+ return /* @__PURE__ */ jsx2("h2", { ...props });
96
+ };
97
+
98
+ // src/components/DatePicker/CustomComponents/ChevronComponent.tsx
99
+ import { chevronLeft, chevronRight } from "@simplybusiness/icons";
100
+ import { Icon } from "@simplybusiness/mobius";
101
+ import { jsx as jsx3 } from "react/jsx-runtime";
102
+ var ChevronComponent = ({ orientation }) => {
101
103
  if (orientation === "left") {
102
- return /* @__PURE__ */ jsx2(Icon, { icon: chevronLeft });
104
+ return /* @__PURE__ */ jsx3(Icon, { icon: chevronLeft });
103
105
  }
104
- return /* @__PURE__ */ jsx2(Icon, { icon: chevronRight });
106
+ return /* @__PURE__ */ jsx3(Icon, { icon: chevronRight });
105
107
  };
108
+
109
+ // src/components/DatePicker/DatePickerModal.tsx
110
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
106
111
  var startWeekday = getStartWeekday(
107
112
  // eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
108
113
  typeof navigator !== "undefined" ? navigator?.language : void 0
@@ -120,11 +125,7 @@ var DatePickerModal = ({
120
125
  const minDate = min ? toLocal(min) : void 0;
121
126
  const maxDate = max ? toLocal(max) : void 0;
122
127
  const hiddenId = `screen-reader-title-${useId()}`;
123
- if (isOpen && PARENT_NODE) {
124
- PARENT_NODE?.setAttribute("aria-hidden", "true");
125
- }
126
128
  const handleSelected = (selectedDate) => {
127
- if (PARENT_NODE) PARENT_NODE?.removeAttribute("aria-hidden");
128
129
  onSelected(selectedDate);
129
130
  };
130
131
  const handleDayPickerSelect = (selectedDate) => {
@@ -139,7 +140,7 @@ var DatePickerModal = ({
139
140
  const modalClasses = classNames("mobius-date-picker__modal", {
140
141
  "--is-open": isOpen
141
142
  });
142
- return /* @__PURE__ */ jsx2(FocusTrap, { children: /* @__PURE__ */ jsxs(
143
+ return /* @__PURE__ */ jsx4(FocusTrap, { children: /* @__PURE__ */ jsxs(
143
144
  "div",
144
145
  {
145
146
  ref: modalRef,
@@ -148,10 +149,11 @@ var DatePickerModal = ({
148
149
  "aria-describedby": hiddenId,
149
150
  "data-testid": "modal-container",
150
151
  children: [
151
- /* @__PURE__ */ jsx2(VisuallyHidden, { children: /* @__PURE__ */ jsx2("div", { id: hiddenId, children: "Please select a date from the calendar" }) }),
152
- /* @__PURE__ */ jsx2(
152
+ /* @__PURE__ */ jsx4(VisuallyHidden, { children: /* @__PURE__ */ jsx4("div", { id: hiddenId, children: "Please select a date from the calendar" }) }),
153
+ /* @__PURE__ */ jsx4(
153
154
  DayPicker,
154
155
  {
156
+ autoFocus: true,
155
157
  mode: "single",
156
158
  ...minDate && { startMonth: minDate },
157
159
  ...maxDate && { endMonth: maxDate },
@@ -167,7 +169,8 @@ var DatePickerModal = ({
167
169
  weekStartsOn: startWeekday,
168
170
  formatters: { formatWeekdayName: weekdayAsOneLetter },
169
171
  components: {
170
- Chevron: ChevronComponent
172
+ Chevron: ChevronComponent,
173
+ CaptionLabel
171
174
  },
172
175
  classNames: {
173
176
  root: "mobius-date-picker__root",
package/dist/esm/index.js CHANGED
@@ -59,7 +59,7 @@ var validateDateFormat = (date) => {
59
59
 
60
60
  // src/components/DatePicker/DatePicker.tsx
61
61
  import { jsx, jsxs } from "react/jsx-runtime";
62
- var DatePickerModal = lazy(() => import("./DatePickerModal-AC36MP2W.js"));
62
+ var DatePickerModal = lazy(() => import("./DatePickerModal-CHBI5WBW.js"));
63
63
  var getValidationState = (props) => {
64
64
  const { validationState, isInvalid } = props;
65
65
  if (isInvalid || validationState === "invalid") {
@@ -111,6 +111,7 @@ var DatePicker = (props) => {
111
111
  validationClasses
112
112
  );
113
113
  const validate = () => {
114
+ if (isOpen) return;
114
115
  const isValidInput = inputRef.current?.checkValidity();
115
116
  if (!isValidInput) {
116
117
  setIsValid(false);
@@ -138,9 +139,13 @@ var DatePicker = (props) => {
138
139
  setIsValid(true);
139
140
  onChange?.(selectedDate);
140
141
  }
142
+ inputRef.current?.focus();
141
143
  setIsOpen(false);
142
144
  };
143
145
  const handleBlur = (event) => {
146
+ if (isOpen && event.relatedTarget && containerRef.current?.contains(event.relatedTarget)) {
147
+ return;
148
+ }
144
149
  validate();
145
150
  if (!textFieldVal) {
146
151
  setIsValid(false);