@invoicebox/ui 0.1.0-alpha.321 → 0.1.0-alpha.325

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 (37) hide show
  1. package/dist/components/form/CountrySelect/components/CountryItem/index.d.ts +2 -1
  2. package/dist/components/form/CountrySelect/components/CountryItem/index.js +11 -4
  3. package/dist/components/form/CountrySelect/components/CountryItem/stlyes.d.ts +4 -0
  4. package/dist/components/form/CountrySelect/components/CountryItem/stlyes.js +18 -7
  5. package/dist/components/form/CountrySelect/index.d.ts +7 -0
  6. package/dist/components/form/CountrySelect/index.js +16 -4
  7. package/dist/components/form/CountrySelect/index.test.d.ts +1 -0
  8. package/dist/components/form/CountrySelect/index.test.js +85 -0
  9. package/dist/components/form/DateInput/index.d.ts +1 -1
  10. package/dist/components/form/DateInput/index.js +7 -1
  11. package/dist/components/form/DateInput/index.test.d.ts +1 -0
  12. package/dist/components/form/DateInput/index.test.js +71 -0
  13. package/dist/components/form/PhoneInput/index.d.ts +2 -1
  14. package/dist/components/form/PhoneInput/index.js +2 -1
  15. package/dist/components/form/PhoneInput/index.stories.js +2 -1
  16. package/dist/components/form/PhoneInput/phoneInputLogic.d.ts +2 -0
  17. package/dist/components/form/PhoneInput/types.d.ts +1 -0
  18. package/dist/components/form/PositiveIntegerInput/index.d.ts +4 -0
  19. package/dist/components/form/PositiveIntegerInput/index.js +46 -6
  20. package/dist/components/form/PositiveIntegerInput/index.test.d.ts +1 -0
  21. package/dist/components/form/PositiveIntegerInput/index.test.js +81 -0
  22. package/dist/components/form/PositiveIntegerInput/styles.d.ts +1 -3
  23. package/dist/components/form/PositiveIntegerInput/styles.js +8 -10
  24. package/dist/components/form/Select/index.js +23 -6
  25. package/dist/esm/components/form/CountrySelect/components/CountryItem/index.js +11 -4
  26. package/dist/esm/components/form/CountrySelect/components/CountryItem/stlyes.js +17 -6
  27. package/dist/esm/components/form/CountrySelect/index.js +17 -5
  28. package/dist/esm/components/form/CountrySelect/index.test.js +82 -0
  29. package/dist/esm/components/form/DateInput/index.js +7 -1
  30. package/dist/esm/components/form/DateInput/index.test.js +69 -0
  31. package/dist/esm/components/form/PhoneInput/index.js +2 -1
  32. package/dist/esm/components/form/PhoneInput/index.stories.js +2 -1
  33. package/dist/esm/components/form/PositiveIntegerInput/index.js +46 -6
  34. package/dist/esm/components/form/PositiveIntegerInput/index.test.js +78 -0
  35. package/dist/esm/components/form/PositiveIntegerInput/styles.js +7 -7
  36. package/dist/esm/components/form/Select/index.js +23 -6
  37. package/package.json +1 -1
@@ -9,5 +9,6 @@ export type TProps<TValue> = {
9
9
  selectedLabel: string;
10
10
  palette: TCountrySelectPalette;
11
11
  flag?: TFlagKey;
12
+ hint?: string;
12
13
  };
