Skip to content

Commit

Permalink
fix(combobox): odd cursor behavior (#17752)
Browse files Browse the repository at this point in the history
Co-authored-by: Nikhil Tomar <[email protected]>
Co-authored-by: Riddhi Bansal <[email protected]>
  • Loading branch information
3 people authored Oct 17, 2024
1 parent d5ae548 commit a7d18f1
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions packages/react/src/components/ComboBox/ComboBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ const ComboBox = forwardRef(
props: ComboBoxProps<ItemType>,
ref: ForwardedRef<HTMLInputElement>
) => {
const [cursorPosition, setCursorPosition] = useState(0);
const prevInputLengthRef = useRef(0);
const inputRef = useRef<HTMLInputElement>(null);

Expand Down Expand Up @@ -745,7 +744,6 @@ const ComboBox = forwardRef(
onChange({ selectedItem, inputValue: normalizedInput });
}
setHighlightedIndex(indexToHighlight(normalizedInput));
setCursorPosition(inputValue === null ? 0 : normalizedInput.length);
},
onSelectedItemChange({ selectedItem }) {
onChange({ selectedItem });
Expand Down Expand Up @@ -797,12 +795,6 @@ const ComboBox = forwardRef(
downshiftSetInputValue,
toggleMenu,
]);
useEffect(() => {
if (inputRef.current) {
inputRef.current.setSelectionRange(cursorPosition, cursorPosition);
}
}, [inputValue, cursorPosition]);

const buttonProps = getToggleButtonProps({
disabled: disabled || readOnly,
onClick: handleToggleClick(isOpen),
Expand Down Expand Up @@ -917,6 +909,7 @@ const ComboBox = forwardRef(
value: inputValue,
onChange: (e) => {
const newValue = e.target.value;
setInputValue(newValue);
downshiftSetInputValue(newValue);
},
ref: mergeRefs(textInput, ref, inputRef),
Expand Down Expand Up @@ -998,7 +991,6 @@ const ComboBox = forwardRef(
if (matchingItem) {
const newValue = itemToString(matchingItem);
downshiftSetInputValue(newValue);
setCursorPosition(newValue.length);
selectItem(matchingItem);
}
}
Expand Down

0 comments on commit a7d18f1

Please sign in to comment.