@instructure/ui-date-input 8.56.3 → 8.56.5-pr-snapshot-1728655013879
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 +20 -0
- package/es/DateInput/__new-tests__/DateInput.test.js +22 -0
- package/es/DateInput/index.js +5 -3
- package/lib/DateInput/__new-tests__/DateInput.test.js +30 -8
- package/lib/DateInput/index.js +33 -35
- package/lib/DateInput/props.js +8 -9
- package/package.json +18 -18
- package/src/DateInput/__new-tests__/DateInput.test.tsx +26 -0
- package/src/DateInput/index.tsx +5 -5
- package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [8.56.5-pr-snapshot-1728655013879](https://github.com/instructure/instructure-ui/compare/v8.56.4...v8.56.5-pr-snapshot-1728655013879) (2024-10-11)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-date-input
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [8.56.4](https://github.com/instructure/instructure-ui/compare/v8.56.3...v8.56.4) (2024-10-02)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **ui-calendar,ui-date-input:** fix locale and timezone for simple api ([94209df](https://github.com/instructure/instructure-ui/commit/94209dfdfaeca8c8ae452771c4bf2688e6345272))
|
|
20
|
+
* **ui-date-input:** fix date format and validation when locale isn't us english ([67e6d1f](https://github.com/instructure/instructure-ui/commit/67e6d1fb4aedda60ab430b69e14a0c93ac57f2bc))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## [8.56.3](https://github.com/instructure/instructure-ui/compare/v8.56.2...v8.56.3) (2024-09-18)
|
|
7
27
|
|
|
8
28
|
**Note:** Version bump only for package @instructure/ui-date-input
|
|
@@ -588,5 +588,27 @@ describe('<DateInput />', () => {
|
|
|
588
588
|
expect(calendarDays).toHaveLength(42);
|
|
589
589
|
});
|
|
590
590
|
});
|
|
591
|
+
it('should change weekdays according to locale', async () => {
|
|
592
|
+
const onChange = jest.fn();
|
|
593
|
+
render( /*#__PURE__*/React.createElement(DateInput, {
|
|
594
|
+
renderLabel: "Choose date",
|
|
595
|
+
assistiveText: "Type a date or use arrow keys to navigate date picker.",
|
|
596
|
+
width: "20rem",
|
|
597
|
+
isInline: true,
|
|
598
|
+
value: '2023-11-23',
|
|
599
|
+
onChange: onChange,
|
|
600
|
+
currentDate: "2023-12-23",
|
|
601
|
+
disabledDates: ['2023-12-22', '2023-12-12', '2023-12-11'],
|
|
602
|
+
disabledDateErrorMessage: "disabled date",
|
|
603
|
+
invalidDateErrorMessage: "invalid date",
|
|
604
|
+
locale: "fr"
|
|
605
|
+
}));
|
|
606
|
+
const dateInput = screen.getByLabelText('Choose date');
|
|
607
|
+
fireEvent.click(dateInput);
|
|
608
|
+
const frenchMonday = screen.getByText('lu');
|
|
609
|
+
await waitFor(() => {
|
|
610
|
+
expect(typeof frenchMonday).toBe('object');
|
|
611
|
+
});
|
|
612
|
+
});
|
|
591
613
|
});
|
|
592
614
|
});
|
package/es/DateInput/index.js
CHANGED
|
@@ -153,7 +153,7 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _dec
|
|
|
153
153
|
} else {
|
|
154
154
|
// @ts-expect-error TODO
|
|
155
155
|
onChange(event, {
|
|
156
|
-
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('
|
|
156
|
+
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('LL')
|
|
157
157
|
});
|
|
158
158
|
this.setState({
|
|
159
159
|
messages: []
|
|
@@ -166,7 +166,7 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _dec
|
|
|
166
166
|
} else {
|
|
167
167
|
// @ts-expect-error TODO
|
|
168
168
|
onChange(event, {
|
|
169
|
-
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('
|
|
169
|
+
value: DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('LL')
|
|
170
170
|
});
|
|
171
171
|
this.setState({
|
|
172
172
|
messages: []
|
|
@@ -261,6 +261,8 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _dec
|
|
|
261
261
|
currentDate = _this$props11.currentDate;
|
|
262
262
|
const isValidDate = value ? DateTime.parse(value, this.locale(), this.timezone()).isValid() : false;
|
|
263
263
|
const noChildrenProps = this.props.children ? {} : {
|
|
264
|
+
timezone: this.timezone(),
|
|
265
|
+
locale: this.locale(),
|
|
264
266
|
disabledDates,
|
|
265
267
|
currentDate,
|
|
266
268
|
selectedDate: isValidDate ? value : void 0,
|
|
@@ -268,7 +270,7 @@ let DateInput = (_dec = withStyle(generateStyle, null), _dec2 = testable(), _dec
|
|
|
268
270
|
onDateSelected: (dateString, momentDate, e) => {
|
|
269
271
|
// @ts-expect-error TODO
|
|
270
272
|
onChange === null || onChange === void 0 ? void 0 : onChange(e, {
|
|
271
|
-
value:
|
|
273
|
+
value: momentDate.format('LL')
|
|
272
274
|
});
|
|
273
275
|
this.handleHideCalendar(e, dateString);
|
|
274
276
|
}
|
|
@@ -6,8 +6,8 @@ var _react2 = require("@testing-library/react");
|
|
|
6
6
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
7
|
require("@testing-library/jest-dom");
|
|
8
8
|
var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
|
|
9
|
-
var
|
|
10
|
-
var
|
|
9
|
+
var _uiAxeCheck = require("@instructure/ui-axe-check");
|
|
10
|
+
var _uiCalendar = require("@instructure/ui-calendar");
|
|
11
11
|
var _DateInput = _interopRequireDefault(require("../__examples__/DateInput.examples"));
|
|
12
12
|
var _index = require("../index");
|
|
13
13
|
var _Calendar$Day, _button, _button2, _Calendar$Day2, _Calendar$Day3;
|
|
@@ -37,11 +37,11 @@ var _Calendar$Day, _button, _button2, _Calendar$Day2, _Calendar$Day3;
|
|
|
37
37
|
// eslint-disable-next-line no-restricted-imports
|
|
38
38
|
describe('<DateInput />', () => {
|
|
39
39
|
const weekdayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
40
|
-
const generateDays = (count =
|
|
40
|
+
const generateDays = (count = _uiCalendar.Calendar.DAY_COUNT) => {
|
|
41
41
|
const days = [];
|
|
42
42
|
const date = new Date('2019-07-28');
|
|
43
43
|
while (days.length < count) {
|
|
44
|
-
days.push( /*#__PURE__*/_react.default.createElement(
|
|
44
|
+
days.push( /*#__PURE__*/_react.default.createElement(_uiCalendar.Calendar.Day, {
|
|
45
45
|
key: date.toISOString(),
|
|
46
46
|
date: date.toISOString(),
|
|
47
47
|
label: date.toISOString()
|
|
@@ -429,7 +429,7 @@ describe('<DateInput />', () => {
|
|
|
429
429
|
const onRequestHideCalendar = jest.fn();
|
|
430
430
|
const onRequestValidateDate = jest.fn();
|
|
431
431
|
const days = generateDays();
|
|
432
|
-
days[4] = _Calendar$Day || (_Calendar$Day = /*#__PURE__*/_react.default.createElement(
|
|
432
|
+
days[4] = _Calendar$Day || (_Calendar$Day = /*#__PURE__*/_react.default.createElement(_uiCalendar.Calendar.Day, {
|
|
433
433
|
key: "4",
|
|
434
434
|
label: "4",
|
|
435
435
|
date: "2019-09-28",
|
|
@@ -502,7 +502,7 @@ describe('<DateInput />', () => {
|
|
|
502
502
|
});
|
|
503
503
|
it('should render days with the correct role', async () => {
|
|
504
504
|
const days = generateDays();
|
|
505
|
-
days[5] = _Calendar$Day2 || (_Calendar$Day2 = /*#__PURE__*/_react.default.createElement(
|
|
505
|
+
days[5] = _Calendar$Day2 || (_Calendar$Day2 = /*#__PURE__*/_react.default.createElement(_uiCalendar.Calendar.Day, {
|
|
506
506
|
key: "5",
|
|
507
507
|
label: "5",
|
|
508
508
|
date: "2019-09-28",
|
|
@@ -526,7 +526,7 @@ describe('<DateInput />', () => {
|
|
|
526
526
|
});
|
|
527
527
|
it('should assign aria-selected to the selected date and link it to the input', async () => {
|
|
528
528
|
const days = generateDays();
|
|
529
|
-
days[7] = _Calendar$Day3 || (_Calendar$Day3 = /*#__PURE__*/_react.default.createElement(
|
|
529
|
+
days[7] = _Calendar$Day3 || (_Calendar$Day3 = /*#__PURE__*/_react.default.createElement(_uiCalendar.Calendar.Day, {
|
|
530
530
|
key: "7",
|
|
531
531
|
label: "7",
|
|
532
532
|
date: "2019-09-28",
|
|
@@ -560,7 +560,7 @@ describe('<DateInput />', () => {
|
|
|
560
560
|
}) => {
|
|
561
561
|
const _render7 = (0, _react2.render)(content),
|
|
562
562
|
container = _render7.container;
|
|
563
|
-
const axeCheck = await (0,
|
|
563
|
+
const axeCheck = await (0, _uiAxeCheck.runAxeCheck)(container);
|
|
564
564
|
expect(axeCheck).toBe(true);
|
|
565
565
|
});
|
|
566
566
|
});
|
|
@@ -590,5 +590,27 @@ describe('<DateInput />', () => {
|
|
|
590
590
|
expect(calendarDays).toHaveLength(42);
|
|
591
591
|
});
|
|
592
592
|
});
|
|
593
|
+
it('should change weekdays according to locale', async () => {
|
|
594
|
+
const onChange = jest.fn();
|
|
595
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.DateInput, {
|
|
596
|
+
renderLabel: "Choose date",
|
|
597
|
+
assistiveText: "Type a date or use arrow keys to navigate date picker.",
|
|
598
|
+
width: "20rem",
|
|
599
|
+
isInline: true,
|
|
600
|
+
value: '2023-11-23',
|
|
601
|
+
onChange: onChange,
|
|
602
|
+
currentDate: "2023-12-23",
|
|
603
|
+
disabledDates: ['2023-12-22', '2023-12-12', '2023-12-11'],
|
|
604
|
+
disabledDateErrorMessage: "disabled date",
|
|
605
|
+
invalidDateErrorMessage: "invalid date",
|
|
606
|
+
locale: "fr"
|
|
607
|
+
}));
|
|
608
|
+
const dateInput = _react2.screen.getByLabelText('Choose date');
|
|
609
|
+
_react2.fireEvent.click(dateInput);
|
|
610
|
+
const frenchMonday = _react2.screen.getByText('lu');
|
|
611
|
+
await (0, _react2.waitFor)(() => {
|
|
612
|
+
expect(typeof frenchMonday).toBe('object');
|
|
613
|
+
});
|
|
614
|
+
});
|
|
593
615
|
});
|
|
594
616
|
});
|
package/lib/DateInput/index.js
CHANGED
|
@@ -8,19 +8,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.default = exports.DateInput = void 0;
|
|
9
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
21
|
-
var _testable = require("@instructure/ui-testable/lib/testable.js");
|
|
22
|
-
var _DateTime = require("@instructure/ui-i18n/lib/DateTime.js");
|
|
23
|
-
var _Locale = require("@instructure/ui-i18n/lib/Locale.js");
|
|
11
|
+
var _uiCalendar = require("@instructure/ui-calendar");
|
|
12
|
+
var _uiIcons = require("@instructure/ui-icons");
|
|
13
|
+
var _uiPopover = require("@instructure/ui-popover");
|
|
14
|
+
var _uiSelectable = require("@instructure/ui-selectable");
|
|
15
|
+
var _uiTextInput = require("@instructure/ui-text-input");
|
|
16
|
+
var _uiUtils = require("@instructure/ui-utils");
|
|
17
|
+
var _uiReactUtils = require("@instructure/ui-react-utils");
|
|
18
|
+
var _uiTestable = require("@instructure/ui-testable");
|
|
19
|
+
var _uiI18n = require("@instructure/ui-i18n");
|
|
24
20
|
var _emotion = require("@instructure/emotion");
|
|
25
21
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
26
22
|
var _props2 = require("./props");
|
|
@@ -58,7 +54,7 @@ category: components
|
|
|
58
54
|
The `DateInput` component provides a visual interface for inputting date data.
|
|
59
55
|
See <https://instructure.design/#DateInput/>
|
|
60
56
|
**/
|
|
61
|
-
let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec2 = (0,
|
|
57
|
+
let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.default, null), _dec2 = (0, _uiTestable.testable)(), _dec(_class = _dec2(_class = (_class2 = class DateInput extends _react.Component {
|
|
62
58
|
constructor(...args) {
|
|
63
59
|
super(...args);
|
|
64
60
|
this.state = {
|
|
@@ -109,7 +105,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
109
105
|
const messages = [];
|
|
110
106
|
// check if date is enabled
|
|
111
107
|
const disabledDates = this.props.disabledDates;
|
|
112
|
-
if (typeof disabledDates === 'function' && disabledDates(date) || Array.isArray(disabledDates) && disabledDates.find(dateString =>
|
|
108
|
+
if (typeof disabledDates === 'function' && disabledDates(date) || Array.isArray(disabledDates) && disabledDates.find(dateString => _uiI18n.DateTime.parse(dateString, this.locale(), this.timezone()).isSame(_uiI18n.DateTime.parse(date, this.locale(), this.timezone()), 'day'))) {
|
|
113
109
|
messages.push(typeof disabledDateErrorMessage === 'function' ? disabledDateErrorMessage(date) : {
|
|
114
110
|
type: 'error',
|
|
115
111
|
text: disabledDateErrorMessage
|
|
@@ -117,7 +113,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
117
113
|
}
|
|
118
114
|
|
|
119
115
|
// check if date is valid
|
|
120
|
-
if (!
|
|
116
|
+
if (!_uiI18n.DateTime.parse(date, this.locale(), this.timezone(), [_uiI18n.DateTime.momentISOFormat, 'llll', 'LLLL', 'lll', 'LLL', 'll', 'LL', 'l', 'L'], true).isValid()) {
|
|
121
117
|
messages.push(typeof invalidDateErrorMessage === 'function' ? invalidDateErrorMessage(date) : {
|
|
122
118
|
type: 'error',
|
|
123
119
|
text: invalidDateErrorMessage
|
|
@@ -157,14 +153,14 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
157
153
|
onChange = _this$props7.onChange,
|
|
158
154
|
value = _this$props7.value,
|
|
159
155
|
currentDate = _this$props7.currentDate;
|
|
160
|
-
const isValueValid = value &&
|
|
156
|
+
const isValueValid = value && _uiI18n.DateTime.parse(value, this.locale(), this.timezone()).isValid();
|
|
161
157
|
if (direction === -1) {
|
|
162
158
|
if (onRequestSelectPrevDay) {
|
|
163
159
|
onRequestSelectPrevDay === null || onRequestSelectPrevDay === void 0 ? void 0 : onRequestSelectPrevDay(event);
|
|
164
160
|
} else {
|
|
165
161
|
// @ts-expect-error TODO
|
|
166
162
|
onChange(event, {
|
|
167
|
-
value:
|
|
163
|
+
value: _uiI18n.DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).subtract(1, 'day').format('LL')
|
|
168
164
|
});
|
|
169
165
|
this.setState({
|
|
170
166
|
messages: []
|
|
@@ -177,7 +173,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
177
173
|
} else {
|
|
178
174
|
// @ts-expect-error TODO
|
|
179
175
|
onChange(event, {
|
|
180
|
-
value:
|
|
176
|
+
value: _uiI18n.DateTime.parse(isValueValid ? value : currentDate, this.locale(), this.timezone()).add(1, 'day').format('LL')
|
|
181
177
|
});
|
|
182
178
|
this.setState({
|
|
183
179
|
messages: []
|
|
@@ -193,7 +189,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
193
189
|
} else if (this.context && this.context.locale) {
|
|
194
190
|
return this.context.locale;
|
|
195
191
|
}
|
|
196
|
-
return
|
|
192
|
+
return _uiI18n.Locale.browserLocale();
|
|
197
193
|
}
|
|
198
194
|
timezone() {
|
|
199
195
|
if (this.props.timezone) {
|
|
@@ -201,7 +197,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
201
197
|
} else if (this.context && this.context.timezone) {
|
|
202
198
|
return this.context.timezone;
|
|
203
199
|
}
|
|
204
|
-
return
|
|
200
|
+
return _uiI18n.DateTime.browserTimeZone();
|
|
205
201
|
}
|
|
206
202
|
componentDidMount() {
|
|
207
203
|
var _this$props$makeStyle, _this$props8;
|
|
@@ -224,7 +220,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
224
220
|
return selectedDateId;
|
|
225
221
|
}
|
|
226
222
|
get interaction() {
|
|
227
|
-
return (0,
|
|
223
|
+
return (0, _uiReactUtils.getInteraction)({
|
|
228
224
|
props: this.props
|
|
229
225
|
});
|
|
230
226
|
}
|
|
@@ -233,7 +229,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
233
229
|
renderPrevMonthButton = _this$props10.renderPrevMonthButton,
|
|
234
230
|
renderNextMonthButton = _this$props10.renderNextMonthButton;
|
|
235
231
|
const button = type === 'prev' ? renderPrevMonthButton : renderNextMonthButton;
|
|
236
|
-
return button && (0,
|
|
232
|
+
return button && (0, _uiReactUtils.safeCloneElement)((0, _uiReactUtils.callRenderProp)(button), {
|
|
237
233
|
tabIndex: -1
|
|
238
234
|
});
|
|
239
235
|
}
|
|
@@ -254,7 +250,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
254
250
|
onClick: optionProps.onClick,
|
|
255
251
|
role: 'presentation'
|
|
256
252
|
} : optionProps;
|
|
257
|
-
return (0,
|
|
253
|
+
return (0, _uiReactUtils.safeCloneElement)(day, propsAdded);
|
|
258
254
|
});
|
|
259
255
|
}
|
|
260
256
|
renderCalendar({
|
|
@@ -270,8 +266,10 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
270
266
|
onChange = _this$props11.onChange,
|
|
271
267
|
disabledDates = _this$props11.disabledDates,
|
|
272
268
|
currentDate = _this$props11.currentDate;
|
|
273
|
-
const isValidDate = value ?
|
|
269
|
+
const isValidDate = value ? _uiI18n.DateTime.parse(value, this.locale(), this.timezone()).isValid() : false;
|
|
274
270
|
const noChildrenProps = this.props.children ? {} : {
|
|
271
|
+
timezone: this.timezone(),
|
|
272
|
+
locale: this.locale(),
|
|
275
273
|
disabledDates,
|
|
276
274
|
currentDate,
|
|
277
275
|
selectedDate: isValidDate ? value : void 0,
|
|
@@ -279,12 +277,12 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
279
277
|
onDateSelected: (dateString, momentDate, e) => {
|
|
280
278
|
// @ts-expect-error TODO
|
|
281
279
|
onChange === null || onChange === void 0 ? void 0 : onChange(e, {
|
|
282
|
-
value:
|
|
280
|
+
value: momentDate.format('LL')
|
|
283
281
|
});
|
|
284
282
|
this.handleHideCalendar(e, dateString);
|
|
285
283
|
}
|
|
286
284
|
};
|
|
287
|
-
return (0, _emotion.jsx)(
|
|
285
|
+
return (0, _emotion.jsx)(_uiCalendar.Calendar, Object.assign({}, getListProps({
|
|
288
286
|
onRequestRenderNextMonth,
|
|
289
287
|
onRequestRenderPrevMonth,
|
|
290
288
|
renderNavigationLabel,
|
|
@@ -320,8 +318,8 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
320
318
|
ref = _getTriggerProps.ref,
|
|
321
319
|
triggerProps = (0, _objectWithoutProperties2.default)(_getTriggerProps, _excluded2);
|
|
322
320
|
const messages = this.props.messages || this.state.messages;
|
|
323
|
-
return (0, _emotion.jsx)(
|
|
324
|
-
renderLabel: (0,
|
|
321
|
+
return (0, _emotion.jsx)(_uiTextInput.TextInput, Object.assign({}, triggerProps, (0, _uiReactUtils.passthroughProps)(rest), getInputProps({
|
|
322
|
+
renderLabel: (0, _uiReactUtils.callRenderProp)(renderLabel),
|
|
325
323
|
value,
|
|
326
324
|
placeholder,
|
|
327
325
|
size,
|
|
@@ -329,12 +327,12 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
329
327
|
width,
|
|
330
328
|
messages,
|
|
331
329
|
onChange: this.handleInputChange,
|
|
332
|
-
onBlur: (0,
|
|
333
|
-
inputRef: (0,
|
|
330
|
+
onBlur: (0, _uiUtils.createChainedFunction)(onBlur, this.handleHideCalendar),
|
|
331
|
+
inputRef: (0, _uiUtils.createChainedFunction)(ref, this.handleInputRef),
|
|
334
332
|
interaction,
|
|
335
333
|
isRequired,
|
|
336
334
|
display: isInline ? 'inline-block' : 'block',
|
|
337
|
-
renderAfterInput: _IconCalendarMonthLin || (_IconCalendarMonthLin = (0, _emotion.jsx)(
|
|
335
|
+
renderAfterInput: _IconCalendarMonthLin || (_IconCalendarMonthLin = (0, _emotion.jsx)(_uiIcons.IconCalendarMonthLine, {
|
|
338
336
|
inline: false
|
|
339
337
|
}))
|
|
340
338
|
}), {
|
|
@@ -356,7 +354,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
356
354
|
assistiveText = _this$props13.assistiveText,
|
|
357
355
|
styles = _this$props13.styles;
|
|
358
356
|
const isShowingCalendar = this.shouldShowCalendar();
|
|
359
|
-
return (0, _emotion.jsx)(
|
|
357
|
+
return (0, _emotion.jsx)(_uiSelectable.Selectable, {
|
|
360
358
|
isShowingOptions: isShowingCalendar,
|
|
361
359
|
onRequestShowOptions: this.handleShowCalendar,
|
|
362
360
|
onRequestHideOptions: this.handleHideCalendar,
|
|
@@ -380,7 +378,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
380
378
|
getTriggerProps
|
|
381
379
|
}), (0, _emotion.jsx)("span", Object.assign({}, getDescriptionProps(), {
|
|
382
380
|
css: styles === null || styles === void 0 ? void 0 : styles.assistiveText
|
|
383
|
-
}), assistiveText), (0, _emotion.jsx)(
|
|
381
|
+
}), assistiveText), (0, _emotion.jsx)(_uiPopover.Popover, {
|
|
384
382
|
placement: placement,
|
|
385
383
|
isShowingContent: isShowingCalendar,
|
|
386
384
|
positionTarget: this._input,
|
|
@@ -391,7 +389,7 @@ let DateInput = exports.DateInput = (_dec = (0, _emotion.withStyle)(_styles.defa
|
|
|
391
389
|
getOptionProps
|
|
392
390
|
}))));
|
|
393
391
|
}
|
|
394
|
-
}, _class2.displayName = "DateInput", _class2.componentId = 'DateInput', _class2.Day =
|
|
392
|
+
}, _class2.displayName = "DateInput", _class2.componentId = 'DateInput', _class2.Day = _uiCalendar.Calendar.Day, _class2.propTypes = _props2.propTypes, _class2.allowedProps = _props2.allowedProps, _class2.defaultProps = {
|
|
395
393
|
value: '',
|
|
396
394
|
size: 'medium',
|
|
397
395
|
onBlur: () => {},
|
package/lib/DateInput/props.js
CHANGED
|
@@ -6,11 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.propTypes = exports.allowedProps = void 0;
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var _Calendar = require("@instructure/ui-calendar/lib/Calendar");
|
|
9
|
+
var _uiPropTypes = require("@instructure/ui-prop-types");
|
|
10
|
+
var _uiFormField = require("@instructure/ui-form-field");
|
|
11
|
+
var _uiPosition = require("@instructure/ui-position");
|
|
12
|
+
var _uiCalendar = require("@instructure/ui-calendar");
|
|
14
13
|
/*
|
|
15
14
|
* The MIT License (MIT)
|
|
16
15
|
*
|
|
@@ -37,7 +36,7 @@ var _Calendar = require("@instructure/ui-calendar/lib/Calendar");
|
|
|
37
36
|
|
|
38
37
|
const propTypes = exports.propTypes = {
|
|
39
38
|
renderLabel: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.func]).isRequired,
|
|
40
|
-
value: (0,
|
|
39
|
+
value: (0, _uiPropTypes.controllable)(_propTypes.default.string),
|
|
41
40
|
size: _propTypes.default.oneOf(['small', 'medium', 'large']),
|
|
42
41
|
placeholder: _propTypes.default.string,
|
|
43
42
|
onChange: _propTypes.default.func,
|
|
@@ -50,8 +49,8 @@ const propTypes = exports.propTypes = {
|
|
|
50
49
|
width: _propTypes.default.string,
|
|
51
50
|
display: _propTypes.default.oneOf(['inline-block', 'block']),
|
|
52
51
|
inputRef: _propTypes.default.func,
|
|
53
|
-
messages: _propTypes.default.arrayOf(
|
|
54
|
-
placement:
|
|
52
|
+
messages: _propTypes.default.arrayOf(_uiFormField.FormPropTypes.message),
|
|
53
|
+
placement: _uiPosition.PositionPropTypes.placement,
|
|
55
54
|
isShowingCalendar: _propTypes.default.bool,
|
|
56
55
|
onRequestValidateDate: _propTypes.default.func,
|
|
57
56
|
onRequestShowCalendar: _propTypes.default.func,
|
|
@@ -64,7 +63,7 @@ const propTypes = exports.propTypes = {
|
|
|
64
63
|
renderWeekdayLabels: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node])),
|
|
65
64
|
renderNextMonthButton: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
|
|
66
65
|
renderPrevMonthButton: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]),
|
|
67
|
-
children:
|
|
66
|
+
children: _uiPropTypes.Children.oneOf([_uiCalendar.Calendar.Day]),
|
|
68
67
|
disabledDates: _propTypes.default.oneOfType([_propTypes.default.array, _propTypes.default.func]),
|
|
69
68
|
currentDate: _propTypes.default.string,
|
|
70
69
|
disabledDateErrorMessage: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-date-input",
|
|
3
|
-
"version": "8.56.
|
|
3
|
+
"version": "8.56.5-pr-snapshot-1728655013879",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,29 +23,29 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-axe-check": "8.56.
|
|
27
|
-
"@instructure/ui-babel-preset": "8.56.
|
|
28
|
-
"@instructure/ui-scripts": "8.56.
|
|
29
|
-
"@instructure/ui-test-utils": "8.56.
|
|
26
|
+
"@instructure/ui-axe-check": "8.56.5-pr-snapshot-1728655013879",
|
|
27
|
+
"@instructure/ui-babel-preset": "8.56.5-pr-snapshot-1728655013879",
|
|
28
|
+
"@instructure/ui-scripts": "8.56.5-pr-snapshot-1728655013879",
|
|
29
|
+
"@instructure/ui-test-utils": "8.56.5-pr-snapshot-1728655013879",
|
|
30
30
|
"@testing-library/jest-dom": "^6.1.4",
|
|
31
31
|
"@testing-library/react": "^14.1.2",
|
|
32
32
|
"@testing-library/user-event": "^14.5.1"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/runtime": "^7.23.2",
|
|
36
|
-
"@instructure/emotion": "8.56.
|
|
37
|
-
"@instructure/ui-calendar": "8.56.
|
|
38
|
-
"@instructure/ui-form-field": "8.56.
|
|
39
|
-
"@instructure/ui-i18n": "8.56.
|
|
40
|
-
"@instructure/ui-icons": "8.56.
|
|
41
|
-
"@instructure/ui-popover": "8.56.
|
|
42
|
-
"@instructure/ui-position": "8.56.
|
|
43
|
-
"@instructure/ui-prop-types": "8.56.
|
|
44
|
-
"@instructure/ui-react-utils": "8.56.
|
|
45
|
-
"@instructure/ui-selectable": "8.56.
|
|
46
|
-
"@instructure/ui-testable": "8.56.
|
|
47
|
-
"@instructure/ui-text-input": "8.56.
|
|
48
|
-
"@instructure/ui-utils": "8.56.
|
|
36
|
+
"@instructure/emotion": "8.56.5-pr-snapshot-1728655013879",
|
|
37
|
+
"@instructure/ui-calendar": "8.56.5-pr-snapshot-1728655013879",
|
|
38
|
+
"@instructure/ui-form-field": "8.56.5-pr-snapshot-1728655013879",
|
|
39
|
+
"@instructure/ui-i18n": "8.56.5-pr-snapshot-1728655013879",
|
|
40
|
+
"@instructure/ui-icons": "8.56.5-pr-snapshot-1728655013879",
|
|
41
|
+
"@instructure/ui-popover": "8.56.5-pr-snapshot-1728655013879",
|
|
42
|
+
"@instructure/ui-position": "8.56.5-pr-snapshot-1728655013879",
|
|
43
|
+
"@instructure/ui-prop-types": "8.56.5-pr-snapshot-1728655013879",
|
|
44
|
+
"@instructure/ui-react-utils": "8.56.5-pr-snapshot-1728655013879",
|
|
45
|
+
"@instructure/ui-selectable": "8.56.5-pr-snapshot-1728655013879",
|
|
46
|
+
"@instructure/ui-testable": "8.56.5-pr-snapshot-1728655013879",
|
|
47
|
+
"@instructure/ui-text-input": "8.56.5-pr-snapshot-1728655013879",
|
|
48
|
+
"@instructure/ui-utils": "8.56.5-pr-snapshot-1728655013879",
|
|
49
49
|
"prop-types": "^15.8.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
@@ -842,5 +842,31 @@ describe('<DateInput />', () => {
|
|
|
842
842
|
expect(calendarDays).toHaveLength(42)
|
|
843
843
|
})
|
|
844
844
|
})
|
|
845
|
+
it('should change weekdays according to locale', async () => {
|
|
846
|
+
const onChange = jest.fn()
|
|
847
|
+
render(
|
|
848
|
+
<DateInput
|
|
849
|
+
renderLabel="Choose date"
|
|
850
|
+
assistiveText="Type a date or use arrow keys to navigate date picker."
|
|
851
|
+
width="20rem"
|
|
852
|
+
isInline
|
|
853
|
+
value={'2023-11-23'}
|
|
854
|
+
onChange={onChange}
|
|
855
|
+
currentDate="2023-12-23"
|
|
856
|
+
disabledDates={['2023-12-22', '2023-12-12', '2023-12-11']}
|
|
857
|
+
disabledDateErrorMessage="disabled date"
|
|
858
|
+
invalidDateErrorMessage="invalid date"
|
|
859
|
+
locale="fr"
|
|
860
|
+
></DateInput>
|
|
861
|
+
)
|
|
862
|
+
const dateInput = screen.getByLabelText('Choose date')
|
|
863
|
+
|
|
864
|
+
fireEvent.click(dateInput)
|
|
865
|
+
|
|
866
|
+
const frenchMonday = screen.getByText('lu')
|
|
867
|
+
await waitFor(() => {
|
|
868
|
+
expect(typeof frenchMonday).toBe('object')
|
|
869
|
+
})
|
|
870
|
+
})
|
|
845
871
|
})
|
|
846
872
|
})
|
package/src/DateInput/index.tsx
CHANGED
|
@@ -265,7 +265,7 @@ class DateInput extends Component<DateInputProps, DateInputState> {
|
|
|
265
265
|
this.timezone()
|
|
266
266
|
)
|
|
267
267
|
.subtract(1, 'day')
|
|
268
|
-
.format('
|
|
268
|
+
.format('LL')
|
|
269
269
|
})
|
|
270
270
|
this.setState({ messages: [] })
|
|
271
271
|
}
|
|
@@ -282,7 +282,7 @@ class DateInput extends Component<DateInputProps, DateInputState> {
|
|
|
282
282
|
this.timezone()
|
|
283
283
|
)
|
|
284
284
|
.add(1, 'day')
|
|
285
|
-
.format('
|
|
285
|
+
.format('LL')
|
|
286
286
|
})
|
|
287
287
|
this.setState({ messages: [] })
|
|
288
288
|
}
|
|
@@ -341,6 +341,8 @@ class DateInput extends Component<DateInputProps, DateInputState> {
|
|
|
341
341
|
const noChildrenProps = this.props.children
|
|
342
342
|
? {}
|
|
343
343
|
: {
|
|
344
|
+
timezone: this.timezone(),
|
|
345
|
+
locale: this.locale(),
|
|
344
346
|
disabledDates,
|
|
345
347
|
currentDate,
|
|
346
348
|
selectedDate: isValidDate ? value : undefined,
|
|
@@ -352,9 +354,7 @@ class DateInput extends Component<DateInputProps, DateInputState> {
|
|
|
352
354
|
) => {
|
|
353
355
|
// @ts-expect-error TODO
|
|
354
356
|
onChange?.(e, {
|
|
355
|
-
value:
|
|
356
|
-
'D'
|
|
357
|
-
)}, ${momentDate.format('YYYY')}`
|
|
357
|
+
value: momentDate.format('LL')
|
|
358
358
|
})
|
|
359
359
|
this.handleHideCalendar(e, dateString)
|
|
360
360
|
}
|