@transferwise/components 0.0.0-experimental-e05dfa3 → 0.0.0-experimental-7905c27

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.
Files changed (50) hide show
  1. package/build/index.esm.js +102 -164
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +104 -166
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/dateLookup/DateLookup.css +1 -1
  7. package/build/styles/header/Header.css +1 -1
  8. package/build/styles/main.css +1 -1
  9. package/build/types/dateInput/DateInput.d.ts +2 -0
  10. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  11. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  12. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts +1 -1
  13. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -1
  14. package/build/types/dateLookup/tableLink/TableLink.d.ts +2 -16
  15. package/build/types/dateLookup/tableLink/TableLink.d.ts.map +1 -1
  16. package/build/types/dateLookup/tableLink/index.d.ts +1 -1
  17. package/build/types/dateLookup/tableLink/index.d.ts.map +1 -1
  18. package/build/types/dateLookup/yearCalendar/table/YearCalendarTable.d.ts.map +1 -1
  19. package/build/types/select/Select.d.ts.map +1 -1
  20. package/build/types/test-utils/window-mock.d.ts +1 -0
  21. package/build/types/test-utils/window-mock.d.ts.map +1 -1
  22. package/package.json +1 -1
  23. package/src/dateInput/DateInput.js +13 -7
  24. package/src/dateInput/DateInput.spec.js +12 -136
  25. package/src/dateInput/DateInput.story.tsx +49 -2
  26. package/src/dateLookup/DateLookup.css +1 -1
  27. package/src/dateLookup/DateLookup.js +3 -16
  28. package/src/dateLookup/DateLookup.keyboardEvents.spec.js +0 -12
  29. package/src/dateLookup/DateLookup.less +49 -46
  30. package/src/dateLookup/DateLookup.story.js +7 -8
  31. package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -14
  32. package/src/dateLookup/dayCalendar/table/DayCalendarTable.spec.js +0 -25
  33. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.js +20 -33
  34. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.spec.js +0 -33
  35. package/src/dateLookup/tableLink/TableLink.js +70 -0
  36. package/src/dateLookup/yearCalendar/table/YearCalendarTable.js +11 -33
  37. package/src/dateLookup/yearCalendar/table/YearCalendarTable.spec.js +0 -26
  38. package/src/header/Header.css +1 -1
  39. package/src/header/Header.less +0 -5
  40. package/src/inputs/SelectInput.spec.tsx +3 -27
  41. package/src/main.css +1 -1
  42. package/src/phoneNumberInput/PhoneNumberInput.spec.js +4 -20
  43. package/src/select/Select.js +3 -0
  44. package/src/test-utils/window-mock.ts +11 -0
  45. package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts +0 -2
  46. package/build/types/dateLookup/getFocusableTime/getFocusableTime.d.ts.map +0 -1
  47. package/src/dateLookup/getFocusableTime/getFocusable.spec.js +0 -38
  48. package/src/dateLookup/getFocusableTime/getFocusableTime.tsx +0 -28
  49. package/src/dateLookup/tableLink/TableLink.tsx +0 -80
  50. /package/src/dateLookup/tableLink/{index.ts → index.js} +0 -0
@@ -15,6 +15,8 @@ export interface DateInputPlaceholders {
15
15
  }
16
16
 
