Skip to content

Commit 218a8b3

Browse files
authored
fix: Temporary fix for auto complete (#364)
1 parent b3ad66c commit 218a8b3

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

packages/fuselage/src/components/AutoComplete/index.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
useMutableCallback,
33
useResizeObserver,
44
} from '@rocket.chat/fuselage-hooks';
5-
import React, { useEffect, useRef, useMemo } from 'react';
5+
import React, { useEffect, useRef, useMemo, useState } from 'react';
66

77
import { Box, PositionAnimated, AnimatedVisibility } from '../Box';
88
import Chip from '../Chip';
@@ -14,7 +14,6 @@ import { useCursor, Options } from '../Options';
1414
const Addon = (props) => <Box rcx-autocomplete__addon {...props} />;
1515

1616
const SelectedOptions = React.memo((props) => <Chip {...props} />);
17-
1817
export function AutoComplete({
1918
value,
2019
filter,
@@ -34,9 +33,14 @@ export function AutoComplete({
3433

3534
const ref = useRef();
3635

36+
const [selected, setSelected] = useState(() =>
37+
options.find((option) => getValue(option) === value)
38+
);
39+
3740
const selectByKeyboard = useMutableCallback(([value]) => {
38-
setFilter('');
41+
setSelected(options.find((option) => getValue(option) === value));
3942
onChange(value);
43+
setFilter('');
4044
});
4145

4246
const memoizedOptions = useMemo(
@@ -53,6 +57,7 @@ export function AutoComplete({
5357
] = useCursor(value, memoizedOptions, selectByKeyboard);
5458

5559
const onSelect = useMutableCallback(([value]) => {
60+
setSelected(options.find((option) => getValue(option) === value));
5661
onChange(value);
5762
setFilter('');
5863
hide();
@@ -88,21 +93,20 @@ export function AutoComplete({
8893
onBlur={hide}
8994
onFocus={show}
9095
onKeyDown={handleKeyDown}
91-
placeholder={placeholder}
96+
placeholder={
97+
(optionsAreVisible !== AnimatedVisibility.HIDDEN || !value) &&
98+
placeholder
99+
}
92100
order={1}
93101
rcx-input-box--undecorated
94102
value={filter}
95103
/>
96-
{value && optionsAreVisible === AnimatedVisibility.HIDDEN && (
104+
{selected && optionsAreVisible === AnimatedVisibility.HIDDEN && (
97105
<RenderSelected
98106
role='option'
99107
value={value}
100-
label={getLabel(
101-
options.find((option) => getValue(option) === value)
102-
)}
103-
children={getLabel(
104-
options.find((option) => getValue(option) === value)
105-
)}
108+
label={getLabel(selected)}
109+
children={getLabel(selected)}
106110
/>
107111
)}
108112
</Margins>

packages/fuselage/src/components/Options/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,4 @@ export const useCursor = (initial, options, onChange) => {
190190
return [cursor, handleKeyDown, handleKeyUp, reset, visibilityHandler];
191191
};
192192

193-
Options.AvatarSize = 'x28';
193+
Options.AvatarSize = 'x20';

0 commit comments

Comments
 (0)