@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.mjs CHANGED
@@ -136,10 +136,6 @@ function stopPropagation$1(event) {
136
136
  event.nativeEvent.stopImmediatePropagation();
137
137
  }
138
138
  }
139
- function getSimpleRandomId(prefix) {
140
- const random = Math.ceil(Math.random() * 999999);
141
- return `${prefix}${random}`;
142
- }
143
139
 
144
140
  /**
145
141
  * Defined in `Dimmer.less`
@@ -7430,9 +7426,8 @@ const formatAmountIfSet = ({
7430
7426
  }) => {
7431
7427
  if (maxLengthOverride) {
7432
7428
  return amount != null ? String(amount) : '';
7433
- } else {
7434
- return typeof amount === 'number' ? formatAmount(amount, currency, locale) : '';
7435
7429
  }
7430
+ return typeof amount === 'number' ? formatAmount(amount, currency, locale) : '';
7436
7431
  };
7437
7432
  const parseNumber = ({
7438
7433
  amount,
@@ -7490,7 +7485,7 @@ class MoneyInput extends Component {
7490
7485
  key,
7491
7486
  ctrlKey
7492
7487
  } = event;
7493
- const isNumberKey = isNumber(parseInt(key, 10));
7488
+ const isNumberKey = isNumber(Number.parseInt(key, 10));
7494
7489
  return isNumberKey || metaKey || ctrlKey || allowedInputKeys.has(key);
7495
7490
  };
7496
7491
  handleKeyDown = event => {
@@ -7506,7 +7501,7 @@ class MoneyInput extends Component {
7506
7501
  const parsed = isEmpty(paste) ? null : parseNumber({
7507
7502
  amount: paste,
7508
7503
  currency: this.props.selectedCurrency.currency,
7509
- locale: locale,
7504
+ locale,
7510
7505
  maxLengthOverride: this.props.maxLengthOverride
7511
7506
  });
7512
7507
  if (isNumberOrNull(parsed)) {
@@ -7514,7 +7509,7 @@ class MoneyInput extends Component {
7514
7509
  formattedAmount: formatAmountIfSet({
7515
7510
  amount: parsed,
7516
7511
  currency: this.props.selectedCurrency.currency,
7517
- locale: locale,
7512
+ locale,
7518
7513
  maxLengthOverride: this.props.maxLengthOverride
7519
7514
  })
7520
7515
  });
@@ -7611,15 +7606,17 @@ class MoneyInput extends Component {
7611
7606
  style = className => this.props.classNames[className] || className;
7612
7607
  render() {
7613
7608
  const {
7609
+ inputAttributes,
7610
+ id: amountInputId,
7611
+ 'aria-labelledby': ariaLabelledByProp,
7614
7612
  selectedCurrency,
7615
7613
  onCurrencyChange,
7616
7614
  size,
7617
7615
  addon,
7618
- id,
7619
- 'aria-labelledby': ariaLabelledBy,
7620
7616
  selectProps,
7621
7617
  maxLengthOverride
7622
7618
  } = this.props;
7619
+ const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes?.['aria-labelledby'];
7623
7620
  const selectOptions = this.getSelectOptions();
7624
7621
  const hasSingleCurrency = () => {
7625
7622
  if (selectOptions.length !== 0) {
@@ -7640,10 +7637,12 @@ class MoneyInput extends Component {
7640
7637
  const isFixedCurrency = !this.state.searchQuery && hasSingleCurrency() || !onCurrencyChange;
7641
7638
  const disabled = !this.props.onAmountChange;
7642
7639
  return /*#__PURE__*/jsxs("div", {
7640
+ role: "group",
7641
+ ...inputAttributes,
7643
7642
  "aria-labelledby": ariaLabelledBy,
7644
7643
  className: classNames(this.style('tw-money-input'), this.style('input-group'), this.style(`input-group-${size}`)),
7645
7644
  children: [/*#__PURE__*/jsx(Input, {
7646
- id: id,
7645
+ id: amountInputId,
7647
7646
  value: this.state.formattedAmount,
7648
7647
  inputMode: "decimal",
7649
7648
  disabled: disabled,
@@ -7744,7 +7743,7 @@ function currencyOptionFitsQuery(option, query) {
7744
7743
  return contains(option.label, query) || contains(option.searchable, query) || contains(option.note, query);
7745
7744
  }
7746
7745
  function contains(property, query) {
7747
- return property && property.toLowerCase().includes(query.toLowerCase());
7746
+ return property?.toLowerCase().includes(query.toLowerCase());
7748
7747
  }
7749
7748
  function sortOptionsLabelsToFirst(options, query) {
7750
7749
  return [...options].sort((first, second) => {
@@ -7762,7 +7761,9 @@ function sortOptionsLabelsToFirst(options, query) {
7762
7761
  return 0;
7763
7762
  });
7764
7763
  }
7765
- var MoneyInput$1 = injectIntl(MoneyInput);
7764
+ var MoneyInput$1 = injectIntl(withInputAttributes(MoneyInput, {
7765
+ nonLabelable: true
7766
+ }));
7766
7767
 
7767
7768
  const NavigationOptionList = ({
7768
7769
  children
@@ -9283,7 +9284,7 @@ const defaultSelectProps = {};
9283
9284
  const defaultDisabledCountries = [];
9284
9285
  const PhoneNumberInput = ({
9285
9286
  id,
9286
- 'aria-labelledby': ariaLabelledBy,
9287
+ 'aria-labelledby': ariaLabelledByProp,
9287
9288
  required,
9288
9289
  disabled,
9289
9290
  initialValue,
@@ -9297,6 +9298,10 @@ const PhoneNumberInput = ({
9297
9298
  selectProps = defaultSelectProps,
9298
9299
  disabledCountries = defaultDisabledCountries
9299
9300
  }) => {
9301
+ const inputAttributes = useInputAttributes({
9302
+ nonLabelable: true
9303
+ });
9304
+ const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes['aria-labelledby'];
9300
9305
  const {
9301
9306
  locale,
9302
9307
  formatMessage
@@ -9353,6 +9358,8 @@ const PhoneNumberInput = ({
9353
9358
  setBroadcastedValue(internalValue);
9354
9359
  }, [onChange, broadcastedValue, internalValue]);
9355
9360
  return /*#__PURE__*/jsxs("div", {
9361
+ role: "group",
9362
+ ...inputAttributes,
9356
9363
  "aria-labelledby": ariaLabelledBy,
9357
9364
  className: "tw-telephone",
9358
9365
  children: [/*#__PURE__*/jsx("div", {
@@ -10085,6 +10092,7 @@ function Select({
10085
10092
  dropdownProps,
10086
10093
  buttonProps
10087
10094
  }) {
10095
+ const inputAttributes = useInputAttributes();
10088
10096
  const {
10089
10097
  formatMessage
10090
10098
  } = useIntl();
@@ -10104,7 +10112,6 @@ function Select({
10104
10112
  const optionsListReference = useRef(null);
10105
10113
  const isSearchEnabled = !!onSearchChange || !!search;
10106
10114
  const isDropdownAutoWidth = dropdownWidth == null;
10107
- const fallbackButtonId = useMemo(() => getSimpleRandomId('np-select-'), []);
10108
10115
  const options = useMemo(() => {
10109
10116
  if (!search || !searchValue) {
10110
10117
  return defaultOptions;
@@ -10112,14 +10119,14 @@ function Select({
10112
10119
  return defaultOptions.filter(isSearchableOption).filter(option => {
10113
10120
  if (typeof search === 'function') {
10114
10121
  return search(option, searchValue);
10115
- } else {
10116
- return defaultFilterFunction(option, searchValue);
10117
10122
  }
10123
+ return defaultFilterFunction(option, searchValue);
10118
10124
  });
10119
10125
  }, [defaultOptions, search, searchValue]);
10120
10126
  const selectableOptions = useMemo(() => options.filter(isActionableOption), [options]);
10121
10127
  const focusedOption = selectableOptions[keyboardFocusedOptionIndex];
10122
- const computedId = id || fallbackButtonId;
10128
+ const fallbackButtonId = useId();
10129
+ const computedId = id || inputAttributes.id || fallbackButtonId;
10123
10130
  const listboxId = `${computedId}-listbox`;
10124
10131
  const searchBoxId = `${computedId}-searchbox`;
10125
10132
  const {
@@ -10250,7 +10257,7 @@ function Select({
10250
10257
  useEffect(() => {
10251
10258
  if (open) {
10252
10259
  if (!isMobile || searchValue) {
10253
- if (isSearchEnabled && !!searchBoxReference.current) {
10260
+ if (isSearchEnabled && searchBoxReference.current) {
10254
10261
  searchBoxReference.current.focus();
10255
10262
  }
10256
10263
  if (!isSearchEnabled && optionsListReference.current && (previousKeyboardFocusedOptionIndex.current == null || Number.isNaN(previousKeyboardFocusedOptionIndex.current))) {
@@ -10436,6 +10443,7 @@ function Select({
10436
10443
  onBlur: handleOnBlur,
10437
10444
  children: [/*#__PURE__*/jsxs(Button, {
10438
10445
  ref: dropdownButtonReference,
10446
+ ...inputAttributes,
10439
10447
  id: computedId,
10440
10448
  block: block,
10441
10449
  size: size,
@@ -10511,9 +10519,6 @@ Select.propTypes = {
10511
10519
  * 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.
10512
10520
  */
10513
10521
  search: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
10514
- onChange: PropTypes.func.isRequired,
10515
- onFocus: PropTypes.func,
10516
- onBlur: PropTypes.func,
10517
10522
  options: PropTypes.arrayOf(PropTypes.shape({
10518
10523
  value: PropTypes.any,
10519
10524
  label: PropTypes.node,
@@ -10526,17 +10531,20 @@ Select.propTypes = {
10526
10531
  disabled: PropTypes.bool,
10527
10532
  searchStrings: PropTypes.arrayOf(PropTypes.string)
10528
10533
  })).isRequired,
10529
- /**
10530
- * To have full control of your search value and response use `onSearchChange` function combined with `searchValue` and custom filtering on the options array.
10531
- * DO NOT USE TOGETHER WITH `search` PROPERTY
10532
- */
10533
- onSearchChange: PropTypes.func,
10534
10534
  searchValue: PropTypes.string,
10535
10535
  searchPlaceholder: PropTypes.string,
10536
10536
  classNames: PropTypes.objectOf(PropTypes.string),
10537
10537
  dropdownUp: PropTypes.bool,
10538
10538
  buttonProps: PropTypes.object,
10539
- dropdownProps: PropTypes.object
10539
+ dropdownProps: PropTypes.object,
10540
+ onChange: PropTypes.func.isRequired,
10541
+ onFocus: PropTypes.func,
10542
+ onBlur: PropTypes.func,
10543
+ /**
10544
+ * To have full control of your search value and response use `onSearchChange` function combined with `searchValue` and custom filtering on the options array.
10545
+ * DO NOT USE TOGETHER WITH `search` PROPERTY
10546
+ */
10547
+ onSearchChange: PropTypes.func
10540
10548
  };
10541
10549
  Select.defaultProps = {
10542
10550
  id: undefined,
@@ -12132,7 +12140,8 @@ class Typeahead extends Component {
12132
12140
  };
12133
12141
  render() {
12134
12142
  const {
12135
- id,
12143
+ inputAttributes,
12144
+ id: idProp,
12136
12145
  placeholder,
12137
12146
  multiple,
12138
12147
  size,
@@ -12150,6 +12159,7 @@ class Typeahead extends Component {
12150
12159
  alert,
12151
12160
  inputAutoComplete
12152
12161
  } = this.props;
12162
+ const id = idProp ?? inputAttributes?.id;
12153
12163
  const {
12154
12164
  errorState,
12155
12165
  query,
@@ -12175,6 +12185,8 @@ class Typeahead extends Component {
12175
12185
  const hasWarning = displayAlert && alertType === Sentiment.WARNING;
12176
12186
  const hasInfo = displayAlert && alertType === Sentiment.NEUTRAL;
12177
12187
  return /*#__PURE__*/jsx("div", {
12188
+ role: "group",
12189
+ ...inputAttributes,
12178
12190
  id: id,
12179
12191
  className: classNames('typeahead', `typeahead-${size}`, {
12180
12192
  'typeahead--has-value': selected.length > 0,
@@ -12230,6 +12242,9 @@ class Typeahead extends Component {
12230
12242
  });
12231
12243
  }
12232
12244
  }
12245
+ var Typeahead$1 = withInputAttributes(Typeahead, {
12246
+ nonLabelable: true
12247
+ });
12233
12248
 
12234
12249
  // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12235
12250
  var UploadStep;
@@ -14758,5 +14773,5 @@ const translations = {
14758
14773
  'zh-HK': zhHK
14759
14774
  };
14760
14775
 
14761
- export { Accordion, ActionButton, ActionOption, Alert, AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card$2 as BaseCard, Body, BottomSheet$1 as BottomSheet, Breakpoint, Button, Card$1 as Card, Carousel, Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput, DateLookup$1 as DateLookup, DateMode, Decision, DecisionPresentation, DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, Emphasis, Field, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList, Label, LanguageProvider, Layout, Link, ListItem$1 as ListItem, Loader, Logo$1 as Logo, LogoType, Markdown, MarkdownNodeType, Modal, Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput, Popover$1 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCardGroup$1 as PromoCardGroup, Provider, RTL_LANGUAGES, Radio, RadioGroup, RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, SegmentedControl, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider, Status, StatusIcon, Stepper, Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip, Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
14776
+ export { Accordion, ActionButton, ActionOption, Alert, AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card$2 as BaseCard, Body, BottomSheet$1 as BottomSheet, Breakpoint, Button, Card$1 as Card, Carousel, Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron, Chip, Chips, CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput, DateLookup$1 as DateLookup, DateMode, Decision, DecisionPresentation, DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, Emphasis, Field, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat, InstructionsList, Label, LanguageProvider, Layout, Link, ListItem$1 as ListItem, Loader, Logo$1 as Logo, LogoType, Markdown, MarkdownNodeType, Modal, Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput, Popover$1 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCardGroup$1 as PromoCardGroup, Provider, RTL_LANGUAGES, Radio, RadioGroup, RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, SegmentedControl, Select, SelectInput, SelectInputOptionContent, SelectInputTriggerButton, Sentiment, Size, SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider, Status, StatusIcon, Stepper, Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat, Theme, Title, Tooltip, Type, Typeahead$1 as Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useScreenSize, useSnackbar };
14762
14777
  //# sourceMappingURL=index.mjs.map