13
- export declare const CountryItem: <TValue>({ isSelected, flag, onSelect, description, value, countryLabel, selectedLabel, palette, }: TProps<TValue>) => import("react/jsx-runtime").JSX.Element;
14
+ export declare const CountryItem: <TValue>({ isSelected, flag, onSelect, description, value, countryLabel, selectedLabel, palette, hint, }: TProps<TValue>) => import("react/jsx-runtime").JSX.Element;
@@ -19,23 +19,30 @@ var CountryItem = exports.CountryItem = function CountryItem(_ref) {
19
19
  value = _ref.value,
20
20
  countryLabel = _ref.countryLabel,
21
21
  selectedLabel = _ref.selectedLabel,
22
- palette = _ref.palette;
22
+ palette = _ref.palette,
23
+ hint = _ref.hint;
23
24
  var handleSelect = (0, _react.useCallback)(function () {
24
25
  return onSelect(value);
25
26
  }, [onSelect, value]);
26
27
  return /*#__PURE__*/_react["default"].createElement(S.Wrapper, {
27
28
  $palette: palette,
28
29
  onClick: handleSelect,
29
- type: "button"
30
+ type: "button",
31
+ role: "option",
32
+ "aria-selected": isSelected
30
33
  }, /*#__PURE__*/_react["default"].createElement(S.Title, {
31
34
  $isSelected: isSelected,
32
35
  $palette: palette
33
36
  }, flag && /*#__PURE__*/_react["default"].createElement(_Flag.Flag, {
34
37
  flag: flag,
35
38
  isSmall: true
36
- }), /*#__PURE__*/_react["default"].createElement(_Typography.Typography, {
39
+ }), /*#__PURE__*/_react["default"].createElement(S.TitleTexts, null, /*#__PURE__*/_react["default"].createElement(_Typography.Typography, {
37
40
  variant: 'captionRegular'
38
- }, countryLabel, " ", isSelected && selectedLabel)), /*#__PURE__*/_react["default"].createElement(_Typography.Typography, {
41
+ }, countryLabel, " ", isSelected && selectedLabel), hint && /*#__PURE__*/_react["default"].createElement(S.Hint, {
42
+ $palette: palette
43
+ }, /*#__PURE__*/_react["default"].createElement(_Typography.Typography, {
44
+ variant: 'captionSRegular'
45
+ }, hint)))), /*#__PURE__*/_react["default"].createElement(_Typography.Typography, {
39
46
  variant: 'captionRegular'
40
47
  }, description));
41
48
  };
@@ -4,6 +4,10 @@ export declare const Title: import("styled-components/dist/types").IStyledCompon
4
4
  $isSelected: boolean;
5
5
  $palette: TCountrySelectPalette;
6
6
  }>> & string;
7
+ export declare const TitleTexts: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
8
+ export declare const Hint: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
9
+ $palette: TCountrySelectPalette;
10
+ }>> & string;
7
11
  export declare const Wrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, {
8
12
  $palette: TCountrySelectPalette;
9
13
  }>> & string;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.Wrapper = exports.Title = void 0;
