@transferwise/components 46.32.0 → 46.33.0

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 (33) hide show
  1. package/build/index.js +46 -31
  2. package/build/index.js.map +1 -1
  3. package/build/index.mjs +46 -31
  4. package/build/index.mjs.map +1 -1
  5. package/build/types/common/domHelpers/documentIosClick.d.ts +0 -1
  6. package/build/types/common/domHelpers/documentIosClick.d.ts.map +1 -1
  7. package/build/types/common/domHelpers/index.d.ts +1 -1
  8. package/build/types/common/domHelpers/index.d.ts.map +1 -1
  9. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  10. package/build/types/moneyInput/MoneyInput.d.ts +4 -2
  11. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  12. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts +1 -1
  13. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
  14. package/build/types/select/Select.d.ts +7 -7
  15. package/build/types/select/Select.d.ts.map +1 -1
  16. package/build/types/typeahead/Typeahead.d.ts +4 -55
  17. package/build/types/typeahead/Typeahead.d.ts.map +1 -1
  18. package/package.json +3 -3
  19. package/src/common/domHelpers/documentIosClick.ts +0 -5
  20. package/src/common/domHelpers/index.ts +0 -1
  21. package/src/dateLookup/DateLookup.rtl.spec.tsx +2 -3
  22. package/src/dateLookup/DateLookup.tsx +1 -3
  23. package/src/inputs/SelectInput.spec.tsx +1 -1
  24. package/src/moneyInput/MoneyInput.rtl.spec.tsx +10 -0
  25. package/src/moneyInput/MoneyInput.spec.js +10 -5
  26. package/src/moneyInput/MoneyInput.tsx +21 -14
  27. package/src/phoneNumberInput/PhoneNumberInput.rtl.spec.tsx +10 -0
  28. package/src/phoneNumberInput/PhoneNumberInput.tsx +11 -2
  29. package/src/select/Select.js +18 -15
  30. package/src/select/Select.rtl.spec.tsx +17 -0
  31. package/src/select/Select.spec.js +2 -7
  32. package/src/typeahead/Typeahead.rtl.spec.tsx +16 -0
  33. package/src/typeahead/Typeahead.tsx +21 -7
package/build/index.js CHANGED
@@ -166,10 +166,6 @@ function stopPropagation$1(event) {
166
166
  event.nativeEvent.stopImmediatePropagation();
167
167
  }
168
168
  }
169
- function getSimpleRandomId(prefix) {
170
- const random = Math.ceil(Math.random() * 999999);
171
- return `${prefix}${random}`;
172
- }
173
169
 
