Skip to content

Commit b2c040d

Browse files
committed
client(SelectInput.tsx): add a ref to the currently selected element to trigger scrollIntoView function to it
1 parent f388f64 commit b2c040d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

client/src/components/input/SelectInput.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const SelectInput: FC<SelectInputProps> = (props) => {
1818

1919
const ref = useOuterClick(() => setIsActive(false));
2020
const inputRef = useRef<HTMLInputElement>(null);
21+
const activeRef = useRef<HTMLSpanElement>(null);
2122

2223
useEffect(() => {
2324
if (filterValue.trim() === "") {
@@ -50,7 +51,13 @@ const SelectInput: FC<SelectInputProps> = (props) => {
5051
<div
5152
onClick={() => {
5253
setIsActive((prev) => {
53-
if (!prev) inputRef.current?.focus();
54+
if (!prev) {
55+
inputRef.current?.focus();
56+
activeRef.current?.scrollIntoView({
57+
block: "nearest",
58+
inline: "start",
59+
});
60+
}
5461
return !prev;
5562
});
5663
}}
@@ -118,7 +125,7 @@ const SelectInput: FC<SelectInputProps> = (props) => {
118125
}`}
119126
>
120127
{isSelected && (
121-
<span>
128+
<span ref={activeRef}>
122129
<FiCheck />
123130
</span>
124131
)}

0 commit comments

Comments
 (0)