@entur/datepicker 12.0.2-beta.0 → 12.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.
@@ -1,4 +1,4 @@
1
- import { ConditionalWrapper, mergeRefs, useWindowDimensions, useOnClickOutside, useOnEscape, useOnMount, warnAboutMissingStyles } from "@entur/utils";
1
+ import { ConditionalWrapper, mergeRefs, useWindowDimensions, useOnClickOutside, useOnEscape, useOnMount, getActiveElement, warnAboutMissingStyles } from "@entur/utils";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
3
  import React, { useRef, useEffect, useId, useState } from "react";
4
4
  import { useDateFieldState, useDatePickerState, useTimeFieldState } from "@react-stately/datepicker";
@@ -196,16 +196,6 @@ function getAdjustedMaxDate(maxDate) {
196
196
  if (maxDate !== void 0) return lastMillisecondOfDay(maxDate);
197
197
  return void 0;
198
198
  }
199
- function shouldUseAriaAlert(variant) {
200
- if (!variant) return false;
201
- if (variant === "negative" || variant === "error") {
202
- return "alert";
203
- }
204
- if (variant === "warning") {
205
- return "status";
206
- }
207
- return false;
208
- }
209
199
  const DateField = ({
210
200
  // normalize undefined to null so the field stays controlled and empty
211
201
  selectedDate = null,
@@ -233,6 +223,8 @@ const DateField = ({
233
223
  prepend,
234
224
  onValidate,
235
225
  dateFieldRef: ref,
226
+ ariaAlertOnFeedback,
227
+ feedbackProps,
236
228
  ...rest
237
229
  }) => {
238
230
  const { locale } = useLocale();
@@ -269,9 +261,8 @@ const DateField = ({
269
261
  BaseFormControl,
270
262
  {
271
263
  append,
272
- ariaAlertOnFeedback: shouldUseAriaAlert(
273
- variant ?? (state.isInvalid ? validationVariant : void 0)
274
- ),
264
+ ariaAlertOnFeedback,
265
+ feedbackProps,
275
266
  className: classNames("eds-datefield", className, {
276
267
  "eds-datefield--has-tooltip": labelTooltip !== void 0
277
268
  }),
@@ -949,6 +940,7 @@ const DatePicker = ({
949
940
  }
950
941
  );
951
942
  };
943
+ const error$1 = "error";
952
944
  const NativeDatePicker = React.forwardRef(
953
945
  ({
954
946
  className,
@@ -959,6 +951,8 @@ const NativeDatePicker = React.forwardRef(
959
951
  variant,
960
952
  disableLabelAnimation,
961
953
  prepend = /* @__PURE__ */ jsx(DateIcon, { inline: true }),
954
+ ariaAlertOnFeedback,
955
+ feedbackProps,
962
956
  ...rest
963
957
  }, ref) => {
964
958
  const nativedatepickerId = `eds-nativetimepicker${useId()}`;
@@ -973,6 +967,8 @@ const NativeDatePicker = React.forwardRef(
973
967
  variant,
974
968
  labelId: nativedatepickerId,
975
969
  disableLabelAnimation,
970
+ ariaAlertOnFeedback,
971
+ feedbackProps,
976
972
  isFilled: true,
977
973
  children: /* @__PURE__ */ jsx(
978
974
  NativeDatePickerBase,
@@ -1016,7 +1012,7 @@ const NativeDatePickerBase = React.forwardRef(({ onChange, variant, value, ...re
1016
1012
  "input",
1017
1013
  {
1018
1014
  ref,
1019
- "aria-invalid": currentVariant === "error",
1015
+ "aria-invalid": currentVariant === "negative" || currentVariant === error$1,
1020
1016
  type: "date",
1021
1017
  className: "eds-form-control eds-native-date-picker",
1022
1018
  onChange: handleChange,
@@ -1075,6 +1071,8 @@ const TimePicker = ({
1075
1071
  forcedTimeZone,
1076
1072
  append,
1077
1073
  prepend,
1074
+ ariaAlertOnFeedback,
1075
+ feedbackProps,
1078
1076
  ...rest
1079
1077
  }) => {
1080
1078
  let { locale } = useLocale();
@@ -1151,7 +1149,8 @@ const TimePicker = ({
1151
1149
  }
1152
1150
  )
1153
1151
  ] }),
1154
- ariaAlertOnFeedback: shouldUseAriaAlert(variant),
1152
+ ariaAlertOnFeedback,
1153
+ feedbackProps,
1155
1154
  "aria-describedby": timePickerId + "description",
1156
1155
  className: classNames("eds-timepicker", className, {
1157
1156
  "eds-timepicker--disabled": disabled,
@@ -1208,8 +1207,20 @@ const TimePicker = ({
1208
1207
  }
1209
1208
  ) });
1210
1209
  };
1210
+ const error = "error";
1211
1211
  const NativeTimePicker = React.forwardRef(
1212
- ({ className, style, onChange, label, feedback, variant, prepend, ...rest }, ref) => {
1212
+ ({
1213
+ className,
1214
+ style,
1215
+ onChange,
1216
+ label,
1217
+ feedback,
1218
+ variant,
1219
+ prepend,
1220
+ ariaAlertOnFeedback,
1221
+ feedbackProps,
1222
+ ...rest
1223
+ }, ref) => {
1213
1224
  const nativetimepickerId = `eds-native-timepicker${useId()}`;
1214
1225
  return /* @__PURE__ */ jsx(
1215
1226
  BaseFormControl,
@@ -1222,6 +1233,8 @@ const NativeTimePicker = React.forwardRef(
1222
1233
  variant,
1223
1234
  labelId: nativetimepickerId,
1224
1235
  disableLabelAnimation: true,
1236
+ ariaAlertOnFeedback,
1237
+ feedbackProps,
1225
1238
  children: /* @__PURE__ */ jsx(
1226
1239
  NativeTimePickerBase,
1227
1240
  {
@@ -1263,7 +1276,7 @@ const NativeTimePickerBase = React.forwardRef(({ onChange, value, ...rest }, ref
1263
1276
  "input",
1264
1277
  {
1265
1278
  ref,
1266
- "aria-invalid": currentVariant === "error",
1279
+ "aria-invalid": currentVariant === "negative" || currentVariant === error,
1267
1280
  type: "time",
1268
1281
  className: "eds-form-control",
1269
1282
  onChange: handleChange,
@@ -1290,6 +1303,8 @@ const SimpleTimePicker = ({
1290
1303
  showSeconds,
1291
1304
  style,
1292
1305
  variant,
1306
+ ariaAlertOnFeedback,
1307
+ feedbackProps,
1293
1308
  ...rest
1294
1309
  }) => {
1295
1310
  const [inputText, setInputText] = useState("");
@@ -1318,7 +1333,7 @@ const SimpleTimePicker = ({
1318
1333
  const updateInputWithSelectedTime = () => {
1319
1334
  const selectedTimeString = getStringFromTimeValue(selectedTime);
1320
1335
  setInputText(selectedTimeString);
1321
- const timeFieldIsFocused = document.activeElement === timeFieldRef?.current;
1336
+ const timeFieldIsFocused = timeFieldRef.current !== null && getActiveElement() === timeFieldRef.current;
1322
1337
  if (selectedTimeString === "" && !timeFieldIsFocused)
1323
1338
  addPlaceholderToInput();
1324
1339
  };
@@ -1426,6 +1441,8 @@ const SimpleTimePicker = ({
1426
1441
  disabled,
1427
1442
  disableLabelAnimation: true,
1428
1443
  feedback,
1444
+ ariaAlertOnFeedback,
1445
+ feedbackProps,
1429
1446
  label,
1430
1447
  labelProps,
1431
1448
  labelTooltip,
@@ -1480,7 +1497,6 @@ export {
1480
1497
  modulo,
1481
1498
  nativeDateToDateValue,
1482
1499
  nativeDateToTimeValue,
1483
- shouldUseAriaAlert,
1484
1500
  timeOrDateValueToNativeDate
1485
1501
  };
1486
1502
  //# sourceMappingURL=datepicker.mjs.map