Skip to content

Commit

Permalink
Merge branch 'main' into store-controlled-props-2
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohaz committed Mar 25, 2024
2 parents 3eee38f + 457f431 commit fbc0fb2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/ariakit-react-core/src/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ export const useCombobox = createHook<TagName, ComboboxOptions>(
onChangeProp?.(event);
if (event.defaultPrevented) return;
if (!store) return;
const { value, selectionStart } = event.currentTarget;
const currentTarget = event.currentTarget;
const { value, selectionStart, selectionEnd } = currentTarget;
const nativeEvent = event.nativeEvent;
canAutoSelectRef.current = true;
if (isInputEvent(nativeEvent)) {
Expand All @@ -398,6 +399,11 @@ export const useCombobox = createHook<TagName, ComboboxOptions>(
if (setValueOnChangeProp(event)) {
const isSameValue = value === store.getState().value;
store.setValue(value);
// When the value is not set synchronously, the selection range may be
// lost. See combobox-group "keep caret position when typing" test.
queueMicrotask(() => {
setSelectionRange(currentTarget, selectionStart, selectionEnd);
});
if (inline && autoSelect && isSameValue) {
// The store.setValue(event.target.value) above may not trigger a
// state update. For example, say the first item starts with "t". The
Expand Down

0 comments on commit fbc0fb2

Please sign in to comment.