@transferwise/components 0.0.0-experimental-f569557 → 0.0.0-experimental-dd4f4a5

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.
@@ -741,35 +741,15 @@ function SelectInputOptions<T = string>({
741
741
  return items;
742
742
  }
743
743
 
744
- const dedupedItems = dedupeSelectInputItems(items, compareValues);
744
+ const filtered = filterSelectInputItems(dedupeSelectInputItems(items, compareValues), (item) =>
745
+ selectInputOptionItemIncludesNeedle(item, needle),
746
+ );
745
747
 
746
748
  if (sortFilteredOptions) {
747
- // When sorting, filter out non-matching items completely to avoid ghost items
748
- const filtered = dedupedItems.map((item) => {
749
- if (item.type === 'option') {
750
- return selectInputOptionItemIncludesNeedle(item, needle)
751
- ? item
752
- : { ...item, value: undefined };
753
- }
754
- if (item.type === 'group') {
755
- return {
756
- ...item,
757
- options: item.options.map((option) =>
758
- selectInputOptionItemIncludesNeedle(option, needle)
759
- ? option
760
- : { ...option, value: undefined },
761
- ),
762
- };
763
- }
764
- return item;
765
- });
766
-
767
749
  return sortSelectInputItems(filtered, sortFilteredOptions, filterQuery);
768
750
  }
769
751
 
770
- return filterSelectInputItems(dedupedItems, (item) =>
771
- selectInputOptionItemIncludesNeedle(item, needle),
772
- );
752
+ return filtered;
773
753
  // eslint-disable-next-line react-hooks/exhaustive-deps
774
754
  }, [needle, items, compareValues]);
775
755
  const resultsEmpty = needle != null && filteredItems.length === 0;
@@ -780,28 +760,17 @@ function SelectInputOptions<T = string>({
780
760
  // the scroll position may jump around inadvertently. Pattern adopted from:
781
761
  // https://inokawa.github.io/virtua/?path=/story/advanced-keep-offscreen-items--append-only
782
762
  const [mountedIndexes, setMountedIndexes] = useState<number[]>([]);
783
- const prevNeedleRef = useRef(needle);
784
-
785
763
  useEffect(() => {
786
- const needleChanged = prevNeedleRef.current !== needle;
787
- prevNeedleRef.current = needle;
788
-
789
- if (needleChanged) {
790
- // Reset mounted indexes when search changes to avoid stale scroll positions
791
- setMountedIndexes([]);
792
- return;
793
- }
794
-
795
- // Ensure the 'End' key works as intended by keeping the last item mounted.
796
- // Skipped on needle change to prevent auto-scrolling on search.
797
- if (filteredItems.length > 0) {
798
- setMountedIndexes((prevMountedIndexes) => {
799
- const indexes = new Set(prevMountedIndexes);
800
- indexes.add(filteredItems.length - 1);
801
- return [...indexes]; // Sorting is redundant by nature here
802
- });
803
- }
804
- }, [needle, filteredItems.length]);
764
+ // Ensure the 'End' key works as intended by keeping the last item mounted
765
+ setMountedIndexes((prevMountedIndexes) => {
766
+ const indexes = new Set(prevMountedIndexes);
767
+ indexes.add(filteredItems.length - 1);
768
+ return [...indexes]; // Sorting is redundant by nature here
769
+ });
770
+ }, [
771
+ needle, // Needed as `filteredItems.length` may be equal between two updates
772
+ filteredItems.length,
773
+ ]);
805
774
 
806
775
  const listboxContainerRef = useRef<HTMLDivElement>(null);
807
776
  useEffect(() => {
@@ -958,6 +927,7 @@ function SelectInputOptions<T = string>({
958
927
  ) : (
959
928
  <Virtualizer
960
929
  ref={virtualiserHandlerRef}
930
+ key={needle}
961
931
  data={filteredItems}
962
932
  keepMounted={mountedIndexes}
963
933
  scrollRef={listboxRef} // `VList` doesn't expose this
@@ -55,7 +55,7 @@ export const ActionPrompt = ({
55
55
 
56
56
  const ariaLabelledByIds = [
57
57
  media['aria-hidden'] ? undefined : mediaId,
58
- ariaLabel ? undefined : titleId,
58
+ Boolean(ariaLabel) ? undefined : titleId,
59
59
  ]
60
60
  .filter(Boolean)
61
61
  .join(' ');
@@ -104,7 +104,7 @@ export const ActionPrompt = ({
104
104
  id={mediaId}
105
105
  size={48}
106
106
  sentiment={sentiment}
107
- iconLabel={media['aria-hidden'] ? null : media['aria-label']}
107
+ iconLabel={Boolean(media['aria-hidden']) ? null : media['aria-label']}
108
108
  />
109
109
  );
110
110
  };
@@ -148,9 +148,9 @@ export const ActionPrompt = ({
148
148
  </Button>
149
149
  </>
150
150
  }
151
- role="region"
152
151
  onDismiss={onDismiss}
153
- {...(ariaLabel
152
+ role="region"
153
+ {...(Boolean(ariaLabel)
154
154
  ? { 'aria-label': ariaLabel }
155
155
  : {
156
156
  'aria-labelledby': ariaLabelledByIds,
@@ -1,7 +1,7 @@
1
1
  import { Meta, Source, Canvas } from '@storybook/addon-docs/blocks';
2
2
  import * as stories from './SentimentSurface.story';
3
3
 
4
- <Meta title="Content/SentimentSurface/Developer Guide" />
4
+ <Meta title="Foundations/SentimentSurface/Developer Guide" />
5
5
 
6
6
  # Developer Guide
7
7
 
@@ -31,7 +31,7 @@ const withComponentGrid = (Story: () => JSX.Element) => (
31
31
  */
32
32
  const meta: Meta<typeof SentimentSurface> = {
33
33
  component: SentimentSurface,
34
- title: 'Content/SentimentSurface',
34
+ title: 'Foundations/SentimentSurface',
35
35
  argTypes: {
36
36
  sentiment: {
37
37
  control: 'select',
@@ -21,7 +21,7 @@ const screenModes: Theming['screenMode'][] = ['light', 'dark'];
21
21
 
22
22
  export default {
23
23
  component: SentimentSurface,
24
- title: 'Content/SentimentSurface/Tests',
24
+ title: 'Foundations/SentimentSurface/Tests',
25
25
  tags: ['!autodocs', '!manifest'],
26
26
  } satisfies Meta<typeof SentimentSurface>;
27
27