@entur/datepicker 11.3.0 → 11.4.0-beta.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.
@@ -191,6 +191,11 @@ function handleOnChange({
191
191
  }
192
192
  onChange?.(value);
193
193
  }
194
+ function getAdjustedMaxDate(maxDate) {
195
+ if ("hour" in (maxDate ?? {})) return maxDate;
196
+ if (maxDate !== void 0) return lastMillisecondOfDay(maxDate);
197
+ return void 0;
198
+ }
194
199
  const DateField = ({
195
200
  selectedDate,
196
201
  onChange,
@@ -235,8 +240,7 @@ const DateField = ({
235
240
  hideTimeZone: !showTimeZone,
236
241
  granularity,
237
242
  minValue: minDate,
238
- // this weird logic makes sure the entire day is included if no time is provided in maxDate
239
- maxValue: "hour" in (maxDate ?? {}) ? maxDate : maxDate !== void 0 ? lastMillisecondOfDay(maxDate) : void 0,
243
+ maxValue: getAdjustedMaxDate(maxDate),
240
244
  isDisabled: isDisabled || disabled || readOnly,
241
245
  shouldForceLeadingZeros: true
242
246
  };
@@ -290,6 +294,7 @@ const CalendarButton = ({
290
294
  const CalendarCell = ({
291
295
  state,
292
296
  date,
297
+ showOutsideMonth = false,
293
298
  onSelectedCellClick = () => {
294
299
  return;
295
300
  },
@@ -312,20 +317,37 @@ const CalendarCell = ({
312
317
  formattedDate
313
318
  } = useCalendarCell({ date }, state, cellRef);
314
319
  const ariaLabel = `${buttonProps["aria-label"]}${weekNumberString} ${ariaLabelForDate?.(date) ?? ""}`;
315
- const cellCanBeSelected = !(isOutsideVisibleRange || isDisabled || isUnavailable);
320
+ const cellCanBeSelected = showOutsideMonth ? !(isDisabled || isUnavailable) : !(isOutsideVisibleRange || isDisabled || isUnavailable);
321
+ const shouldHideDate = !showOutsideMonth && isOutsideVisibleRange;
322
+ const extendedButtonProps = {
323
+ ...buttonProps,
324
+ ...showOutsideMonth && isOutsideVisibleRange && {
325
+ onClick: () => {
326
+ state.selectDate(date);
327
+ onCellClick();
328
+ },
329
+ onKeyUp: (e) => {
330
+ if (e.key === "Enter") {
331
+ state.selectDate(date);
332
+ onCellClick();
333
+ }
334
+ }
335
+ }
336
+ };
316
337
  return /* @__PURE__ */ jsx("td", { ...cellProps, className: "eds-datepicker__calendar__grid__cell__td", children: /* @__PURE__ */ jsx(
317
338
  "div",
318
339
  {
319
- ...buttonProps,
340
+ ...extendedButtonProps,
320
341
  "aria-label": ariaLabel,
321
- "aria-hidden": isOutsideVisibleRange,
342
+ "aria-hidden": shouldHideDate,
322
343
  ref: cellRef,
323
- hidden: isOutsideVisibleRange,
344
+ hidden: shouldHideDate,
324
345
  className: classNames("eds-datepicker__calendar__grid__cell", {
325
- [classNameForDate?.(date) ?? ""]: !isOutsideVisibleRange,
346
+ [classNameForDate?.(date) ?? ""]: !shouldHideDate,
326
347
  "eds-datepicker__calendar__grid__cell--selected": isSelected,
327
348
  "eds-datepicker__calendar__grid__cell--disabled": isDisabled || isUnavailable,
328
- "eds-datepicker__calendar__grid__cell--outside-month": isOutsideVisibleRange,
349
+ "eds-datepicker__calendar__grid__cell--outside-month": isOutsideVisibleRange && !showOutsideMonth,
350
+ "eds-datepicker__calendar__grid__cell--outside-month--visible": isOutsideVisibleRange && showOutsideMonth,
329
351
  "eds-datepicker__calendar__grid__cell--today": isEqualDay(
330
352
  date,
331
353
  now(state.timeZone ?? getLocalTimeZone())
@@ -333,12 +355,12 @@ const CalendarCell = ({
333
355
  }),
334
356
  ...rest,
335
357
  onClick: (e) => {
336
- buttonProps.onClick && buttonProps.onClick(e);
358
+ extendedButtonProps?.onClick?.(e);
337
359
  isSelected && onSelectedCellClick();
338
360
  cellCanBeSelected && onCellClick();
339
361
  },
340
362
  onKeyUp: (e) => {
341
- buttonProps.onKeyUp && buttonProps.onKeyUp(e);
363
+ extendedButtonProps?.onKeyUp?.(e);
342
364
  if (e.key === "Enter") {
343
365
  isSelected && onSelectedCellClick();
344
366
  cellCanBeSelected && onCellClick();
@@ -359,6 +381,7 @@ const CalendarGrid = ({
359
381
  },
360
382
  showWeekNumbers,
361
383
  weekNumberHeader,
384
+ showOutsideMonth = false,
362
385
  classNameForDate,
363
386
  ariaLabelForDate,
364
387
  ...rest
@@ -405,7 +428,7 @@ const CalendarGrid = ({
405
428
  showWeekNumbers && /* @__PURE__ */ jsx(
406
429
  "th",
407
430
  {
408
- "aria-hidden": true,
431
+ "aria-label": `${weekNumberHeader} ${weekNumber}`,
409
432
  className: "eds-datepicker__calendar__grid__weeknumber",
410
433
  children: weekNumber
411
434
  }
@@ -421,7 +444,8 @@ const CalendarGrid = ({
421
444
  onSelectedCellClick,
422
445
  onCellClick,
423
446
  classNameForDate,
424
- ariaLabelForDate
447
+ ariaLabelForDate,
448
+ showOutsideMonth
425
449
  },
426
450
  `${date.month}.${date.day}`
427
451
  ) : /* @__PURE__ */ jsx("td", {}, i)
@@ -449,6 +473,7 @@ const CalendarBase = ({
449
473
  maxDate,
450
474
  showWeekNumbers = false,
451
475
  weekNumberHeader = "uke",
476
+ showOutsideMonth = false,
452
477
  forcedReturnType,
453
478
  style,
454
479
  className,
@@ -477,7 +502,7 @@ const CalendarBase = ({
477
502
  locale,
478
503
  createCalendar,
479
504
  minValue: minDate,
480
- maxValue: maxDate
505
+ maxValue: getAdjustedMaxDate(maxDate)
481
506
  };
482
507
  const state = useCalendarState(_props);
483
508
  const { calendarProps, prevButtonProps, nextButtonProps, title } = useCalendar(_props, state);
@@ -531,7 +556,8 @@ const CalendarBase = ({
531
556
  classNameForDate,
532
557
  ariaLabelForDate,
533
558
  showWeekNumbers,
534
- weekNumberHeader
559
+ weekNumberHeader,
560
+ showOutsideMonth
535
561
  }
536
562
  )
537
563
  ]
@@ -553,6 +579,7 @@ const DatePicker = ({
553
579
  validationFeedback,
554
580
  showWeekNumbers,
555
581
  weekNumberHeader,
582
+ showOutsideMonth = false,
556
583
  disableModal = false,
557
584
  labelTooltip,
558
585
  navigationDescription,
@@ -579,7 +606,7 @@ const DatePicker = ({
579
606
  }),
580
607
  minValue: minDate,
581
608
  // this weird logic makes sure the entire day is included if no time is provided in maxDate
582
- maxValue: "hour" in (maxDate ?? {}) ? maxDate : maxDate !== void 0 ? lastMillisecondOfDay(maxDate) : void 0,
609
+ maxValue: getAdjustedMaxDate(maxDate),
583
610
  value: selectedDate,
584
611
  granularity,
585
612
  isDisabled: disabled || readOnly
@@ -623,7 +650,8 @@ const DatePicker = ({
623
650
  classNameForDate,
624
651
  ariaLabelForDate,
625
652
  showWeekNumbers,
626
- weekNumberHeader
653
+ weekNumberHeader,
654
+ showOutsideMonth
627
655
  };
628
656
  const isModal = typeof width !== "undefined" && width <= CALENDAR_MODAL_MAX_SCREEN_WIDTH && !disableModal;
629
657
  const popoverCalendar = /* @__PURE__ */ jsx(
@@ -1221,6 +1249,7 @@ export {
1221
1249
  convertValueToType,
1222
1250
  createCalendar,
1223
1251
  focusSegment,
1252
+ getAdjustedMaxDate,
1224
1253
  getWeekNumberForDate,
1225
1254
  handleOnChange,
1226
1255
  lastMillisecondOfDay,