Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocomplete components on mobile #1673

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class MobileTransactionEntryPage {

async fillField(fieldLocator, content) {
await fieldLocator.click();
await this.page.locator('css=[role=combobox] input').fill(content);
await fieldLocator.fill(content);
await this.page.keyboard.press('Enter');
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';

import { css } from 'glamor';

Expand All @@ -14,6 +14,8 @@ function AccountList({
getItemProps,
highlightedIndex,
embedded,
style,
itemStyle,
groupHeaderStyle,
}) {
let lastItem = null;
Expand All @@ -25,6 +27,7 @@ function AccountList({
overflow: 'auto',
padding: '5px 0',
...(!embedded && { maxHeight: 175 }),
...style,
}}
>
{items.map((item, idx) => {
Expand Down Expand Up @@ -93,6 +96,7 @@ function AccountList({
paddingLeft: 20,
borderRadius: embedded ? 4 : 0,
},
itemStyle,
])}`}
data-testid={
'account-item' +
Expand All @@ -109,17 +113,21 @@ function AccountList({
}

export default function AccountAutocomplete({
accounts,
embedded,
includeClosedAccounts = true,
accountListStyle,
accountListItemStyle,
groupHeaderStyle,
closeOnBlur,
inputProps,
...props
}) {
let accounts = useCachedAccounts() || [];
const cachedAccounts = useCachedAccounts() || [];

//remove closed accounts if needed
//then sort by closed, then offbudget
accounts = accounts
accounts = (accounts || cachedAccounts)
.filter(item => {
return includeClosedAccounts ? item : !item.closed;
})
Expand All @@ -131,19 +139,35 @@ export default function AccountAutocomplete({
}
});

const [accountFieldFocused, setAccountFieldFocused] = useState(false);

return (
<Autocomplete
strict={true}
highlightFirst={true}
embedded={embedded}
closeOnBlur={closeOnBlur}
suggestions={accounts}
inputProps={{
...inputProps,
onBlur: e => {
setAccountFieldFocused(false);
inputProps?.onBlur?.(e);
},
onFocus: e => {
setAccountFieldFocused(true);
inputProps?.onFocus?.(e);
},
}}
focused={accountFieldFocused}
renderItems={(items, getItemProps, highlightedIndex) => (
<AccountList
items={items}
getItemProps={getItemProps}
highlightedIndex={highlightedIndex}
embedded={embedded}
style={accountListStyle}
itemStyle={accountListItemStyle}
groupHeaderStyle={groupHeaderStyle}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import React, {
Fragment,
useMemo,
type ReactNode,
useState,
} from 'react';

import { css } from 'glamor';

import Split from '../../icons/v0/Split';
import { theme } from '../../style';
import { type CSSProperties, theme } from '../../style';
import Text from '../common/Text';
import View from '../common/View';

Expand All @@ -33,15 +34,21 @@ export type CategoryListProps = {
highlightedIndex: number;
embedded: boolean;
footer?: ReactNode;
groupHeaderStyle?: object;
style?: CSSProperties;
groupHeaderStyle?: CSSProperties;
itemStyle?: CSSProperties;
splitButtonStyle?: CSSProperties;
};
function CategoryList({
items,
getItemProps,
highlightedIndex,
embedded,
footer,
style,
groupHeaderStyle,
itemStyle,
splitButtonStyle,
}: CategoryListProps) {
let lastGroup = null;

Expand All @@ -52,6 +59,7 @@ function CategoryList({
overflow: 'auto',
padding: '5px 0',
...(!embedded && { maxHeight: 175 }),
...style,
}}
>
{items.map((item, idx) => {
Expand Down Expand Up @@ -98,6 +106,7 @@ function CategoryList({
':active': {
backgroundColor: 'rgba(100, 100, 100, .25)',
},
...splitButtonStyle,
}}
data-testid="split-transaction-button"
>
Expand Down Expand Up @@ -139,6 +148,7 @@ function CategoryList({
paddingLeft: 20,
borderRadius: embedded ? 4 : 0,
},
itemStyle,
])}`}
data-testid={
'category-item' +
Expand All @@ -159,14 +169,21 @@ function CategoryList({
type CategoryAutocompleteProps = ComponentProps<typeof Autocomplete> & {
categoryGroups: CategoryGroup[];
showSplitOption?: boolean;
groupHeaderStyle?: object;
categoryListStyle?: CSSProperties;
categoryListItemStyle?: CSSProperties;
groupHeaderStyle?: CSSProperties;
splitButtonStyle?: CSSProperties;
};
export default function CategoryAutocomplete({
categoryGroups,
showSplitOption,
embedded,
closeOnBlur,
inputProps,
categoryListStyle,
groupHeaderStyle,
categoryListItemStyle,
splitButtonStyle,
...props
}: CategoryAutocompleteProps) {
let categorySuggestions = useMemo(
Expand All @@ -184,6 +201,8 @@ export default function CategoryAutocomplete({
[categoryGroups],
);

const [categoryFieldFocused, setCategoryFieldFocused] = useState(false);

return (
<Autocomplete
strict={true}
Expand All @@ -207,14 +226,29 @@ export default function CategoryAutocomplete({
);
});
}}
inputProps={{
...inputProps,
onFocus: e => {
setCategoryFieldFocused(true);
inputProps?.onFocus?.(e);
},
onBlur: e => {
setCategoryFieldFocused(false);
inputProps?.onBlur?.(e);
},
}}
focused={categoryFieldFocused}
suggestions={categorySuggestions}
renderItems={(items, getItemProps, highlightedIndex) => (
<CategoryList
items={items}
embedded={embedded}
getItemProps={getItemProps}
highlightedIndex={highlightedIndex}
style={categoryListStyle}
groupHeaderStyle={groupHeaderStyle}
itemStyle={categoryListItemStyle}
splitButtonStyle={splitButtonStyle}
/>
)}
{...props}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ function PayeeList({
highlightedIndex,
embedded,
inputValue,
style,
itemStyle,
groupHeaderStyle,
createPayeeButtonStyle,
footer,
}) {
const { isNarrowWidth } = useResponsive();
Expand All @@ -78,6 +81,7 @@ function PayeeList({
overflow: 'auto',
padding: '5px 0',
...(!embedded && { maxHeight: 175 }),
...style,
}}
>
{createNew && (
Expand All @@ -94,6 +98,7 @@ function PayeeList({
':active': {
backgroundColor: 'rgba(100, 100, 100, .25)',
},
...createPayeeButtonStyle,
}}
>
<View
Expand Down Expand Up @@ -176,6 +181,7 @@ function PayeeList({
padding: 4,
paddingLeft: 20,
},
itemStyle,
])}`}
>
{item.name}
Expand Down Expand Up @@ -213,7 +219,12 @@ export default function PayeeAutocomplete({
onUpdate,
onSelect,
onManagePayees,
payeeListStyle,
payeeListItemStyle,
groupHeaderStyle,
createPayeeButtonStyle,
makeTransferButtonStyle,
managePayeesButtonStyle,
accounts,
payees,
...props
Expand Down Expand Up @@ -285,11 +296,15 @@ export default function PayeeAutocomplete({
focused={payeeFieldFocused}
inputProps={{
...inputProps,
onBlur: () => {
onBlur: e => {
setRawPayee('');
setPayeeFieldFocused(false);
inputProps?.onBlur?.(e);
},
onFocus: e => {
setPayeeFieldFocused(true);
inputProps?.onFocus?.(e);
},
onFocus: () => setPayeeFieldFocused(true),
onChange: setRawPayee,
}}
onUpdate={(value, inputValue) =>
Expand Down Expand Up @@ -360,13 +375,19 @@ export default function PayeeAutocomplete({
highlightedIndex={highlightedIndex}
inputValue={inputValue}
embedded={embedded}
style={payeeListStyle}
itemStyle={payeeListItemStyle}
createPayeeButtonStyle={createPayeeButtonStyle}
groupHeaderStyle={groupHeaderStyle}
footer={
<AutocompleteFooter embedded={embedded}>
{showMakeTransfer && (
<Button
type={focusTransferPayees ? 'menuSelected' : 'menu'}
style={showManagePayees && { marginBottom: 5 }}
style={{
...(showManagePayees && { marginBottom: 5 }),
...makeTransferButtonStyle,
}}
onClick={() => {
onUpdate?.(null);
setFocusTransferPayees(!focusTransferPayees);
Expand All @@ -376,7 +397,11 @@ export default function PayeeAutocomplete({
</Button>
)}
{showManagePayees && (
<Button type="menu" onClick={() => onManagePayees()}>
<Button
type="menu"
style={managePayeesButtonStyle}
onClick={() => onManagePayees?.()}
>
Manage Payees
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class AmountInput extends PureComponent {
// });
// }

onKeyPress = e => {
if (e.nativeEvent.key === 'Backspace' && this.state.text === '') {
onKeyUp = e => {
if (e.key === 'Backspace' && this.state.text === '') {
this.setState({ editing: true });
}
};
Expand Down Expand Up @@ -151,7 +151,7 @@ class AmountInput extends PureComponent {
autoCapitalize="none"
onChange={e => this.onChangeText(e.target.value)}
onBlur={this.onBlur}
onKeyPress={this.onKeyPress}
onKeyUp={this.onKeyUp}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated since onKeyPress is now deprecated.

data-testid="amount-input"
style={{ flex: 1, textAlign: 'center', position: 'absolute' }}
/>
Expand Down
3 changes: 2 additions & 1 deletion packages/desktop-client/src/components/mobile/MobileForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export const InputField = forwardRef(function InputField(
);
});

export function TapField({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function TapField({
value,
children,
disabled,
Expand Down
Loading