@transferwise/components 0.0.0-experimental-11854c7 → 0.0.0-experimental-bf4cb26

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,7 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { SelectInputProps } from '..';
3
- import { DateMode, MonthFormat, SizeSmall, SizeMedium, SizeLarge } from '../common';
3
+ import { DateMode, MonthFormat, SizeLarge, SizeMedium, SizeSmall } from '../common';
4
4
  export interface DateInputProps {
5
+ /** @deprecated Use `Field` wrapper or the `aria-labelledby` attribute instead. */
5
6
  'aria-label'?: string;
6
7
  'aria-labelledby'?: string;
7
8
  disabled?: boolean;
@@ -25,6 +26,6 @@ export interface DateInputProps {
25
26
  id?: string;
26
27
  selectProps?: Partial<SelectInputProps<number | null>>;
27
28
  }
28
- declare const DateInput: ({ "aria-labelledby": ariaLabelledBy, "aria-label": ariaLabel, disabled, size, value, dayLabel, dayAutoComplete, monthLabel, yearLabel, yearAutoComplete, monthFormat, mode, onChange, onFocus, onBlur, placeholders, id, selectProps, }: DateInputProps) => import("react").JSX.Element;
29
+ declare const DateInput: ({ "aria-labelledby": ariaLabelledByProp, "aria-label": ariaLabel, disabled, size, value, dayLabel, dayAutoComplete, monthLabel, yearLabel, yearAutoComplete, monthFormat, mode, onChange, onFocus, onBlur, placeholders, id: idProp, selectProps, }: DateInputProps) => import("react").JSX.Element;
29
30
  export default DateInput;
30
31
  //# sourceMappingURL=DateInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DateInput.d.ts","sourceRoot":"","sources":["../../../src/dateInput/DateInput.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAsB,gBAAgB,EAA4B,MAAM,IAAI,CAAC;AACpF,OAAO,EAAQ,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAM1F,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,EAAE,MAA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experimental-11854c7",
3
+ "version": "0.0.0-experimental-bf4cb26",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,17 @@
1
+ import { Field } from '../field/Field';
2
+ import { mockMatchMedia, mockResizeObserver, render, screen } from '../test-utils';
3
+ import DateInput from './DateInput';
4
+
5
+ mockMatchMedia();
6
+ mockResizeObserver();
7
+
8
+ describe('DateInput', () => {
9
+ it('supports `Field` for labeling', () => {
10
+ render(
11
+ <Field label="Date of birth">
12
+ <DateInput onChange={() => {}} />
13
+ </Field>,
14
+ );
15
+ expect(screen.getAllByRole('group')[0]).toHaveAccessibleName(/^Date of birth/);
16
+ });
17
+ });
@@ -2,14 +2,15 @@ import classNames from 'classnames';
2
2
  import { useState } from 'react';
3
3
  import { useIntl } from 'react-intl';
4
4
 
5
- import { Input, SelectInput, SelectInputProps, SelectInputOptionContent } from '..';
6
- import { Size, DateMode, MonthFormat, SizeSmall, SizeMedium, SizeLarge } from '../common';
7
- import { getMonthNames, isDateValid, isMonthAndYearFormat, MDY, YMD } from '../common/dateUtils';
8
-
5
+ import { Input, SelectInput, SelectInputOptionContent, SelectInputProps } from '..';
6
+ import { DateMode, MonthFormat, Size, SizeLarge, SizeMedium, SizeSmall } from '../common';
7
+ import { MDY, YMD, getMonthNames, isDateValid, isMonthAndYearFormat } from '../common/dateUtils';
8
+ import { useInputAttributes } from '../inputs/contexts';
9
9
  import messages from './DateInput.messages';
10
10
  import { convertToLocalMidnight } from './utils';
11
11
 
12
12
  export interface DateInputProps {
13
+ /** @deprecated Use `Field` wrapper or the `aria-labelledby` attribute instead. */
13
14
  'aria-label'?: string;
14
15
  'aria-labelledby'?: string;
15
16
  disabled?: boolean;
@@ -35,7 +36,7 @@ export interface DateInputProps {
35
36
  }
36
37
 
37
38
  const DateInput = ({
38
- 'aria-labelledby': ariaLabelledBy,
39
+ 'aria-labelledby': ariaLabelledByProp,
39
40
  'aria-label': ariaLabel,
40
41
  disabled = false,
41
42
  size = Size.MEDIUM,
@@ -51,9 +52,13 @@ const DateInput = ({
51
52
  onFocus,
52
53
  onBlur,
53
54
  placeholders,
54
- id,
55
+ id: idProp,
55
56
  selectProps = {},
56
57
  }: DateInputProps) => {
58
+ const inputAttributes = useInputAttributes({ nonLabelable: true });
59
+ const id = idProp ?? inputAttributes.id;
60
+ const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes['aria-labelledby'];
61
+
57
62
  const { locale, formatMessage } = useIntl();
58
63
 
59
64
  const getDateObject = (): Date | undefined => {
@@ -95,9 +100,9 @@ const DateInput = ({
95
100
  );
96
101
  const monthNames = getMonthNames(locale, monthFormat);
97
102
 
98
- dayLabel = dayLabel || formatMessage(messages.dayLabel);
99
- monthLabel = monthLabel || formatMessage(messages.monthLabel);
100
- yearLabel = yearLabel || formatMessage(messages.yearLabel);
103
+ dayLabel ||= formatMessage(messages.dayLabel);
104
+ monthLabel ||= formatMessage(messages.monthLabel);
105
+ yearLabel ||= formatMessage(messages.yearLabel);
101
106
  placeholders = {
102
107
  day: placeholders?.day || formatMessage(messages.dayPlaceholder),
103
108
  month: placeholders?.month || formatMessage(messages.monthLabel),
@@ -298,6 +303,7 @@ const DateInput = ({
298
303
  return (
299
304
  <div
300
305
  className="tw-date"
306
+ {...inputAttributes}
301
307
  id={id}
302
308
  aria-labelledby={ariaLabelledBy}
303
309
  aria-label={ariaLabel}
@@ -328,7 +334,8 @@ const DateInput = ({
328
334
  {getYear()}
329
335
  </>
330
336
  );
331
- } else if (yearFirst) {
337
+ }
338
+ if (yearFirst) {
332
339
  return (
333
340
  <>
334
341
  {getYear()}
@@ -336,15 +343,14 @@ const DateInput = ({
336
343
  {getDay()}
337
344
  </>
338
345
  );
339
- } else {
340
- return (
341
- <>
342
- {getDay()}
343
- {getMonth()}
344
- {getYear()}
345
- </>
346
- );
347
346
  }
347
+ return (
348
+ <>
349
+ {getDay()}
350
+ {getMonth()}
351
+ {getYear()}
352
+ </>
353
+ );
348
354
  })()}
349
355
  </div>
350
356
  </div>