6
+ exports.Wrapper = exports.TitleTexts = exports.Title = exports.Hint = void 0;
7
7
  var _styledComponents = _interopRequireDefault(require("styled-components"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
9
  var Title = exports.Title = _styledComponents["default"].div.withConfig({
@@ -16,16 +16,27 @@ var Title = exports.Title = _styledComponents["default"].div.withConfig({
16
16
  var $isSelected = _ref2.$isSelected;
17
17
  return $isSelected ? 0.5 : 1;
18
18
  });
19
- var Wrapper = exports.Wrapper = _styledComponents["default"].button.withConfig({
20
- displayName: "stlyes__Wrapper",
19
+ var TitleTexts = exports.TitleTexts = _styledComponents["default"].div.withConfig({
20
+ displayName: "stlyes__TitleTexts",
21
21
  componentId: "sc-cou0vg-1"
22
- })(["padding:15px 20px;display:flex;align-items:center;justify-content:space-between;width:100%;border:none;cursor:pointer;background-color:", ";color:", ";&:hover{background-color:", ";", "{opacity:0.5;}}"], function (_ref3) {
22
+ })(["text-align:left;"]);
23
+ var Hint = exports.Hint = _styledComponents["default"].div.withConfig({
24
+ displayName: "stlyes__Hint",
25
+ componentId: "sc-cou0vg-2"
26
+ })(["color:", ";"], function (_ref3) {
23
27
  var $palette = _ref3.$palette;
24
- return $palette.countryBg;
25
- }, function (_ref4) {
26
- var $palette = _ref4.$palette;
27
28
  return $palette.countryDescription;
29
+ });
30
+ var Wrapper = exports.Wrapper = _styledComponents["default"].button.withConfig({
31
+ displayName: "stlyes__Wrapper",
32
+ componentId: "sc-cou0vg-3"
33
+ })(["padding:15px 20px;display:flex;align-items:center;justify-content:space-between;width:100%;border:none;cursor:pointer;background-color:", ";color:", ";&:hover{background-color:", ";", "{opacity:0.5;}}"], function (_ref4) {
34
+ var $palette = _ref4.$palette;
35
+ return $palette.countryBg;
28
36
  }, function (_ref5) {
29
37
  var $palette = _ref5.$palette;
38
+ return $palette.countryDescription;
39
+ }, function (_ref6) {
40
+ var $palette = _ref6.$palette;
30
41
  return $palette.countryHoverBg;
31
42
  }, Title);
@@ -8,6 +8,7 @@ type TOption = {
8
8
  label: string;
9
9
  description: string;
10
10
  flag?: TFlagKey;
11
+ hint?: string;
11
12
  };
12
13
  type TFieldProps = {
13
14
  value: TOption['value'];
@@ -16,6 +17,12 @@ type TFieldProps = {
16
17
  type TControlProps<T> = Pick<TSearchInputProps, 'placeholder'> & Pick<TCountryItemProps<T>, 'selectedLabel'> & {
17
18
  options: TOption[];
18
19
  disabled?: boolean;
20
+ /**
21
+ * Только для скринридеров, на экране не выводится: начало aria-label кнопки выбора страны.
22
+ * Итоговое имя — «<buttonAriaLabelPrefix>: <название выбранной страны>», например
23
+ * «Код страны: Россия». Кнопка показывает только флаг, без имени её не понять (WCAG 4.1.2).
24
+ */
25
+ buttonAriaLabelPrefix?: string;
19
26
  } & Pick<TDropdownProps, 'positionVertical' | 'positionLeft' | 'positionRight' | 'minWidth' | 'width' | 'isAutoPosition' | 'isTopPosition'>;
20
27
  export type TProps = TFieldProps & TControlProps<string>;
21
28
  export declare const CountrySelect: FC<TProps>;
@@ -16,7 +16,7 @@ var _Arrow = require("../../common/Arrow");
16
16
  var _Dropdown = require("../../common/Dropdown");
17
17
  var _Scrollbar = require("../../common/Scrollbar");
18
18
  var _palette = require("../../../palette");
19
- var _excluded = ["value", "onChange", "options", "placeholder", "disabled", "selectedLabel"];
19
+ var _excluded = ["value", "onChange", "options", "placeholder", "disabled", "selectedLabel", "buttonAriaLabelPrefix"];
20
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
21
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
22
22
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
@@ -40,7 +40,10 @@ var CountrySelect = exports.CountrySelect = function CountrySelect(_ref) {
40
40
  _ref$disabled = _ref.disabled,
41
41
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
42
42
  selectedLabel = _ref.selectedLabel,
43
+ _ref$buttonAriaLabelP = _ref.buttonAriaLabelPrefix,
44
+ buttonAriaLabelPrefix = _ref$buttonAriaLabelP === void 0 ? 'Код страны' : _ref$buttonAriaLabelP,
43
45
  dropdownPositionProps = _objectWithoutProperties(_ref, _excluded);
46
+ var listboxId = (0, _react.useId)();
44
47
  var palette = (0, _palette.useComponentPalette)('countrySelect');
45
48
  var _useState = (0, _react.useState)(false),
46
49
  _useState2 = _slicedToArray(_useState, 2),
@@ -87,8 +90,12 @@ var CountrySelect = exports.CountrySelect = function CountrySelect(_ref) {
87
90
  }, /*#__PURE__*/_react["default"].createElement(S.HeaderWrapper, {
88
91
  type: "button",
89
92
  onClick: handleDropdownTrigger,
90
- disabled: disabled
91
- }, selectedOption.flag && /*#__PURE__*/_react["default"].createElement(_Flag.Flag, {
93
+ disabled: disabled,
94
+ "aria-label": selectedOption ? "".concat(buttonAriaLabelPrefix, ": ").concat(selectedOption.label) : buttonAriaLabelPrefix,
95
+ "aria-haspopup": "listbox",
96
+ "aria-expanded": isOpen,
97
+ "aria-controls": isOpen ? listboxId : undefined
98
+ }, (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.flag) && /*#__PURE__*/_react["default"].createElement(_Flag.Flag, {
92
99
  isSmall: false,
93
100
  flag: selectedOption.flag
94
101
  }), !disabled && /*#__PURE__*/_react["default"].createElement(_Arrow.Arrow, {
@@ -108,6 +115,10 @@ var CountrySelect = exports.CountrySelect = function CountrySelect(_ref) {
108
115
  value: search
109
116
  })), /*#__PURE__*/_react["default"].createElement(_Scrollbar.Scrollbar, {
110
117
  maxHeight: 192
118
+ }, /*#__PURE__*/_react["default"].createElement("div", {
119
+ role: "listbox",
120
+ id: listboxId,
121
+ "aria-label": buttonAriaLabelPrefix
111
122
  }, filtredOptions.map(function (option) {
112
123
  return /*#__PURE__*/_react["default"].createElement(_CountryItem.CountryItem, {
113
124
  key: option.value,
@@ -118,7 +129,8 @@ var CountrySelect = exports.CountrySelect = function CountrySelect(_ref) {
118
129
  value: option.value,
119
130
  isSelected: option === selectedOption,
120
131
  description: option.description,
132
+ hint: option.hint,
121
133
  flag: option.flag
122
134
  });
123
- })))));
135
+ }))))));
124
136
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ var _react = _interopRequireDefault(require("react"));
4
+ var _server = require("react-dom/server");
5
+ var _ = require(".");
6
+ var _PhoneInput = require("../PhoneInput");
7
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
8
+ var options = [{
9
+ label: 'Россия',
10
+ value: 'RUS',
11
+ description: '+7',
12
+ flag: 'RUS'
13
+ }, {
14
+ label: 'Казахстан',
15
+ value: 'KAZ',
16
+ description: '+7',
17
+ flag: 'KAZ'
18
+ }];
19
+
20
+ // Серверный рендер: предупреждения про useLayoutEffect (Dropdown) ожидаемы и к проверке не относятся
21
+ // eslint-disable-next-line no-console
22
+ var originalError = console.error;
23
+ beforeAll(function () {
24
+ jest.spyOn(console, 'error').mockImplementation(function (message) {
25
+ if (typeof message === 'string' && message.includes('useLayoutEffect does nothing on the server')) return;
26
+ // eslint-disable-next-line no-console
27
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
28
+ rest[_key - 1] = arguments[_key];
29
+ }
30
+ originalError.apply(void 0, [message].concat(rest));
31
+ });
32
+ });
33
+ afterAll(function () {
34
+ return jest.restoreAllMocks();
35
+ });
36
+ var noop = jest.fn();
37
+ var renderButton = function renderButton(markup) {
38
+ var match = markup.match(/<button[^>]*aria-haspopup[^>]*>/);
39
+ if (!match) throw new Error("\u041A\u043D\u043E\u043F\u043A\u0430 \u0432\u044B\u0431\u043E\u0440\u0430 \u0441\u0442\u0440\u0430\u043D\u044B \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D\u0430: ".concat(markup));
40
+ return match[0];
41
+ };
42
+ describe('CountrySelect: доступное имя и состояние кнопки (A11Y-12)', function () {
43
+ test('имя по умолчанию — «Код страны: <страна>», свёрнут, раскрывает listbox', function () {
44
+ var button = renderButton((0, _server.renderToStaticMarkup)(/*#__PURE__*/_react["default"].createElement(_.CountrySelect, {
45
+ value: "KAZ",
46
+ onChange: noop,
47
+ options: options,
48
+ selectedLabel: ""
49
+ })));
50
+ expect(button).toContain('aria-label="Код страны: Казахстан"');
51
+ expect(button).toContain('aria-haspopup="listbox"');
52
+ expect(button).toContain('aria-expanded="false"');
53
+ expect(button).not.toContain('aria-controls');
54
+ });
55
+ test('префикс имени задаётся пропом buttonAriaLabelPrefix', function () {
56
+ var button = renderButton((0, _server.renderToStaticMarkup)(/*#__PURE__*/_react["default"].createElement(_.CountrySelect, {
57
+ value: "RUS",
58
+ onChange: noop,
59
+ options: options,
60
+ selectedLabel: "",
61
+ buttonAriaLabelPrefix: "Country code"
62
+ })));
63
+ expect(button).toContain('aria-label="Country code: Россия"');
64
+ });
65
+ test('PhoneInput пробрасывает buttonAriaLabelPrefix из countrySelectProps', function () {
66
+ var button = renderButton((0, _server.renderToStaticMarkup)(/*#__PURE__*/_react["default"].createElement(_PhoneInput.PhoneInput, {
67
+ label: "\u0422\u0435\u043B\u0435\u0444\u043E\u043D",
68
+ value: "",
69
+ onChange: noop,
70
+ countries: [{
71
+ label: 'Russia',
72
+ value: 'RUS'
73
+ }, {
74
+ label: 'Belarus',
75
+ value: 'BLR'
76
+ }],
77
+ countrySelectProps: {
78
+ selectedLabel: '',
79
+ placeholder: '',
80
+ buttonAriaLabelPrefix: 'Country code'
81
+ }
82
+ })));
83
+ expect(button).toContain('aria-label="Country code: Russia"');
84
+ });
85
+ });
@@ -11,7 +11,7 @@ export type TProps = {
11
11
  dropdownProps?: Pick<TDropdownProps, 'isAutoPosition' | 'positionLeft' | 'positionRight' | 'positionVertical'>;
12
12
  useModernStyles?: boolean;
13
13
  required?: boolean;
14
- } & Pick<TPureInputProps, 'hasError' | 'name' | 'onBlur' | 'onFocus' | 'id'> & Pick<TInputLabelProps, 'label'> & Pick<TCalendarProps, 'maxDate' | 'minDate'> & {
14
+ } & Pick<TPureInputProps, 'hasError' | 'name' | 'onBlur' | 'onFocus' | 'id' | 'inputMode'> & Pick<TInputLabelProps, 'label'> & Pick<TCalendarProps, 'maxDate' | 'minDate'> & {
15
15
  size?: TSizes;
16
16
  };
17
17
  export declare const DateInput: FC<TProps>;
@@ -46,12 +46,17 @@ var DateInput = exports.DateInput = function DateInput(_ref) {
46
46
  useModernStyles = _ref$useModernStyles === void 0 ? false : _ref$useModernStyles,
47
47
  _ref$required = _ref.required,
48
48
  required = _ref$required === void 0 ? false : _ref$required,
49
- id = _ref.id;
49
+ id = _ref.id,
50
+ inputMode = _ref.inputMode;
50
51
  var palette = (0, _palette.useComponentPalette)('dateInput');
51
52
  var inputRef = (0, _react.useRef)(null);
52
53
  var fallbackId = (0, _react.useId)();
53
54
  var inputId = id !== null && id !== void 0 ? id : fallbackId;
54
55
  var isMobile = (0, _index.useMobile)();
56
+ // На мобильном тап по полю открывает календарь в шторке — экранная клавиатура поверх него
57
+ // не нужна (MOB-8). Ввод с клавиатуры остаётся (физическая клавиатура, вставка); проп
58
+ // inputMode переопределяет значение, например 'none' для всех тач-экранов
59
+ var fieldInputMode = inputMode !== null && inputMode !== void 0 ? inputMode : isMobile ? 'none' : undefined;
55
60
  var _useState = (0, _react.useState)(false),
56
61
  _useState2 = _slicedToArray(_useState, 2),
57
62
  isOpen = _useState2[0],
@@ -142,6 +147,7 @@ var DateInput = exports.DateInput = function DateInput(_ref) {
142
147
  onBlur: handleBlur,
143
148
  value: stringValue,
144
149
  onChange: handleStringValueChange,
150
+ inputMode: fieldInputMode,
145
151
  paddingRight: 44,
146
152
  useModernStyles: useModernStyles
147
153
  }, paddingAndVariantOptions)), /*#__PURE__*/_react["default"].createElement(S.Icon, {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ var _react = _interopRequireDefault(require("react"));
4
+ var _server = require("react-dom/server");
5
+ var _ = require(".");
6
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
7
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
8
+ // Серверный рендер: предупреждения про useLayoutEffect (Dropdown) ожидаемы и к проверке не относятся
9
+ // eslint-disable-next-line no-console
10
+ var originalError = console.error;
11
+ beforeAll(function () {
12
+ jest.spyOn(console, 'error').mockImplementation(function (message) {
13
+ if (typeof message === 'string' && message.includes('useLayoutEffect does nothing on the server')) return;
14
+ // eslint-disable-next-line no-console
15
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
16
+ rest[_key - 1] = arguments[_key];
17
+ }
18
+ originalError.apply(void 0, [message].concat(rest));
19
+ });
20
+ });
21
+ afterAll(function () {
22
+ return jest.restoreAllMocks();
23
+ });
24
+ var noop = jest.fn();
25
+
26
+ // useMobile читает window.matchMedia при первом рендере
27
+ var withViewport = function withViewport(isMobile, render) {
28
+ var globalWithWindow = globalThis;
29
+ var previous = globalWithWindow.window;
30
+ globalWithWindow.window = {
31
+ matchMedia: function matchMedia() {
32
+ return {
33
+ matches: isMobile
34
+ };
35
+ }
36
+ };
37
+ try {
38
+ return render();
39
+ } finally {
40
+ globalWithWindow.window = previous;
41
+ }
42
+ };
43
+ var renderInput = function renderInput(isMobile) {
44
+ var _markup$match$, _markup$match;
45
+ var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
46
+ var markup = withViewport(isMobile, function () {
47
+ return (0, _server.renderToStaticMarkup)(/*#__PURE__*/_react["default"].createElement(_.DateInput, _extends({
48
+ id: "date",
49
+ label: "\u0414\u0430\u0442\u0430",
50
+ value: null,
51
+ onChange: noop
52
+ }, props)));
53
+ });
54
+ return (_markup$match$ = (_markup$match = markup.match(/<input[^>]*>/)) === null || _markup$match === void 0 ? void 0 : _markup$match[0]) !== null && _markup$match$ !== void 0 ? _markup$match$ : '';
55
+ };
56
+ describe('DateInput: экранная клавиатура (MOB-8)', function () {
57
+ test('на мобильном — inputmode="none": тап открывает только календарь', function () {
58
+ expect(renderInput(true)).toContain('inputMode="none"');
59
+ });
60
+ test('на десктопе inputmode не задан', function () {
61
+ expect(renderInput(false)).not.toContain('inputMode');
62
+ });
63
+ test('проп inputMode переопределяет значение по умолчанию', function () {
64
+ expect(renderInput(false, {
65
+ inputMode: 'none'
66
+ })).toContain('inputMode="none"');
67
+ expect(renderInput(true, {
68
+ inputMode: 'numeric'
69
+ })).toContain('inputMode="numeric"');
70
+ });
71
+ });
@@ -10,11 +10,12 @@ type TFieldProps = Pick<TPureInputProps, 'name' | 'onBlur' | 'onFocus'> & {
10
10
  };
11
11
  type TControlProps = Pick<TPureInputProps, 'disabled' | 'id' | 'autoFocus' | 'useModernStyles'> & {
12
12
  label: string;
13
- countrySelectProps?: Pick<TCountrySelectProps, 'selectedLabel' | 'placeholder'>;
13
+ countrySelectProps?: Pick<TCountrySelectProps, 'selectedLabel' | 'placeholder' | 'buttonAriaLabelPrefix'>;
14
14
  onCountryChange?: (countryCode: string) => void;
15
15
  countries?: Array<{
16
16
  label: string;
17
17
  value: TSupportedCountries;
18
+ hint?: string;
18
19
  }>;
19
20
  pureInputProps?: Pick<TPureInputProps, 'paddingTop' | 'paddingBottom' | 'autoFocus'>;
20
21
  size?: TSizes;
@@ -212,7 +212,8 @@ var PhoneInput = exports.PhoneInput = function PhoneInput(_ref) {
212
212
  positionRight: "0",
213
213
  positionLeft: "-20px",
214
214
  disabled: disabled,
215
- selectedLabel: (countrySelectProps === null || countrySelectProps === void 0 ? void 0 : countrySelectProps.selectedLabel) || ''
215
+ selectedLabel: (countrySelectProps === null || countrySelectProps === void 0 ? void 0 : countrySelectProps.selectedLabel) || '',
216
+ buttonAriaLabelPrefix: countrySelectProps === null || countrySelectProps === void 0 ? void 0 : countrySelectProps.buttonAriaLabelPrefix
216
217
  }))), /*#__PURE__*/_react["default"].createElement(_reactInputMask["default"], {
217
218
  value: inputValue,
218
219
  onFocus: focusHandler,
@@ -153,7 +153,8 @@ var MultiCountryWithUnknown = exports.MultiCountryWithUnknown = {
153
153
  value: 'BLR'
154
154
  }, {
155
155
  label: 'Другая',
156
- value: 'UNKNOWN'
156
+ value: 'UNKNOWN',
157
+ hint: 'Выберите если вашей страны нет в списке'
157
158
  }]
158
159
  }),
