@transferwise/components 0.0.0-experimental-fbd2ec1 → 0.0.0-experimental-e1f66d5

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 (30) hide show
  1. package/build/moneyInput/MoneyInput.js +1 -0
  2. package/build/moneyInput/MoneyInput.js.map +1 -1
  3. package/build/moneyInput/MoneyInput.mjs +1 -0
  4. package/build/moneyInput/MoneyInput.mjs.map +1 -1
  5. package/build/typeahead/Typeahead.js +8 -22
  6. package/build/typeahead/Typeahead.js.map +1 -1
  7. package/build/typeahead/Typeahead.mjs +9 -22
  8. package/build/typeahead/Typeahead.mjs.map +1 -1
  9. package/build/typeahead/typeaheadInput/TypeaheadInput.js +2 -5
  10. package/build/typeahead/typeaheadInput/TypeaheadInput.js.map +1 -1
  11. package/build/typeahead/typeaheadInput/TypeaheadInput.mjs +2 -5
  12. package/build/typeahead/typeaheadInput/TypeaheadInput.mjs.map +1 -1
  13. package/build/typeahead/typeaheadOption/TypeaheadOption.js +6 -9
  14. package/build/typeahead/typeaheadOption/TypeaheadOption.js.map +1 -1
  15. package/build/typeahead/typeaheadOption/TypeaheadOption.mjs +6 -9
  16. package/build/typeahead/typeaheadOption/TypeaheadOption.mjs.map +1 -1
  17. package/build/types/moneyInput/MoneyInput.d.ts.map +1 -1
  18. package/build/types/typeahead/Typeahead.d.ts +1 -1
  19. package/build/types/typeahead/Typeahead.d.ts.map +1 -1
  20. package/build/types/typeahead/typeaheadInput/TypeaheadInput.d.ts +0 -2
  21. package/build/types/typeahead/typeaheadInput/TypeaheadInput.d.ts.map +1 -1
  22. package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts +1 -2
  23. package/build/types/typeahead/typeaheadOption/TypeaheadOption.d.ts.map +1 -1
  24. package/package.json +3 -3
  25. package/src/moneyInput/MoneyInput.tsx +1 -0
  26. package/src/typeahead/Typeahead.spec.js +0 -8
  27. package/src/typeahead/Typeahead.tsx +13 -29
  28. package/src/typeahead/typeaheadInput/TypeaheadInput.tsx +0 -9
  29. package/src/typeahead/typeaheadOption/TypeaheadOption.spec.js +0 -8
  30. package/src/typeahead/typeaheadOption/TypeaheadOption.tsx +6 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transferwise/components",
3
- "version": "0.0.0-experimental-fbd2ec1",
3
+ "version": "0.0.0-experimental-e1f66d5",
4
4
  "description": "Neptune React components",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -93,12 +93,12 @@
93
93
  "rollup-preserve-directives": "^1.1.1",
94
94
  "storybook": "^8.2.2",
95
95
  "@transferwise/less-config": "3.1.0",
96
- "@transferwise/neptune-css": "0.0.0-experimental-fbd2ec1",
96
+ "@transferwise/neptune-css": "14.16.0",
97
97
  "@wise/components-theming": "1.6.0"
98
98
  },
