@happeouikit/form-elements 2.3.1 → 2.3.6

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,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.3.6
4
+
5
+ - [Added] Added data-testids for datepicker components
6
+
7
+ ## 2.3.5
8
+
9
+ - [Added] Added the option to pass dayPickerProps
10
+
11
+ ## 2.3.4
12
+
13
+ - [Fixed] DatePicker. Added htmlFor to the label and input ID autogeneration. Accessibility issue.
14
+
3
15
  ## 2.3.1
4
16
 
5
17
  - [Fixed] remove role from span, keep role on input only
@@ -6,7 +6,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
6
6
 
7
7
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
8
 
9
- import React, { useState } from "react";
9
+ import React, { useState, useRef } from "react";
10
10
  import PropTypes from "prop-types";
11
11
  import styled, { css } from "styled-components";
12
12
  import DayPickerInput from "react-day-picker/DayPickerInput";
@@ -26,7 +26,7 @@ import Dropdown from "./Dropdown"; // CSS
26
26
 
27
27
  import "react-day-picker/lib/style.css";
28
28
  import messages from "./messages";
29
- import { useDevWarningOnce } from "./utils";
29
+ import { useDevWarningOnce, uuidv4 } from "./utils";
30
30
  import { jsx as _jsx } from "react/jsx-runtime";
31
31
  import { jsxs as _jsxs } from "react/jsx-runtime";