174
170
  /**
175
171
  * Defined in `Dimmer.less`
@@ -7460,9 +7456,8 @@ const formatAmountIfSet = ({
7460
7456
  }) => {
7461
7457
  if (maxLengthOverride) {
7462
7458
  return amount != null ? String(amount) : '';
7463
- } else {
7464
- return typeof amount === 'number' ? formatting.formatAmount(amount, currency, locale) : '';
7465
7459
  }
7460
+ return typeof amount === 'number' ? formatting.formatAmount(amount, currency, locale) : '';
7466
7461
  };
7467
7462
  const parseNumber = ({
7468
7463
  amount,
@@ -7520,7 +7515,7 @@ class MoneyInput extends React.Component {
7520
7515
  key,
7521
7516
  ctrlKey
7522
7517
  } = event;
7523
- const isNumberKey = neptuneValidation.isNumber(parseInt(key, 10));
7518
+ const isNumberKey = neptuneValidation.isNumber(Number.parseInt(key, 10));
7524
7519
  return isNumberKey || metaKey || ctrlKey || allowedInputKeys.has(key);
7525
7520
  };
7526
7521
  handleKeyDown = event => {
@@ -7536,7 +7531,7 @@ class MoneyInput extends React.Component {
7536
7531
  const parsed = neptuneValidation.isEmpty(paste) ? null : parseNumber({
7537
7532
  amount: paste,
7538
7533
  currency: this.props.selectedCurrency.currency,
7539
- locale: locale,
7534
+ locale,
7540
7535
  maxLengthOverride: this.props.maxLengthOverride
7541
7536
  });
7542
7537
  if (isNumberOrNull(parsed)) {
@@ -7544,7 +7539,7 @@ class MoneyInput extends React.Component {
7544
7539
  formattedAmount: formatAmountIfSet({
7545
7540
  amount: parsed,
7546
7541
  currency: this.props.selectedCurrency.currency,
7547
- locale: locale,
7542
+ locale,
7548
7543
  maxLengthOverride: this.props.maxLengthOverride
7549
7544
  })
7550
7545
  });
@@ -7641,15 +7636,17 @@ class MoneyInput extends React.Component {
7641
7636
  style = className => this.props.classNames[className] || className;
7642
7637
  render() {
7643
7638
  const {
7639
+ inputAttributes,
7640
+ id: amountInputId,
7641
+ 'aria-labelledby': ariaLabelledByProp,
7644
7642
  selectedCurrency,
7645
7643
  onCurrencyChange,
7646
7644
  size,
7647
7645
  addon,
7648
- id,
7649
- 'aria-labelledby': ariaLabelledBy,
7650
7646
  selectProps,
7651
7647
  maxLengthOverride
7652
7648
  } = this.props;
7649
+ const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes?.['aria-labelledby'];
7653
7650
  const selectOptions = this.getSelectOptions();
7654
7651
  const hasSingleCurrency = () => {
7655
7652
  if (selectOptions.length !== 0) {
@@ -7670,10 +7667,12 @@ class MoneyInput extends React.Component {
7670
7667
  const isFixedCurrency = !this.state.searchQuery && hasSingleCurrency() || !onCurrencyChange;
7671
7668
  const disabled = !this.props.onAmountChange;
7672
7669
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
7670
+ role: "group",
7671
+ ...inputAttributes,
7673
7672
  "aria-labelledby": ariaLabelledBy,
7674
7673
  className: classNames__default.default(this.style('tw-money-input'), this.style('input-group'), this.style(`input-group-${size}`)),
7675
7674
  children: [/*#__PURE__*/jsxRuntime.jsx(Input, {
7676
- id: id,
7675
+ id: amountInputId,
7677
7676
  value: this.state.formattedAmount,
7678
7677
  inputMode: "decimal",
7679
7678
  disabled: disabled,
@@ -7774,7 +7773,7 @@ function currencyOptionFitsQuery(option, query) {
7774
7773
  return contains(option.label, query) || contains(option.searchable, query) || contains(option.note, query);
7775
7774
  }
7776
7775
  function contains(property, query) {
7777
- return property && property.toLowerCase().includes(query.toLowerCase());
7776
+ return property?.toLowerCase().includes(query.toLowerCase());
7778
7777
  }
7779
7778
  function sortOptionsLabelsToFirst(options, query) {
7780
7779
  return [...options].sort((first, second) => {
@@ -7792,7 +7791,9 @@ function sortOptionsLabelsToFirst(options, query) {
7792
7791
  return 0;
7793
7792
  });
7794
7793
  }
7795
- var MoneyInput$1 = reactIntl.injectIntl(MoneyInput);
7794
+ var MoneyInput$1 = reactIntl.injectIntl(withInputAttributes(MoneyInput, {
7795
+ nonLabelable: true
7796
+ }));
7796
7797
 
7797
7798
  const NavigationOptionList = ({
7798
7799
  children
@@ -9313,7 +9314,7 @@ const defaultSelectProps = {};
9313
9314
  const defaultDisabledCountries = [];
9314
9315
  const PhoneNumberInput = ({
9315
9316
  id,
9316
- 'aria-labelledby': ariaLabelledBy,
9317
+ 'aria-labelledby': ariaLabelledByProp,
9317
9318
  required,
9318
9319
  disabled,
9319
9320
  initialValue,
@@ -9327,6 +9328,10 @@ const PhoneNumberInput = ({
9327
9328
  selectProps = defaultSelectProps,
9328
9329
  disabledCountries = defaultDisabledCountries
9329
9330
  }) => {
9331
+ const inputAttributes = useInputAttributes({
9332
+ nonLabelable: true
9333
+ });
9334
+ const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes['aria-labelledby'];
9330
9335
  const {
9331
9336
  locale,
9332
9337
  formatMessage
@@ -9383,6 +9388,8 @@ const PhoneNumberInput = ({
9383
9388
  setBroadcastedValue(internalValue);
9384
9389
  }, [onChange, broadcastedValue, internalValue]);
9385
9390
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
9391
+ role: "group",
9392
+ ...inputAttributes,
9386
9393
  "aria-labelledby": ariaLabelledBy,
9387
9394
  className: "tw-telephone",
9388
9395
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
@@ -10115,6 +10122,7 @@ function Select({
10115
10122
  dropdownProps,
10116
10123
  buttonProps
10117
10124
  }) {
10125
+ const inputAttributes = useInputAttributes();
10118
10126
  const {
10119
10127
  formatMessage
10120
10128
  } = reactIntl.useIntl();
@@ -10134,7 +10142,6 @@ function Select({
10134
10142
  const optionsListReference = React.useRef(null);
10135
10143
  const isSearchEnabled = !!onSearchChange || !!search;
10136
10144
  const isDropdownAutoWidth = dropdownWidth == null;
10137
- const fallbackButtonId = React.useMemo(() => getSimpleRandomId('np-select-'), []);
10138
10145
  const options = React.useMemo(() => {
10139
10146
  if (!search || !searchValue) {
10140
10147
  return defaultOptions;
@@ -10142,14 +10149,14 @@ function Select({
10142
10149
  return defaultOptions.filter(isSearchableOption).filter(option => {
10143
10150
  if (typeof search === 'function') {
10144
10151
  return search(option, searchValue);
10145
- } else {
10146
- return defaultFilterFunction(option, searchValue);
10147
10152
  }
10153
+ return defaultFilterFunction(option, searchValue);
10148
10154
  });
10149
10155
  }, [defaultOptions, search, searchValue]);
10150
10156
  const selectableOptions = React.useMemo(() => options.filter(isActionableOption), [options]);
10151
10157
  const focusedOption = selectableOptions[keyboardFocusedOptionIndex];
10152
- const computedId = id || fallbackButtonId;
10158
+ const fallbackButtonId = reactId.useId();
10159
+ const computedId = id || inputAttributes.id || fallbackButtonId;
10153
10160
  const listboxId = `${computedId}-listbox`;
10154
10161
  const searchBoxId = `${computedId}-searchbox`;
10155
10162
  const {
@@ -10280,7 +10287,7 @@ function Select({
10280
10287
  React.useEffect(() => {
10281
10288
  if (open) {
10282
10289
  if (!isMobile || searchValue) {
10283
- if (isSearchEnabled && !!searchBoxReference.current) {
10290
+ if (isSearchEnabled && searchBoxReference.current) {
10284
10291
  searchBoxReference.current.focus();
10285
10292
  }
10286
10293
  if (!isSearchEnabled && optionsListReference.current && (previousKeyboardFocusedOptionIndex.current == null || Number.isNaN(previousKeyboardFocusedOptionIndex.current))) {
@@ -10466,6 +10473,7 @@ function Select({
10466
10473
  onBlur: handleOnBlur,
10467
10474
  children: [/*#__PURE__*/jsxRuntime.jsxs(Button, {
10468
10475
  ref: dropdownButtonReference,
10476
+ ...inputAttributes,
10469
10477
  id: computedId,
10470
10478
  block: block,
10471
10479
  size: size,
@@ -10541,9 +10549,6 @@ Select.propTypes = {
10541
10549
  * if `function` you can define your own search function to implement custom search experience. This search function used while filtering the options array. The custom search function takes two parameters. First is the option the second is the keyword.
10542
10550
  */
10543
10551
  search: PropTypes__default.default.oneOfType([PropTypes__default.default.bool, PropTypes__default.default.func]),
10544
- onChange: PropTypes__default.default.func.isRequired,
10545
- onFocus: PropTypes__default.default.func,
10546
- onBlur: PropTypes__default.default.func,
10547
10552
  options: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
10548
10553
  value: PropTypes__default.default.any,
10549
10554
  label: PropTypes__default.default.node,
@@ -10556,17 +10561,20 @@ Select.propTypes = {
10556
10561
  disabled: PropTypes__default.default.bool,
10557
10562
  searchStrings: PropTypes__default.default.arrayOf(PropTypes__default.default.string)
10558
10563
  })).isRequired,
10559
- /**
10560
- * To have full control of your search value and response use `onSearchChange` function combined with `searchValue` and custom filtering on the options array.
10561
- * DO NOT USE TOGETHER WITH `search` PROPERTY
10562
- */
10563
- onSearchChange: PropTypes__default.default.func,
10564
10564
  searchValue: PropTypes__default.default.string,
10565
10565
  searchPlaceholder: PropTypes__default.default.string,
10566
10566
  classNames: PropTypes__default.default.objectOf(PropTypes__default.default.string),
10567
10567
  dropdownUp: PropTypes__default.default.bool,
10568
10568
  buttonProps: PropTypes__default.default.object,
10569
- dropdownProps: PropTypes__default.default.object
10569
+ dropdownProps: PropTypes__default.default.object,
10570
+ onChange: PropTypes__default.default.func.isRequired,
10571
+ onFocus: PropTypes__default.default.func,
10572
+ onBlur: PropTypes__default.default.func,
10573
+ /**
10574
+ * To have full control of your search value and response use `onSearchChange` function combined with `searchValue` and custom filtering on the options array.
10575
+ * DO NOT USE TOGETHER WITH `search` PROPERTY
10576
+ */
10577
+ onSearchChange: PropTypes__default.default.func
10570
10578
  };
10571
10579
  Select.defaultProps = {
10572
10580
  id: undefined,
@@ -12162,7 +12170,8 @@ class Typeahead extends React.Component {
12162
12170
  };
12163
12171
  render() {
12164
12172
  const {
12165
- id,
12173
+ inputAttributes,
12174
+ id: idProp,
12166
12175
  placeholder,
12167
12176
  multiple,
12168
12177
  size,
@@ -12180,6 +12189,7 @@ class Typeahead extends React.Component {
12180
12189
  alert,
12181
12190
  inputAutoComplete
12182
12191
  } = this.props;
12192
+ const id = idProp ?? inputAttributes?.id;
12183
12193
  const {
12184
12194
  errorState,
12185
12195
  query,
@@ -12205,6 +12215,8 @@ class Typeahead extends React.Component {
12205
12215
  const hasWarning = displayAlert && alertType === exports.Sentiment.WARNING;
12206
12216
  const hasInfo = displayAlert && alertType === exports.Sentiment.NEUTRAL;
12207
12217
  return /*#__PURE__*/jsxRuntime.jsx("div", {
12218
+ role: "group",
12219
+ ...inputAttributes,
12208
12220
  id: id,
12209
12221
  className: classNames__default.default('typeahead', `typeahead-${size}`, {
12210
12222
  'typeahead--has-value': selected.length > 0,
@@ -12260,6 +12272,9 @@ class Typeahead extends React.Component {
12260
12272
  });
12261
12273
  }
12262
12274
  }
12275
+ var Typeahead$1 = withInputAttributes(Typeahead, {
12276
+ nonLabelable: true
12277
+ });
12263
12278
 
12264
12279
  // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12265
12280
  exports.UploadStep = void 0;
@@ -14882,7 +14897,7 @@ exports.TextArea = TextArea;
14882
14897
  exports.TextareaWithDisplayFormat = TextareaWithDisplayFormat;
14883
14898
  exports.Title = Title;
14884
14899
  exports.Tooltip = Tooltip;
14885
- exports.Typeahead = Typeahead;
14900
+ exports.Typeahead = Typeahead$1;
14886
14901
  exports.Upload = Upload$1;
14887
14902
  exports.UploadInput = UploadInput;
14888
14903
  exports.adjustLocale = adjustLocale;