Skip to content

A local-first personal finance app

Replace usage of deprecated Button in Autocomplete with new Button component (#4561)

Joel Jeremy Marquez4bc34776fbdd
diff --git a/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx b/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx
index c79698da2d..d0bae776c3 100644
--- a/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/Autocomplete.tsx
@@ -11,17 +11,17 @@ import React, {
useState,
} from 'react';
+import { Button } from '@actual-app/components/button';
+import { SvgRemove } from '@actual-app/components/icons/v2';
import { Popover } from '@actual-app/components/popover';
import { styles } from '@actual-app/components/styles';
+import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { css, cx } from '@emotion/css';
import Downshift, { type StateChangeTypes } from 'downshift';
import { getNormalisedString } from 'loot-core/shared/normalisation';
-import { SvgRemove } from '../../icons/v2';
-import { theme } from '../../style';
-import { Button } from '../common/Button';
import { Input } from '../common/Input';
import { useResponsive } from '../responsive/ResponsiveProvider';
@@ -255,6 +255,7 @@ function SingleAutocomplete<T extends Item>({
};
const triggerRef = useRef(null);
+ const itemsViewRef = useRef(null);
const { isNarrowWidth } = useResponsive();
const narrowInputStyle = isNarrowWidth
@@ -465,7 +466,15 @@ function SingleAutocomplete<T extends Item>({
e['preventDownshiftDefault'] = true;
inputProps.onBlur?.(e);
- if (!closeOnBlur) return;
+ if (!closeOnBlur) {
+ return;
+ }
+
+ if (itemsViewRef.current?.contains(e.relatedTarget)) {
+ // Do not close when the user clicks on any of the items.
+ e.stopPropagation();
+ return;
+ }
if (clearOnBlur) {
if (e.target.value === '') {
@@ -589,12 +598,14 @@ function SingleAutocomplete<T extends Item>({
}}
data-testid="autocomplete"
>
- {renderItems(
- filtered,
- getItemProps,
- highlightedIndex,
- inputValue,
- )}
+ <View ref={itemsViewRef}>
+ {renderItems(
+ filtered,
+ getItemProps,
+ highlightedIndex,
+ inputValue,
+ )}
+ </View>
</Popover>
))}
</div>
@@ -621,7 +632,7 @@ function MultiItem({ name, onRemove }: MultiItemProps) {
}}
>
{name}
- <Button type="bare" style={{ marginLeft: 1 }} onClick={onRemove}>
+ <Button variant="bare" style={{ marginLeft: 1 }} onPress={onRemove}>
<SvgRemove style={{ width: 8, height: 8 }} />
</Button>
</View>
@@ -755,7 +766,6 @@ export function AutocompleteFooter({
flexShrink: 0,
...(embedded ? { paddingTop: 5 } : { padding: 5 }),
}}
- onMouseDown={e => e.preventDefault()}
>
{children}
</View>
diff --git a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
index e5b623eaea..08004002d0 100644
--- a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
@@ -13,6 +13,7 @@ import React, {
} from 'react';
import { Trans, useTranslation } from 'react-i18next';
+import { Button } from '@actual-app/components/button';
import { styles } from '@actual-app/components/styles';
import { TextOneLine } from '@actual-app/components/text-one-line';
import { View } from '@actual-app/components/view';
@@ -30,7 +31,6 @@ import { useCommonPayees, usePayees } from '../../hooks/usePayees';
import { SvgAdd, SvgBookmark } from '../../icons/v1';
import { useDispatch } from '../../redux';
import { theme } from '../../style';
-import { Button } from '../common/Button';
import { useResponsive } from '../responsive/ResponsiveProvider';
import {
@@ -448,9 +448,9 @@ export function PayeeAutocomplete({
<AutocompleteFooter embedded={embedded}>
{showMakeTransfer && (
<Button
- type={focusTransferPayees ? 'menuSelected' : 'menu'}
+ variant={focusTransferPayees ? 'menuSelected' : 'menu'}
style={showManagePayees && { marginBottom: 5 }}
- onClick={() => {
+ onPress={() => {
onUpdate?.(null, null);
setFocusTransferPayees(!focusTransferPayees);
}}
@@ -459,7 +459,7 @@ export function PayeeAutocomplete({
</Button>
)}
{showManagePayees && (
- <Button type="menu" onClick={() => onManagePayees()}>
+ <Button variant="menu" onPress={() => onManagePayees()}>
<Trans>Manage payees</Trans>
</Button>
)}
diff --git a/upcoming-release-notes/4561.md b/upcoming-release-notes/4561.md
new file mode 100644
index 0000000000..89e554653b
--- /dev/null
+++ b/upcoming-release-notes/4561.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [joel-jeremy]
+---
+
+Replace usage of deprecated Button in Autocomplete with new Button component