159
160
  render: Component
@@ -11,11 +11,13 @@ export declare class PhoneInputLogic {
11
11
  getCountriesSelectOptions(countries?: Array<{
12
12
  label: string;
13
13
  value: TSupportedCountries;
14
+ hint?: string;
14
15
  }>): {
15
16
  description: string;
16
17
  flag: "RUS" | "BLR" | "KAZ" | "AZE" | "ARM" | "KGZ" | "MDA" | "TJK" | "UZB" | "CHN" | "ENG" | "ESP" | "ARE" | "AUS" | "DEU" | "ECU" | "FRA" | "IND" | "SAU" | "SRB" | "SVK" | "SVN" | "TUR" | "USA" | "CAN" | "UNKNOWN";
17
18
  label: string;
18
19
  value: TSupportedCountries;
20
+ hint?: string | undefined;
19
21
  }[] | undefined;
20
22
  getIsHaveCountriesSelectOptions(countrySelectOptions?: Array<TCountrySelectOption | TSupportedCountries>): boolean;
21
23
  getCountriesPhoneRulesBySelectOptions(countrySelectOptions?: Array<TCountrySelectOption>): {
@@ -15,4 +15,5 @@ export type TCountrySelectOption = {
15
15
  flag: string;
16
16
  label: string;
17
17
  value: string;
18
+ hint?: string;
18
19
  };
@@ -7,6 +7,10 @@ export type TProps = {
7
7
  onChange: (value: number | null) => void;
8
8
  max?: number;
9
9
  upAndDown?: boolean;
10
+ /** Только для скринридеров и голосового управления, на экране не выводится: aria-label кнопки «вверх» */
11
+ incrementButtonAriaLabel?: string;
12
+ /** Только для скринридеров и голосового управления, на экране не выводится: aria-label кнопки «вниз» */
13
+ decrementButtonAriaLabel?: string;
10
14
  } & Pick<TInputLabelProps, 'label'> & Pick<TPureInputProps, 'placeholder' | 'hasError' | 'onFocus' | 'onBlur' | 'disabled' | 'name' | 'useModernStyles' | 'id'> & {
11
15
  size?: TSizes;
12
16
  };
@@ -35,7 +35,13 @@ var PositiveIntegerInput = exports.PositiveIntegerInput = function PositiveInteg
35
35
  size = _ref.size,
36
36
  _ref$useModernStyles = _ref.useModernStyles,
37
37
  useModernStyles = _ref$useModernStyles === void 0 ? false : _ref$useModernStyles,
38
- id = _ref.id;
38
+ id = _ref.id,
39
+ _ref$disabled = _ref.disabled,
40
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
41
+ _ref$incrementButtonA = _ref.incrementButtonAriaLabel,
42
+ incrementButtonAriaLabel = _ref$incrementButtonA === void 0 ? 'Увеличить' : _ref$incrementButtonA,
43
+ _ref$decrementButtonA = _ref.decrementButtonAriaLabel,
44
+ decrementButtonAriaLabel = _ref$decrementButtonA === void 0 ? 'Уменьшить' : _ref$decrementButtonA;
39
45
  var _useInputFocus = (0, _useInputFocus2.useInputFocus)({
40
46
  onFocus: onFocus,
41
47
  onBlur: onBlur
@@ -85,12 +91,32 @@ var PositiveIntegerInput = exports.PositiveIntegerInput = function PositiveInteg
85
91
  var handleDown = (0, _react.useCallback)(function () {
86
92
  onChange(decrement(value));
87
93
  }, [decrement, value, onChange]);
94
+ var isUpDisabled = disabled || isIncrementDisabled;
95
+ var isDownDisabled = disabled || isDecrementDisabled;
96
+
97
+ // Стрелки клавиатуры в поле — как кнопки «вверх»/«вниз» (кнопки вне порядка Tab)
98
+ var handleKeyDown = (0, _react.useCallback)(function (event) {
99
+ if (!upAndDown) return;
100
+ if (event.key === 'ArrowUp') {
101
+ event.preventDefault();
102
+ if (!isUpDisabled) handleUp();
103
+ } else if (event.key === 'ArrowDown') {
104
+ event.preventDefault();
105
+ if (!isDownDisabled) handleDown();
106
+ }
107
+ }, [handleDown, handleUp, isDownDisabled, isUpDisabled, upAndDown]);
108
+
109
+ // Клик по кнопке не забирает фокус у поля: иначе срабатывал бы onBlur поля
110
+ var preventFocusLoss = (0, _react.useCallback)(function (event) {
111
+ return event.preventDefault();
112
+ }, []);
88
113
  return /*#__PURE__*/_react["default"].createElement(_InputLabel.InputLabel, {
89
114
  inFocus: inFocus,
90
115
  label: inputLabel,
91
116
  useModernStyles: useModernStyles,
92
117
  size: fieldSize,
93
- htmlFor: inputId
118
+ htmlFor: inputId,
119
+ disabled: disabled
94
120
  }, /*#__PURE__*/_react["default"].createElement(S.ControlWrapper, null, modernPlaceholder, /*#__PURE__*/_react["default"].createElement(_PureInput.PureInput, _extends({
95
121
  id: inputId,
96
122
  "aria-label": label && !inputLabel ? label : undefined,
@@ -102,18 +128,32 @@ var PositiveIntegerInput = exports.PositiveIntegerInput = function PositiveInteg
102
128
  onBlur: handleBlur,
103
129
  value: normalizeFrom(value),
104
130
  onChange: handleChange,
131
+ onKeyDown: handleKeyDown,
132
+ disabled: disabled,
133
+ inputMode: "numeric",
134
+ pattern: "[0-9]*",
105
135
  paddingRight: upAndDown ? 44 : undefined
106
136
  }, paddingAndVariantOptions, {
107
137
  useModernStyles: useModernStyles
108
138
  })), upAndDown && /*#__PURE__*/_react["default"].createElement(S.Arrows, null, /*#__PURE__*/_react["default"].createElement(S.Arrow, {
109
- onClick: handleUp,
110
- $disabled: isIncrementDisabled
139
+ type: "button",
140
+ tabIndex: -1,
141
+ "aria-label": incrementButtonAriaLabel,
142
+ "aria-controls": inputId,
143
+ disabled: isUpDisabled,
144
+ onMouseDown: preventFocusLoss,
145
+ onClick: handleUp
111
146
  }, /*#__PURE__*/_react["default"].createElement(_Arrow.Arrow, {
112
147
  isOpen: true,
113
148
  outterSize: 12
114
149
  })), /*#__PURE__*/_react["default"].createElement(S.Arrow, {
115
- onClick: handleDown,
116
- $disabled: isDecrementDisabled
150
+ type: "button",
151
+ tabIndex: -1,
152
+ "aria-label": decrementButtonAriaLabel,
153
+ "aria-controls": inputId,
154
+ disabled: isDownDisabled,
155
+ onMouseDown: preventFocusLoss,
156
+ onClick: handleDown
117
157
  }, /*#__PURE__*/_react["default"].createElement(_Arrow.Arrow, {
118
158
  isOpen: false,
119
159
  outterSize: 12
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ var _react = _interopRequireDefault(require("react"));
4
+ var _server = require("react-dom/server");
5
+ var _ = require(".");
6
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
7
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
13
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
14
+ var noop = jest.fn();
15
+ var render = function render() {
16
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17
+ return (0, _server.renderToStaticMarkup)(/*#__PURE__*/_react["default"].createElement(_.PositiveIntegerInput, _extends({
18
+ id: "count",
19
+ label: "\u041A\u043E\u043B-\u0432\u043E",
20
+ value: 2,
21
+ onChange: noop,
22
+ max: 5,
23
+ upAndDown: true
24
+ }, props)));
25
+ };
26
+ var buttons = function buttons(markup) {
27
+ var _markup$match;
28
+ return (_markup$match = markup.match(/<button[^>]*>/g)) !== null && _markup$match !== void 0 ? _markup$match : [];
29
+ };
30
+ var input = function input(markup) {
31
+ var _markup$match$, _markup$match2;
32
+ return (_markup$match$ = (_markup$match2 = markup.match(/<input[^>]*>/)) === null || _markup$match2 === void 0 ? void 0 : _markup$match2[0]) !== null && _markup$match$ !== void 0 ? _markup$match$ : '';
33
+ };
34
+ describe('PositiveIntegerInput: стрелки «вверх/вниз» (A11Y-16)', function () {
35
+ test('стрелки — кнопки с именами вне порядка Tab', function () {
36
+ var _buttons = buttons(render()),
37
+ _buttons2 = _slicedToArray(_buttons, 2),
38
+ up = _buttons2[0],
39
+ down = _buttons2[1];
40
+ expect(up).toContain('type="button"');
41
+ expect(up).toContain('tabindex="-1"');
42
+ expect(up).toContain('aria-label="Увеличить"');
43
+ expect(up).toContain('aria-controls="count"');
44
+ expect(up).not.toContain('disabled');
45
+ expect(down).toContain('aria-label="Уменьшить"');
46
+ expect(down).not.toContain('disabled');
47
+ });
48
+ test('имена кнопок задаются пропами', function () {
49
+ var _buttons3 = buttons(render({
50
+ incrementButtonAriaLabel: 'Увеличить количество',
51
+ decrementButtonAriaLabel: 'Уменьшить количество'
52
+ })),
53
+ _buttons4 = _slicedToArray(_buttons3, 2),
54
+ up = _buttons4[0],
55
+ down = _buttons4[1];
56
+ expect(up).toContain('aria-label="Увеличить количество"');
57
+ expect(down).toContain('aria-label="Уменьшить количество"');
58
+ });
59
+ test('на границах недоступна соответствующая кнопка', function () {
60
+ expect(buttons(render({
61
+ value: 5
62
+ }))[0]).toContain('disabled');
63
+ expect(buttons(render({
64
+ value: 0
65
+ }))[1]).toContain('disabled');
66
+ });
67
+ test('disabled блокирует поле и обе кнопки', function () {
68
+ var markup = render({
69
+ disabled: true
70
+ });
71
+ expect(input(markup)).toContain('disabled');
72
+ buttons(markup).forEach(function (button) {
73
+ return expect(button).toContain('disabled');
74
+ });
75
+ });
76
+ test('цифровая клавиатура на телефоне', function () {
77
+ var field = input(render());
78
+ expect(field).toContain('inputMode="numeric"');
79
+ expect(field).toContain('pattern="[0-9]*"');
80
+ });
81
+ });
@@ -1,6 +1,4 @@
1
1
  /// <reference types="react" />
2
2
  export declare const Arrows: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
3
- export declare const Arrow: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
4
- $disabled: boolean;
5
- }>> & string;
3
+ export declare const Arrow: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, never>> & string;
6
4
  export declare const ControlWrapper: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;