99
99
  "peerDependencies": {
100
100
  "@transferwise/icons": "^3.7.0",
101
- "@transferwise/neptune-css": "0.0.0-experimental-fbd2ec1",
101
+ "@transferwise/neptune-css": "^14.9.6",
102
102
  "@wise/art": "^2.7.0",
103
103
  "@wise/components-theming": "^1.0.0",
104
104
  "react": ">=18",
@@ -381,6 +381,7 @@ class MoneyInput extends Component<MoneyInputPropsWithInputAttributes, MoneyInpu
381
381
  </div>
382
382
  ) : (
383
383
  <div
384
+ translate="no"
384
385
  className={clsx(
385
386
  this.style('input-group-btn'),
386
387
  this.style('amount-currency-select-btn'),
@@ -258,14 +258,6 @@ describe('Typeahead', () => {
258
258
  expect(event.preventDefault).toHaveBeenCalledTimes(1);
259
259
  });
260
260
 
261
- it('sets aria-activedescendant correctly based on focus', () => {
262
- const inputElement = input().getDOMNode();
263
-
264
- doTimes(3, () => input().simulate('keyDown', fakeKeyDownEventForKey('ArrowDown')));
265
-
266
- expect(inputElement).toHaveAttribute('aria-activedescendant', 'menu-test option-Test2');
267
- });
268
-
269
261
  it('displays alert when alert is provided and chips are valid or alert type is error', () => {
270
262
  const event = {
271
263
  key: 'Enter',
@@ -3,7 +3,7 @@ import { clsx } from 'clsx';
3
3
  import { DebouncedFunc } from 'lodash';
4
4
  import clamp from 'lodash.clamp';
5
5
  import debounce from 'lodash.debounce';
6
- import React, { Component, ReactNode } from 'react';
6
+ import { Component, ReactNode } from 'react';
7
7
  import { injectIntl, WrappedComponentProps } from 'react-intl';
8
8
 
9
9
  import Chip from '../chips/Chip';
@@ -101,7 +101,6 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
101
101
  size: Size.MEDIUM,
102
102
  validateChip: () => true,
103
103
  } satisfies Partial<TypeaheadProps<unknown>>;
104
- optionRefs: (React.RefObject<HTMLLIElement> | null)[];
105
104
 
106
105
  constructor(props: TypeaheadPropsWithInputAttributes<T>) {
107
106
  super(props);
@@ -116,7 +115,6 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
116
115
  optionsShown: false,
117
116
  isFocused: false,
118
117
  };
119
- this.optionRefs = [] as (React.RefObject<HTMLLIElement> | null)[];
120
118
  }
121
119
 
122
120
  handleSearchDebounced: DebouncedFunc<Typeahead<T>['handleSearch']>;
@@ -230,6 +228,7 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
230
228
  }
231
229
  }
232
230
  };
231
+
233
232
  moveFocusedOption(offset: number) {
234
233
  this.setState((previousState) => {
235
234
  const { keyboardFocusedOptionIndex } = previousState;
@@ -238,10 +237,6 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
238
237
  if (keyboardFocusedOptionIndex !== null) {
239
238
  index = clamp(keyboardFocusedOptionIndex + offset, 0, options.length - 1);
240
239
  }
241
- const optionRef = this.optionRefs[index];
242
- if (optionRef?.current) {
243
- optionRef.current.focus(); // Set focus on the option element
244
- }
245
240
  return {
246
241
  keyboardFocusedOptionIndex: index,
247
242
  };
@@ -407,23 +402,17 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
407
402
  id={`menu-${id}`}
408
403
  >
409
404
  <ul className="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
410
- {optionsToRender.map((option, idx) => {
411
- const ref = React.createRef<HTMLLIElement>();
412
- this.optionRefs[idx] = ref;
413
- return (
414
- <TypeaheadOption
415
- key={`${option.label}${idx.toString()}`}
416
- ref={ref}
417
- query={query}
418
- option={option}
419
- selected={keyboardFocusedOptionIndex === idx}
420
- id={String(option.label.replace(/\s+/g, '-'))}
421
- onClick={(event) => {
422
- this.onOptionSelected(event, option);
423
- }}
424
- />
425
- );
426
- })}
405
+ {optionsToRender.map((option, idx) => (
406
+ <TypeaheadOption
407
+ key={`${option.label}${idx.toString()}`}
408
+ query={query}
409
+ option={option}
410
+ selected={keyboardFocusedOptionIndex === idx}
411
+ onClick={(event) => {
412
+ this.onOptionSelected(event, option);
413
+ }}
414
+ />
415
+ ))}
427
416
  {footer}
428
417
  </ul>
429
418
  </div>
@@ -518,11 +507,6 @@ class Typeahead<T> extends Component<TypeaheadPropsWithInputAttributes<T>, Typea
518
507
  typeaheadId={id}
519
508
  renderChip={this.renderChip}
520
509
  autoComplete={inputAutoComplete}
521
- ariaActivedescendant={
522
- keyboardFocusedOptionIndex !== null && options[keyboardFocusedOptionIndex]
523
- ? `option-${options[keyboardFocusedOptionIndex].label.replace(/\s+/g, '-')}`
524
- : undefined
525
- }
526
510
  onChange={this.handleOnChange}
527
511
  onKeyDown={this.handleOnKeyDown}
528
512
  onFocus={this.handleOnFocus}
@@ -20,12 +20,10 @@ export type TypeaheadInputProps<T> = {
20
20
  onFocus: () => void;
21
21
  onPaste: React.ClipboardEventHandler<HTMLInputElement>;
22
22
  renderChip: (chip: TypeaheadOption<T>, index: number) => ReactNode;
23
- ariaActivedescendant?: string;
24
23
  } & Pick<TypeaheadProps<T>, 'id' | 'name' | 'autoFocus' | 'multiple' | 'placeholder' | 'maxHeight'>;
25
24
 
26
25
  type TypeaheadInputState = {
27
26
  inputWidth: number;
28
- keyboardFocusedOptionIndex: number | null;
29
27
  };
30
28
 
31
29
  export default class TypeaheadInput<T> extends Component<
@@ -39,7 +37,6 @@ export default class TypeaheadInput<T> extends Component<
39
37
  super(props);
40
38
  this.state = {
41
39
  inputWidth: DEFAULT_INPUT_MIN_WIDTH,
42
- keyboardFocusedOptionIndex: null,
43
40
  };
44
41
  }
45
42
 
@@ -79,7 +76,6 @@ export default class TypeaheadInput<T> extends Component<
79
76
  onFocus,
80
77
  onPaste,
81
78
  autoComplete,
82
- ariaActivedescendant, // Declare the ariaActivedescendant variable
83
79
  } = this.props;
84
80
  const { inputWidth } = this.state;
85
81
 
@@ -90,11 +86,6 @@ export default class TypeaheadInput<T> extends Component<
90
86
  className={clsx(multiple && 'typeahead__input')}
91
87
  name={name}
92
88
  id={`input-${typeaheadId}`}
93
- aria-activedescendant={
94
- ariaActivedescendant
95
- ? `menu-${typeaheadId} ${ariaActivedescendant}`
96
- : `menu-${typeaheadId}`
97
- }
98
89
  autoFocus={autoFocus}
99
90
  placeholder={hasPlaceholder ? placeholder : ''}
100
91
  aria-autocomplete="list"
@@ -51,14 +51,6 @@ describe('Typeahead Option', () => {
51
51
  expect(component.is('.tw-dropdown-item--focused')).toBe(true);
52
52
  });
53
53
 
54
- it('expect aria-selected to be true', () => {
55
- component.setProps({
56
- selected: true,
57
- });
58
-
59
- expect(component.prop('aria-selected')).toBe('true');
60
- });
61
-
62
54
  it('calls onClick when clicked', () => {
63
55
  const onClick = jest.fn();
64
56
  component.setProps({
@@ -1,5 +1,5 @@
1
+ /* eslint-disable jsx-a11y/anchor-is-valid */
1
2
  import { clsx } from 'clsx';
2
- import { forwardRef } from 'react';
3
3
 
4
4
  import { TypeaheadOption } from '../Typeahead';
5
5
  import highlight from '../util/highlight';
@@ -9,24 +9,21 @@ export type TypeaheadOptionProps<T> = {
9
9
  selected?: boolean;
10
10
  onClick?: React.MouseEventHandler;
11
11
  query?: string;
12
- id?: string;
13
12
  };
14
13
 
15
- const Option = forwardRef<HTMLLIElement, TypeaheadOptionProps<any>>((props, ref) => {
16
- const { option, selected = false, onClick = () => {}, query = '', id } = props;
14
+ const Option = <T,>(props: TypeaheadOptionProps<T>) => {
15
+ const { option, selected = false, onClick = () => {}, query = '' } = props;
17
16
  const { label, note, secondary } = option;
18
17
 
19
18
  return (
20
19
  <li
21
- ref={ref}
22
20
  role="option"
23
- aria-selected={selected ? 'true' : 'false'}
24
- id={`option-${id}`}
21
+ aria-selected="false"
25
22
  className={clsx('typeahead__option tw-dropdown-item clickable', {
26
23
  'tw-dropdown-item--focused': selected,
27
24
  })}
28
25
  >
29
- <a className="dropdown-item" href="#" tabIndex={0} onClick={onClick}>
26
+ <a className="dropdown-item" href="#" tabIndex={-1} onClick={onClick}>
30
27
  <span>{highlight(label, query)}</span>
31
28
  {note && <span className="np-text-body-default m-l-1">{note}</span>}
32
29
  {secondary && (
@@ -35,6 +32,6 @@ const Option = forwardRef<HTMLLIElement, TypeaheadOptionProps<any>>((props, ref)
35
32
  </a>
36
33
  </li>
37
34
  );
38
- });
35
+ };
39
36
 
40
37
  export default Option;