17
17
  export interface DateInputProps {
18
+ "aria-label"?: string;
19
+ "aria-labelledby"?: string;
18
20
  disabled?: boolean;
19
21
  size?: DateInputSize;
20
22
  value?: DateInputValue;
@@ -1 +1 @@
1
- {"version":3,"file":"DateInput.d.ts","sourceRoot":"","sources":["../../../src/dateInput/DateInput.js"],"names":[],"mappings":";AAeA;;;;;;;;;;;;;;;;;gCAsQC"}
1
+ {"version":3,"file":"DateInput.d.ts","sourceRoot":"","sources":["../../../src/dateInput/DateInput.js"],"names":[],"mappings":";AAeA;;;;;;;;;;;;;;;;;;;gCA0QC"}
@@ -1 +1 @@
1
- {"version":3,"file":"DateLookup.d.ts","sourceRoot":"","sources":["../../../src/dateLookup/DateLookup.js"],"names":[],"mappings":";AAqBA;IAoBE;;;;;;aAqBC;IApCD,wBAaC;IAjBD,wCAAsB;IAEtB,yCAAuB;IAIrB;;;;;;;;;;MAUC;IA0BH,6CAMC;IAFC,uCAAyE;IAI3E,6BAGC;IAED,iBAOE;IAEF,oBAME;IAEF,kBAME;IAEF,oCA2CE;IAEF,wEAmBE;IAEF,+DAOE;IAEF,gCAIE;IAEF,yBAA+C;IAE/C,2BAAmD;IAEnD,0BAAiD;IAEjD,sDAME;IAEF;;;eAEE;IAEF,+CA8BE;IAEF,wBAGE;IAEF,sCA0BC;CACF"}
1
+ {"version":3,"file":"DateLookup.d.ts","sourceRoot":"","sources":["../../../src/dateLookup/DateLookup.js"],"names":[],"mappings":";AAqBA;IAmBE;;;;;;aAqBC;IAnCD,wBAYC;IAhBD,wCAAsB;IAEtB,yCAAuB;IAIrB;;;;;;;;;MASC;IA0BH,6CAMC;IAFC,uCAAyE;IAI3E,6BAGC;IAED,iBAOE;IAEF,kBAME;IAEF,oCA0CE;IAEF,wEAgBE;IAEF,+DAOE;IAEF,gCAIE;IAEF,yBAA+C;IAE/C,2BAAmD;IAEnD,0BAAiD;IAEjD,sDAME;IAEF;;;eAEE;IAEF,+CA8BE;IAEF,wBAGE;IAEF,sCA0BC;CACF"}
@@ -1,5 +1,5 @@
1
1
  export default MonthCalendarTable;
2
- declare function MonthCalendarTable({ selectedDate, min, max, viewYear, placeholder, onSelect }: {
2
+ declare function MonthCalendarTable({ selectedDate: selected, min, max, viewYear, placeholder, onSelect, }: {
3
3
  selectedDate: any;
4
4
  min: any;
5
5
  max: any;
@@ -1 +1 @@
1
- {"version":3,"file":"MonthCalendarTable.d.ts","sourceRoot":"","sources":["../../../../../src/dateLookup/monthCalendar/table/MonthCalendarTable.js"],"names":[],"mappings":";AAWA;;;;;;;gCA4DC"}
1
+ {"version":3,"file":"MonthCalendarTable.d.ts","sourceRoot":"","sources":["../../../../../src/dateLookup/monthCalendar/table/MonthCalendarTable.js"],"names":[],"mappings":";AAUA;;;;;;;gCAgDC"}
@@ -1,19 +1,5 @@
1
- /// <reference types="react" />
2
- import { IntlShape } from 'react-intl';
3
- interface TableLinkProps {
4
- item: number;
5
- type: 'day' | 'month' | 'year';
6
- title?: string;
7
- longTitle?: string;
8
- active: boolean;
9
- disabled: boolean;
10
- today: boolean;
11
- autofocus?: boolean;
12
- onClick: (item: number) => void;
13
- intl: IntlShape;
14
- }
15
- declare const _default: import("react").FC<import("react-intl").WithIntlProps<TableLinkProps>> & {
16
- WrappedComponent: import("react").ComponentType<TableLinkProps>;
1
+ declare const _default: import("react").FC<import("react-intl").WithIntlProps<any>> & {
2
+ WrappedComponent: import("react").ComponentType<any>;
17
3
  };
18
4
  export default _default;
19
5
  //# sourceMappingURL=TableLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TableLink.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/TableLink.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAc,SAAS,EAAE,MAAM,YAAY,CAAC;AAInD,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,IAAI,EAAE,SAAS,CAAC;CACjB;;;;AA8DD,wBAAqC"}
1
+ {"version":3,"file":"TableLink.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/TableLink.js"],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- export { default } from './TableLink';
1
+ export { default } from "./TableLink";
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/dateLookup/tableLink/index.js"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"YearCalendarTable.d.ts","sourceRoot":"","sources":["../../../../../src/dateLookup/yearCalendar/table/YearCalendarTable.js"],"names":[],"mappings":";AAWA;;;;;;;gCAuDC"}
1
+ {"version":3,"file":"YearCalendarTable.d.ts","sourceRoot":"","sources":["../../../../../src/dateLookup/yearCalendar/table/YearCalendarTable.js"],"names":[],"mappings":";AAUA;;;;;;;gCAkCC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../src/select/Select.js"],"names":[],"mappings":"AA8EA;;;;;;;;;;;;;;;;;;;;;;gCAkeC"}
1
+ {"version":3,"file":"Select.d.ts","sourceRoot":"","sources":["../../../src/select/Select.js"],"names":[],"mappings":"AA8EA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;gCAkeC"}
@@ -1,2 +1,3 @@
1
1
  export declare function mockMatchMedia(): void;
2
+ export declare function mockResizeObserver(): void;
2
3
  //# sourceMappingURL=window-mock.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"window-mock.d.ts","sourceRoot":"","sources":["../../../src/test-utils/window-mock.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,SAkB7B"}
1
+ {"version":3,"file":"window-mock.d.ts","sourceRoot":"","sources":["../../../src/test-utils/window-mock.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,SAkB7B;AAED,wBAAgB,kBAAkB,SASjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-e05dfa3",
3
+ "version": "0.0.0-experimental-7905c27",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import { useState } from 'react';
4
4
  import { useIntl } from 'react-intl';
5
5
 
6
- import { Select, Input } from '..';
6
+ import { Input, SelectInput, SelectInputOptionContent } from '..';
7
7
  import { Size, DateMode, MonthFormat } from '../common';
8
8
  import { getMonthNames, isDateValid, isMonthAndYearFormat } from '../common/dateUtils';
9
9
 
@@ -14,6 +14,8 @@ const MonthBeforeDay = new Set(['en-US', 'ja-JP']);
14
14
  const INITIAL_DEFAULT_STATE = { year: null, month: null, day: null };
15
15
 
16
16
  const DateInput = ({
17
+ 'aria-labelledby': ariaLabelledBy,
18
+ 'aria-label': ariaLabel,
17
19
  disabled,
18
20
  size,
19
21
  value,
@@ -88,16 +90,16 @@ const DateInput = ({
88
90
  const months = getMonthNames(locale, monthFormat);
89
91
 
90
92
  return (
91
- <label>
93
+ <label className="d-flex flex-column">
92
94
  <span className="sr-only">{monthLabel}</span>
93
- <Select
94
- id={id ? `${id}-select` : undefined}
95
+ <SelectInput
95
96
  name="month"
96
97
  disabled={disabled}
97
98
  placeholder={placeholders.month}
98
- options={getMonthsOptions()}
99
+ items={getMonthsOptions()}
99
100
  size={size}
100
- selected={month === null ? null : { value: month, label: months[month] }}
101
+ value={month === null ? null : { value: month, label: months[month] }}
102
+ renderValue={({ label }) => <SelectInputOptionContent title={label} />}
101
103
  onChange={(selectedValue) => handleMonthChange(selectedValue)}
102
104
  {...selectProps}
103
105
  />
@@ -110,7 +112,7 @@ const DateInput = ({
110
112
  const months = getMonthNames(locale, monthFormat);
111
113
 
112
114
  months.forEach((label, index) => {
113
- options.push({ value: index, label });
115
+ options.push({ type: 'option', value: { label, value: index } });
114
116
  });
115
117
  return options;
116
118
  };
@@ -224,6 +226,8 @@ const DateInput = ({
224
226
  <div
225
227
  className="tw-date"
226
228
  id={id}
229
+ aria-labelledby={ariaLabelledBy}
230
+ aria-label={ariaLabel}
227
231
  onFocus={(event) =>
228
232
  shouldPropagateOnFocus(event) ? onFocus && onFocus() : event.stopPropagation()
229
233
  }
@@ -300,6 +304,8 @@ function shouldPropagateOnBlur({ target, relatedTarget }) {
300
304
  }
301
305
 
302
306
  DateInput.propTypes = {
307
+ 'aria-label': PropTypes.string,
308
+ 'aria-labelledby': PropTypes.string,
303
309
  disabled: PropTypes.bool,
304
310
  size: PropTypes.oneOf(['sm', 'md', 'lg']),
305
311
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.instanceOf(Date)]),
@@ -2,7 +2,7 @@ import { shallow, mount } from 'enzyme';
2
2
  import { useIntl } from 'react-intl';
3
3
 
4
4
  import { DateInput, Input } from '..';
5
- import { fakeEvent } from '../common/fakeEvents';
5
+ import { mockMatchMedia, mockResizeObserver } from '../test-utils';
6
6
 
7
7
  const MONTHS_FR = [
8
8
  'janvier',
@@ -41,10 +41,10 @@ const LOCALES = {
41
41
 
42
42
  const DEFAULT_LOCALE = 'en-GB';
43
43
 
44
- const FEBRUARY_OPTION = { value: 1, label: MONTHS_EN[1] };
44
+ const FEBRUARY_OPTION = { value: MONTHS_EN[1] };
45
45
 
46
46
  const DAY_SELECTOR = 'ForwardRef(Input)[name="day"]';
47
- const MONTH_SELECTOR = 'Select';
47
+ const MONTH_SELECTOR = 'SelectInput';
48
48
  const YEAR_SELECTOR = 'ForwardRef(Input)[name="year"]';
49
49
 
50
50
  jest.mock('./DateInput.messages', () => ({
@@ -78,6 +78,8 @@ describe('Date Input Component', () => {
78
78
  const props = { onChange: jest.fn() };
79
79
 
80
80
  beforeEach(() => {
81
+ mockMatchMedia();
82
+ mockResizeObserver();
81
83
  useIntl.mockReturnValue({
82
84
  locale: DEFAULT_LOCALE,
83
85
  formatMessage: (message) => message.defaultMessage,
@@ -99,7 +101,7 @@ describe('Date Input Component', () => {
99
101
  });
100
102
 
101
103
  it('sets month field to 0', () => {
102
- expect(selectMonth.props().selected).toBeNull();
104
+ expect(selectMonth.props().value).toBeNull();
103
105
  });
104
106
 
105
107
  it('sets year field to empty', () => {
@@ -131,7 +133,7 @@ describe('Date Input Component', () => {
131
133
  inputYear = component.find(YEAR_SELECTOR);
132
134
 
133
135
  expect(inputDay.prop('value')).toBe(1);
134
- expect(selectMonth.prop('selected')).toStrictEqual(FEBRUARY_OPTION);
136
+ expect(selectMonth.prop('value').label).toBe(FEBRUARY_OPTION.value);
135
137
  expect(inputYear.prop('value')).toBe(1971);
136
138
  });
137
139
  });
@@ -145,7 +147,7 @@ describe('Date Input Component', () => {
145
147
  inputYear = component.find(YEAR_SELECTOR);
146
148
 
147
149
  expect(inputDay.prop('value')).toBe(22);
148
- expect(selectMonth.prop('selected')).toStrictEqual({ label: MONTHS_EN[7], value: 7 });
150
+ expect(selectMonth.prop('value').label).toBe(MONTHS_EN[7]);
149
151
  expect(inputYear.prop('value')).toBe(1990);
150
152
  });
151
153
  });
@@ -159,7 +161,7 @@ describe('Date Input Component', () => {
159
161
  inputYear = component.find(YEAR_SELECTOR);
160
162
 
161
163
  expect(inputDay.prop('value')).toBe('');
162
- expect(selectMonth.prop('selected')).toStrictEqual({ label: MONTHS_EN[7], value: 7 });
164
+ expect(selectMonth.prop('value').label).toBe(MONTHS_EN[7]);
163
165
  expect(inputYear.prop('value')).toBe(1990);
164
166
  });
165
167
  });
@@ -173,7 +175,7 @@ describe('Date Input Component', () => {
173
175
  inputYear = component.find(YEAR_SELECTOR);
174
176
 
175
177
  expect(inputDay.prop('value')).toBe(28);
176
- expect(selectMonth.prop('selected')).toStrictEqual(FEBRUARY_OPTION);
178
+ expect(selectMonth.prop('value').label).toBe(FEBRUARY_OPTION.value);
177
179
  expect(inputYear.prop('value')).toBe(1990);
178
180
  });
179
181
  });
@@ -216,7 +218,7 @@ describe('Date Input Component', () => {
216
218
  component = shallow(<DateInput {...props} />);
217
219
  selectMonth = component.find(MONTH_SELECTOR);
218
220
 
219
- expect(selectMonth.props().options[0].label).toStrictEqual(MONTHS_FR[0]);
221
+ expect(selectMonth.props().items[0].value.label).toStrictEqual(MONTHS_FR[0]);
220
222
  });
221
223
 
222
224
  it('shows day before month if locale not US', () => {
@@ -240,26 +242,6 @@ describe('Date Input Component', () => {
240
242
  });
241
243
  });
242
244
 
243
- describe('when id is provided', () => {
244
- it('renders Select component with id', () => {
245
- component = mount(<DateInput id="mock-id" {...props} />);
246
-
247
- const select = component.find('Select');
248
-
249
- expect(select.prop('id')).toBe('mock-id-select');
250
- });
251
- });
252
-
253
- describe('when id is not provided', () => {
254
- it('renders Select component with no id', () => {
255
- component = mount(<DateInput {...props} />);
256
-
257
- const select = component.find('Select');
258
-
259
- expect(select.prop('id')).toBeUndefined();
260
- });
261
- });
262
-
263
245
  describe('when initialised', () => {
264
246
  describe('without an initial value', () => {
265
247
  it(`doesn't call the onChange callback`, () => {
@@ -334,19 +316,6 @@ describe('Date Input Component', () => {
334
316
 
335
317
  describe('when user interacts', () => {
336
318
  describe('with an empty date input', () => {
337
- it('calls onChange with null if day is not entered', () => {
338
- component = mount(<DateInput {...props} />);
339
-
340
- // Select February
341
- simulateSelectChange(2);
342
-
343
- inputYear = component.find(YEAR_SELECTOR);
344
-
345
- inputYear.simulate('change', { target: { value: '1990' } });
346
-
347
- expect(props.onChange).toHaveBeenLastCalledWith(null);
348
- });
349
-
350
319
  it('calls onChange with null if month is not selected', () => {
351
320
  component = mount(<DateInput {...props} />);
352
321
 
@@ -360,36 +329,6 @@ describe('Date Input Component', () => {
360
329
 
361
330
  expect(props.onChange).toHaveBeenLastCalledWith(null);
362
331
  });
363
-
364
- it('calls onChange with null if year is not entered', () => {
365
- component = mount(<DateInput {...props} />);
366
-
367
- inputDay = component.find(DAY_SELECTOR);
368
-
369
- inputDay.simulate('change', { target: { value: '12' } });
370
-
371
- // Select February
372
- simulateSelectChange(2);
373
-
374
- expect(props.onChange).toHaveBeenLastCalledWith(null);
375
- });
376
-
377
- it('returns a valid date if all three fields are entered', () => {
378
- component = mount(<DateInput {...props} />);
379
-
380
- inputDay = component.find(DAY_SELECTOR);
381
-
382
- inputDay.simulate('change', { target: { value: '12' } });
383
-
384
- // Select February
385
- simulateSelectChange(2);
386
-
387
- inputYear = component.find(YEAR_SELECTOR);
388
-
389
- inputYear.simulate('change', { target: { value: '1990' } });
390
-
391
- expect(props.onChange).toHaveBeenLastCalledWith('1990-02-12');
392
- });
393
332
  });
394
333
 
395
334
  describe('with day input', () => {
@@ -434,26 +373,6 @@ describe('Date Input Component', () => {
434
373
  expect(props.onChange).toHaveBeenCalledWith('1990-01-01');
435
374
  });
436
375
  });
437
-
438
- describe('with month select', () => {
439
- it('returns correct value for correct input', () => {
440
- component = mount(<DateInput {...props} value="2001-01-01" />);
441
-
442
- // Selects March
443
- simulateSelectChange(3);
444
-
445
- expect(props.onChange).toHaveBeenCalledWith('2001-03-01');
446
- });
447
-
448
- it('returns null when de-selecting month', () => {
449
- component = mount(<DateInput {...props} value="2001-01-01" />);
450
-
451
- // De-selects Month
452
- simulateSelectChange(0);
453
-
454
- expect(props.onChange).toHaveBeenLastCalledWith(null);
455
- });
456
- });
457
376
  });
458
377
 
459
378
  describe('with day input and year input', () => {
@@ -515,38 +434,6 @@ describe('Date Input Component', () => {
515
434
  expect(component.find(DAY_SELECTOR).prop('value')).toBe(28);
516
435
  });
517
436
 
518
- it('corrects days too high in February', () => {
519
- component = mount(<DateInput {...props} />);
520
-
521
- inputDay = component.find(DAY_SELECTOR);
522
- inputYear = component.find(YEAR_SELECTOR);
523
-
524
- inputDay.simulate('change', { target: { value: 29 } });
525
- // Selects February
526
- simulateSelectChange(2);
527
- inputYear.simulate('change', { target: { value: 2001 } });
528
-
529
- expect(component.find(DAY_SELECTOR).prop('value')).toBe(28);
530
- });
531
-
532
- it("doesn't correct days in leap years February", () => {
533
- component = mount(<DateInput {...props} value="2000-03-29" />);
534
-
535
- // Selects February
536
- simulateSelectChange(2);
537
-
538
- expect(component.find(DAY_SELECTOR).prop('value')).toBe(29);
539
- });
540
-
541
- it('corrects days too high for selected months', () => {
542
- component = mount(<DateInput {...props} value="2001-01-31" />);
543
-
544
- // Selects April
545
- simulateSelectChange(4);
546
-
547
- expect(component.find(DAY_SELECTOR).prop('value')).toBe(30);
548
- });
549
-
550
437
  it('lowers days if value entered too high', () => {
551
438
  const comp = shallow(<DateInput {...props} />);
552
439
 
@@ -582,12 +469,6 @@ describe('Date Input Component', () => {
582
469
  expect(component.exists(MONTH_SELECTOR)).toBe(true);
583
470
  expect(component.exists(DAY_SELECTOR)).toBe(false);
584
471
  });
585
-
586
- it('should produce MM-YYYY date string', () => {
587
- // Selects March
588
- simulateSelectChange(3);
589
- expect(props.onChange).toHaveBeenCalledWith('2001-03');
590
- });
591
472
  });
592
473
 
593
474
  describe('when selectProps is provided', () => {
@@ -605,16 +486,11 @@ describe('Date Input Component', () => {
605
486
  });
606
487
 
607
488
  it('renders Select component with expected props', () => {
608
- const select = component.find('Select');
489
+ const select = component.find(MONTH_SELECTOR);
609
490
 
610
491
  expect(select.prop('buttonProps')).toStrictEqual({
611
492
  'aria-label': 'mock-button-label',
612
493
  });
613
494
  });
614
495
  });
615
-
616
- const simulateSelectChange = (n) => {
617
- component.find('button.np-dropdown-toggle').simulate('click', fakeEvent());
618
- component.find('li').at(n).simulate('click', fakeEvent());
619
- };
620
496
  });
@@ -1,7 +1,7 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
 
3
- import { DateInput, InlineAlert } from '..';
4
- import { lorem10, storyConfig } from '../test-utils';
3
+ import { DateInput, Info, InlineAlert, Title, Typography } from '..';
4
+ import { lorem10, storyConfig, userEvent, within } from '../test-utils';
5
5
 
6
6
  export default {
7
7
  component: DateInput,
@@ -25,6 +25,53 @@ type Story = StoryObj<typeof DateInput>;
25
25
 
26
26
  export const Basic: Story = {};
27
27
 
28
+ Basic.play = ({ canvasElement }) => {
29
+ const canvas = within(canvasElement);
30
+ userEvent.click(canvas.getByRole('button'));
31
+ };
32
+
33
+ export const WithLabel: Story = {
34
+ render: (args) => {
35
+ const id1 = 'date-input-group-label-1';
36
+ const label = 'Date of Birth';
37
+ return (
38
+ <>
39
+ <Title type={Typography.TITLE_SUBSECTION}>
40
+ label (as <code>div</code> element) is linked with <code>DateInput</code> via{' '}
41
+ <code>aria-labelledby</code> prop
42
+ </Title>
43
+ <div className="control-label" id={id1}>
44
+ Date of Delivery
45
+ </div>
46
+ <DateInput {...args} aria-labelledby={id1} />
47
+
48
+ <br />
49
+
50
+ <Title type={Typography.TITLE_SUBSECTION}>
51
+ label (as <code>div</code> element) is detached but <code>DateInput</code> has same label
52
+ via <code>aria-label</code> attribute
53
+ </Title>
54
+ <div className="control-label">
55
+ {label}{' '}
56
+ <Info aria-label="Fast transfer hint" title="Fast transfer hint" content={lorem10} />
57
+ </div>
58
+ <DateInput {...args} aria-label={label} />
59
+
60
+ <br />
61
+
62
+ <Title type={Typography.TITLE_SUBSECTION}>
63
+ <code>DateInput</code> wrapped in <code>fieldset</code> + using <code>legend</code> as
64
+ label (rare use case)
65
+ </Title>
66
+ <fieldset>
67
+ <legend className="control-label">Expiry Date</legend>
68
+ <DateInput {...args} />
69
+ </fieldset>
70
+ </>
71
+ );
72
+ },
73
+ };
74
+
28
75
  export const BasicMobile: Story = storyConfig(Basic, { variants: ['mobile'] });
29
76
 
30
77
  export const InputError: Story = {
@@ -1 +1 @@
1
- .tw-date-lookup-menu{width:400px}.tw-date-lookup-calendar{background-color:inherit;min-width:300px;table-layout:fixed;text-align:center}.tw-date-lookup-calendar>tbody>tr>td:nth-child(7n+6) button,.tw-date-lookup-calendar>tbody>tr>td:nth-child(7n+7) button,.tw-date-lookup-calendar>thead>tr>th:nth-child(7n+6),.tw-date-lookup-calendar>thead>tr>th:nth-child(7n+7){color:#5d7079;color:var(--color-content-secondary);font-weight:400;font-weight:var(--font-weight-regular)}.tw-date-lookup-calendar>tbody>tr>td{padding:4px;padding:var(--size-4)}@media (max-width:320px){.tw-date-lookup-calendar>tbody>tr>td{padding:0}}.tw-date-lookup-calendar>tbody>tr>td:has(.tw-date-lookup-day-option){padding:1px}.tw-date-lookup-calendar>tbody>tr>td button{background-color:transparent;border:transparent;border-radius:10px;border-radius:var(--radius-small);color:#0097c7;color:var(--color-content-accent);color:#37517e;color:var(--color-content-primary);font-weight:600;font-weight:var(--font-weight-semi-bold);padding:4px 0;padding:var(--size-4) 0;width:100%}@media (max-width:320px){.tw-date-lookup-calendar>tbody>tr>td button{padding:0}}.tw-date-lookup-calendar>tbody>tr>td button.tw-date-lookup-day-option{align-items:center;border-radius:50%;display:inline-flex;height:40px;height:var(--size-40);justify-content:center;line-height:40px;line-height:var(--size-40);padding:0;width:40px;width:var(--size-40)}.tw-date-lookup-calendar>tbody>tr>td button.tw-date-lookup-day-option.today{text-decoration:underline;text-decoration-thickness:2px;text-underline-offset:4px}.tw-date-lookup-calendar>tbody>tr>td:hover button:not(.disabled,:disabled),.tw-date-lookup-calendar>tbody>tr>td:not(.disabled,:disabled) button.show-focus{background-color:var(--color-background-screen-hover)}.tw-date-lookup-calendar>tbody>tr>td:not(.disabled,:disabled) button.active{background-color:var(--color-interactive-primary);color:#00a2dd;color:var(--color-interactive-accent)}.tw-date-lookup-calendar abbr{text-decoration:none}.tw-date-lookup-header-current-container{display:inline}.tw-date-lookup-header-current{font-weight:800;font-weight:var(--font-weight-bold)}.np-theme-personal .tw-date-lookup-menu .table-bordered,.np-theme-personal.tw-date-lookup-menu .table-bordered{border:none}.np-theme-personal .tw-date-lookup-menu thead,.np-theme-personal.tw-date-lookup-menu thead{background-color:unset}.np-theme-personal .tw-date-lookup-menu td,.np-theme-personal.tw-date-lookup-menu td{border:none}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-header-current,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-header-current{color:#37517e;color:var(--color-content-primary)}
1
+ .tw-date-lookup-menu{width:400px}.tw-date-lookup-calendar{min-width:300px;table-layout:fixed;text-align:center}.tw-date-lookup-calendar>tbody>tr>td{padding:4px;padding:var(--size-4)}@media (max-width:320px){.tw-date-lookup-calendar>tbody>tr>td{padding:0}}.tw-date-lookup-calendar>tbody>tr>td button{background-color:transparent;border:transparent;border-radius:10px;border-radius:var(--radius-small);color:#0097c7;color:var(--color-content-accent);font-weight:600;font-weight:var(--font-weight-semi-bold);padding:4px 0;padding:var(--size-4) 0;width:100%}@media (max-width:320px){.tw-date-lookup-calendar>tbody>tr>td button{padding:0}}.tw-date-lookup-calendar>tbody>tr>td button:not(.disabled,:disabled).active{background-color:#0081ba;background-color:var(--color-interactive-accent-active);color:#fff}.tw-date-lookup-calendar>tbody>tr>td button:not(.disabled,:disabled):hover{background-color:#008fc9;background-color:var(--color-interactive-accent-hover);color:#fff}.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td button{color:#37517e;color:var(--color-content-primary)}.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td button:not(.disabled,:disabled).active,.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td button:not(.disabled,:disabled):hover{color:var(--color-interactive-control)}.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td:nth-child(7n+6) button,.np-theme-personal .tw-date-lookup-calendar>tbody>tr>td:nth-child(7n+7) button,.np-theme-personal .tw-date-lookup-calendar>thead>tr>th:nth-child(7n+6),.np-theme-personal .tw-date-lookup-calendar>thead>tr>th:nth-child(7n+7){color:#5d7079;color:var(--color-content-secondary);font-weight:400;font-weight:var(--font-weight-regular)}.tw-date-lookup-calendar abbr{text-decoration:none}.np-theme-personal .tw-date-lookup-calendar{background-color:inherit}.np-theme-personal .tw-date-lookup-menu .table-bordered,.np-theme-personal.tw-date-lookup-menu .table-bordered{border:none}.np-theme-personal .tw-date-lookup-menu thead,.np-theme-personal.tw-date-lookup-menu thead{background-color:unset}.np-theme-personal .tw-date-lookup-menu td,.np-theme-personal.tw-date-lookup-menu td{border:none}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-header-current-container,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-header-current-container{display:inline-block}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-header-current-container .tw-date-lookup-header-current,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-header-current-container .tw-date-lookup-header-current{color:#37517e;color:var(--color-content-primary)}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-day-option,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-day-option{align-items:center;color:#37517e;color:var(--color-content-primary);display:inline-flex;height:32px;height:var(--size-32);justify-content:center;line-height:32px;line-height:var(--size-32)}.np-theme-personal .tw-date-lookup-menu .tw-date-lookup-day-option.active,.np-theme-personal.tw-date-lookup-menu .tw-date-lookup-day-option.active{background-color:#00a2dd;background-color:var(--color-interactive-accent);color:var(--color-interactive-primary)}
@@ -28,7 +28,6 @@ class DateLookup extends PureComponent {
28
28
  super(props);
29
29
  this.state = {
30
30
  selectedDate: getStartOfDay(props.value),
31
- originalDate: null,
32
31
  min: getStartOfDay(props.min),
33
32
  max: getStartOfDay(props.max),
34
33
  viewMonth: (props.value || new Date()).getMonth(),
@@ -84,14 +83,6 @@ class DateLookup extends PureComponent {
84
83
  }
85
84
  };
86
85
 
87
- discard = () => {
88
- const { originalDate } = this.state;
89
- if (originalDate !== null) {
90
- this.props.onChange(originalDate);
91
- }
92
- this.close();
93
- };
94
-
95
86
  close = () => {
96
87
  const { onBlur } = this.props;
97
88
  this.setState({ open: false });
@@ -101,7 +92,7 @@ class DateLookup extends PureComponent {
101
92
  };
102
93
 
103
94
  handleKeyDown = (event) => {
104
- const { open, originalDate } = this.state;
95
+ const { open } = this.state;
105
96
  switch (event.keyCode) {
106
97
  case KeyCodes.LEFT:
107
98
  if (open) {
@@ -136,7 +127,6 @@ class DateLookup extends PureComponent {
136
127
  event.preventDefault();
137
128
  break;
138
129
  case KeyCodes.ESCAPE:
139
- originalDate && this.props.onChange(originalDate);
140
130
  this.close();
141
131
  event.preventDefault();
142
132
  break;
@@ -146,10 +136,7 @@ class DateLookup extends PureComponent {
146
136
  };
147
137
 
148
138
  adjustDate = (daysToAdd, monthsToAdd, yearsToAdd) => {
149
- const { selectedDate, min, max, mode, originalDate } = this.state;
150
- if (originalDate === null) {
151
- this.setState({ originalDate: selectedDate });
152
- }
139
+ const { selectedDate, min, max, mode } = this.state;
153
140
  let date;
154
141
  if (selectedDate) {
155
142
  date = new Date(
@@ -256,7 +243,7 @@ class DateLookup extends PureComponent {
256
243
  open={open}
257
244
  className="tw-date-lookup-menu"
258
245
  position={Position.BOTTOM}
259
- onClose={this.discard}
246
+ onClose={this.close}
260
247
  >
261
248
  {this.getCalendar()}
262
249
  </ResponsivePanel>
@@ -80,18 +80,6 @@ describe('DateLookup (keyboard events)', () => {
80
80
  pressKey(KEY_CODES.DOWN);
81
81
  onChangeCalledWith(new Date(2019, 0, 3));
82
82
  });
83
-
84
- it('resets to original date when escape key is pressed', () => {
85
- pressKey(KEY_CODES.LEFT);
86
- pressKey(KEY_CODES.ESCAPE);
87
- onChangeCalledWith(date);
88
- });
89
-
90
- it('resets to original date when clicking outside modal', () => {
91
- pressKey(KEY_CODES.LEFT);
92
- component.find('.dimmer').simulate('click');
93
- onChangeCalledWith(date);
94
- });
95
83
  });
96
84
 
97
85
  describe('when open and in month mode', () => {