32
32
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -68,7 +68,16 @@ var DatePicker = function DatePicker(_ref) {
68
68
  disabledDays = _ref.disabledDays,
69
69
  value = _ref.value,
70
70
  pickerRef = _ref.pickerRef,
71
- props = _objectWithoutProperties(_ref, ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef"]);
71
+ _ref$inputProps = _ref.inputProps,
72
+ inputProps = _ref$inputProps === void 0 ? {} : _ref$inputProps,
73
+ _ref$dayPickerProps = _ref.dayPickerProps,
74
+ dayPickerProps = _ref$dayPickerProps === void 0 ? {} : _ref$dayPickerProps,
75
+ props = _objectWithoutProperties(_ref, ["label", "locale", "width", "date", "type", "fromMonth", "disabledDays", "value", "pickerRef", "inputProps", "dayPickerProps"]);
76
+
77
+ // Stores the ID of the input field. If "id" isn't provided, it will be generated
78
+ // to improve accessibility by linking label to the input field.
79
+ var _useRef = useRef(inputProps.id || uuidv4()),
80
+ datePickerId = _useRef.current;
72
81
 
73
82
  var _useState = useState(fromMonth),
74
83
  _useState2 = _slicedToArray(_useState, 2),
@@ -90,11 +99,14 @@ var DatePicker = function DatePicker(_ref) {
90
99
  return /*#__PURE__*/_jsxs(Wrapper, {
91
100
  width: width,
92
101
  hasRange: isRangeMode,
93
- children: [label && /*#__PURE__*/_jsx("div", {
102
+ children: [label && /*#__PURE__*/_jsx("label", {
103
+ htmlFor: datePickerId,
104
+ "aria-label": label,
94
105
  style: {
95
106
  margin: "4px 0"
96
107
  },
97
108
  children: /*#__PURE__*/_jsx(BodyUI, {
109
+ as: "span",
98
110
  color: gray01,
99
111
  children: label
100
112
  })
@@ -104,7 +116,7 @@ var DatePicker = function DatePicker(_ref) {
104
116
  formatDate: formatDate,
105
117
  parseDate: parseDate,
106
118
  placeholder: formatValue(new Date(), locale),
107
- dayPickerProps: {
119
+ dayPickerProps: _objectSpread({
108
120
  locale: locale,
109
121
  localeUtils: MomentLocaleUtils,
110
122
  className: "Range",
@@ -125,15 +137,18 @@ var DatePicker = function DatePicker(_ref) {
125
137
  }),
126
138
  showOutsideDays: true,
127
139
  month: month
128
- },
129
- ref: pickerRef
140
+ }, dayPickerProps),
141
+ ref: pickerRef,
142
+ inputProps: _objectSpread({
143
+ id: datePickerId
144
+ }, inputProps)
130
145
  }, props), date[type])]
131
146
  });
132
147
  };
133
148
 
134
149
  DatePicker.defaultProps = {
135
150
  type: "to",
136
- fromMonth: new Date(),
151
+ fromMonth: new Date() || "",
137
152
  date: {
138
153
  from: "",
139
154
  to: ""
@@ -146,7 +161,7 @@ DatePicker.defaultProps = {
146
161
  disabledDays: []
147
162
  };
148
163
  DatePicker.propTypes = {
149
- fromMonth: PropTypes.instanceOf(Date),
164
+ fromMonth: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string]),
150
165
  label: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
151
166
  locale: PropTypes.string,
152
167
  width: PropTypes.string,
@@ -203,7 +218,8 @@ var CustomNavbar = function CustomNavbar(_ref3) {
203
218
  },
204
219
  "aria-label": intl.formatMessage(messages.pickerPrevMonth),
205
220
  "data-tip": true,
206
- "data-for": "datepicker-prev-month"
221
+ "data-for": "datepicker-prev-month",
222
+ "data-testid": "datepicker-select-prev-month"
207
223
  }), /*#__PURE__*/_jsx(ButtonSecondary, {
208
224
  onClick: function onClick() {
209
225
  return setShowYearMonthPicker(true);
@@ -211,6 +227,7 @@ var CustomNavbar = function CustomNavbar(_ref3) {
211
227
  "aria-label": intl.formatMessage(messages.pickerSelectYear),
212
228
  "data-tip": true,
213
229
  "data-for": "datepicker-select-year",
230
+ "data-testid": "datepicker-select-year",
214
231
  text: moment(month).format("MMMM YYYY")
215
232
  }), /*#__PURE__*/_jsx(IconButton, {
216
233
  icon: IconChevronRight,
@@ -220,7 +237,8 @@ var CustomNavbar = function CustomNavbar(_ref3) {
220
237
  },
221
238
  "aria-label": intl.formatMessage(messages.pickerNextMonth),
222
239
  "data-tip": true,
223
- "data-for": "datepicker-next-month"
240
+ "data-for": "datepicker-next-month",
241
+ "data-testid": "datepicker-select-next-month"
224
242
  }), /*#__PURE__*/_jsx(Tooltip, {
225
243
  id: "datepicker-prev-month",
226
244
  content: intl.formatMessage(messages.pickerPrevMonth)
@@ -300,6 +318,7 @@ var MonthPicker = function MonthPicker(_ref4) {
300
318
 
301
319
  return /*#__PURE__*/_jsxs(YearMonthSelectContainer, {
302
320
  children: [/*#__PURE__*/_jsx(YearSelectContainer, {
321
+ "data-testid": "yearmonth-dropdown-select",
303
322
  children: /*#__PURE__*/_jsx(Dropdown, {
304
323
  "aria-label": intl.formatMessage(messages.selectYearDropdown),
305
324
  options: getYears(),
@@ -319,6 +338,7 @@ var MonthPicker = function MonthPicker(_ref4) {
319
338
  return /*#__PURE__*/_jsx("li", {
320
339
  value: i,
321
340
  children: /*#__PURE__*/_jsx(MonthSelectButton2, {
341
+ "data-testid": "select-month-".concat(month),
322
342
  "data-for": "datepicker-select-month-button",
323
343
  $isActive: i === selectedMonth,
324
344
  onClick: function onClick() {
@@ -340,7 +360,8 @@ var MonthPicker = function MonthPicker(_ref4) {
340
360
  });
341
361
  },
342
362
  "data-tip": true,
343
- "data-for": "datepicker-year-month-done"
363
+ "data-for": "datepicker-year-month-done",
364
+ "data-testid": "datepicker-year-month-done"
344
365
  }), /*#__PURE__*/_jsx(Tooltip, {
345
366
  id: "datepicker-year-month-done",
346
367
  content: intl.formatMessage(messages.closeYearMonthPicker)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happeouikit/form-elements",
3
- "version": "2.3.1",
3
+ "version": "2.3.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.js",