From 5b63917db308ab75dc765de543e97819f16924b7 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 6 Jul 2023 20:07:45 -0700 Subject: details --- extension/react-app/src/components/ComboBox.tsx | 62 +++++++++++++--------- .../react-app/src/components/ContinueButton.tsx | 3 +- .../react-app/src/components/StepContainer.tsx | 3 ++ extension/react-app/src/tabs/gui.tsx | 26 +-------- 4 files changed, 44 insertions(+), 50 deletions(-) (limited to 'extension/react-app/src') diff --git a/extension/react-app/src/components/ComboBox.tsx b/extension/react-app/src/components/ComboBox.tsx index 55496fb9..4dab8bcd 100644 --- a/extension/react-app/src/components/ComboBox.tsx +++ b/extension/react-app/src/components/ComboBox.tsx @@ -1,4 +1,9 @@ -import React, { useCallback, useEffect, useState } from "react"; +import React, { + useCallback, + useEffect, + useImperativeHandle, + useState, +} from "react"; import { useCombobox } from "downshift"; import styled from "styled-components"; import { @@ -151,22 +156,13 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { const [highlightedCodeSections, setHighlightedCodeSections] = React.useState( props.highlightedCodeSections || [] ); + const inputRef = React.useRef(null); useEffect(() => { setHighlightedCodeSections(props.highlightedCodeSections || []); }, [props.highlightedCodeSections]); - const { - isOpen, - getToggleButtonProps, - getLabelProps, - getMenuProps, - getInputProps, - highlightedIndex, - getItemProps, - selectedItem, - setInputValue, - } = useCombobox({ + const { getInputProps, ...downshiftProps } = useCombobox({ onInputValueChange({ inputValue }) { if (!inputValue) return; props.onInputValueChange(inputValue); @@ -182,6 +178,24 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { }, }); + useImperativeHandle(ref, () => downshiftProps, [downshiftProps]); + + useEffect(() => { + if (!inputRef.current) { + return; + } + inputRef.current.focus(); + const handler = (event: any) => { + if (event.data.type === "focusContinueInput") { + inputRef.current!.focus(); + } + }; + window.addEventListener("message", handler); + return () => { + window.removeEventListener("message", handler); + }; + }, [inputRef.current]); + const divRef = React.useRef(null); const ulRef = React.useRef(null); const showAbove = () => { @@ -255,7 +269,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { ))} -