From 19571f79d6f0fd29d1d6e7de4aa5d521e694191c Mon Sep 17 00:00:00 2001 From: Dan Roujinsky Date: Fri, 10 Jun 2022 15:24:05 +0300 Subject: [PATCH] fix(combobox): fix focus on option select --- .idea/.gitignore | 5 ++ .idea/codeStyles/Project.xml | 65 +++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ .idea/headlessui-fork.iml | 12 ++++ .idea/markdown.xml | 9 +++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 ++ .../src/components/combobox/combobox.tsx | 25 ++++--- 8 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/headlessui-fork.iml create mode 100644 .idea/markdown.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000..b58b603fea --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000000..28934ac789 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000000..79ee123c2b --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/headlessui-fork.iml b/.idea/headlessui-fork.iml new file mode 100644 index 0000000000..0c8867d7e1 --- /dev/null +++ b/.idea/headlessui-fork.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown.xml b/.idea/markdown.xml new file mode 100644 index 0000000000..1e34094123 --- /dev/null +++ b/.idea/markdown.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..4d68d84897 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..94a25f7f4c --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/packages/@headlessui-react/src/components/combobox/combobox.tsx b/packages/@headlessui-react/src/components/combobox/combobox.tsx index e00d55fdd9..0245a62a8d 100644 --- a/packages/@headlessui-react/src/components/combobox/combobox.tsx +++ b/packages/@headlessui-react/src/components/combobox/combobox.tsx @@ -1,19 +1,17 @@ import React, { - Fragment, createContext, createRef, - useCallback, - useContext, - useMemo, - useReducer, - useRef, - - // Types ElementType, + Fragment, KeyboardEvent as ReactKeyboardEvent, MouseEvent as ReactMouseEvent, MutableRefObject, Ref, + useCallback, + useContext, + useMemo, + useReducer, + useRef, } from 'react' import { Props } from '../../types' @@ -30,16 +28,17 @@ import { useTreeWalker } from '../../hooks/use-tree-walker' import { calculateActiveIndex, Focus } from '../../utils/calculate-active-index' import { disposables } from '../../utils/disposables' -import { forwardRefWithAs, render, compact, PropsForFeatures, Features } from '../../utils/render' +import { compact, Features, forwardRefWithAs, PropsForFeatures, render } from '../../utils/render' import { isDisabledReactIssue7711 } from '../../utils/bugs' import { match } from '../../utils/match' import { objectToFormEntries } from '../../utils/form' -import { FocusableMode, isFocusableElement, sortByDomNode } from '../../utils/focus-management' +import { sortByDomNode } from '../../utils/focus-management' -import { Hidden, Features as HiddenFeatures } from '../../internal/hidden' -import { useOpenClosed, State, OpenClosedProvider } from '../../internal/open-closed' +import { Features as HiddenFeatures, Hidden } from '../../internal/hidden' +import { OpenClosedProvider, State, useOpenClosed } from '../../internal/open-closed' import { Keys } from '../keyboard' +import { microTask } from 'utils/micro-task' enum ComboboxState { Open, @@ -1064,7 +1063,7 @@ let Option = forwardRefWithAs(function Option< select() if (data.mode === ValueMode.Single) { actions.closeCombobox() - disposables().nextFrame(() => data.inputRef.current?.focus({ preventScroll: true })) + microTask(() => data.inputRef.current?.focus({ preventScroll: true })) } })