From aaabdfdd7906ad8557bfe1cd26454e3fbb616b0b Mon Sep 17 00:00:00 2001 From: James Gatz Date: Wed, 26 Jun 2024 11:03:18 +0200 Subject: [PATCH] fix empty value and close combobox input on select (#7590) --- .../src/ui/components/environment-picker.tsx | 149 ++++++++---------- 1 file changed, 69 insertions(+), 80 deletions(-) diff --git a/packages/insomnia/src/ui/components/environment-picker.tsx b/packages/insomnia/src/ui/components/environment-picker.tsx index 58a0252d14..bb2259ef8c 100644 --- a/packages/insomnia/src/ui/components/environment-picker.tsx +++ b/packages/insomnia/src/ui/components/environment-picker.tsx @@ -1,5 +1,5 @@ import { IconName } from '@fortawesome/fontawesome-svg-core'; -import React, { Fragment } from 'react'; +import React, { Fragment, useRef } from 'react'; import { Button, ComboBox, Dialog, DialogTrigger, Heading, Input, ListBox, ListBoxItem, Popover } from 'react-aria-components'; import { useFetcher, useNavigate, useParams, useRouteLoaderData } from 'react-router-dom'; @@ -50,6 +50,8 @@ export const EnvironmentPicker = ({ const navigate = useNavigate(); + const globalEnvironmentListBox = useRef(null); + return ( )} - { - const match = Boolean(fuzzyMatch( - filter, - textValue, - { splitSpace: false, loose: true } - )?.indexes); +
+ { + const match = Boolean(fuzzyMatch( + filter, + textValue, + { splitSpace: false, loose: true } + )?.indexes); - return match; - }} - onSelectionChange={environmentId => { - if (environmentId === 'all' || !environmentId) { - return; - } - - setActiveGlobalEnvironmentFetcher.submit( - { - environmentId, - }, - { - method: 'POST', - action: `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/environment/set-active-global`, + return match; + }} + onSelectionChange={environmentId => { + if (environmentId === 'all' || environmentId === null) { + return; } - ); - }} - inputValue={selectedGlobalBaseEnvironment?.workspaceName || selectedGlobalBaseEnvironment?.name || ''} - selectedKey={selectedGlobalBaseEnvironmentId} - defaultItems={[...globalBaseEnvironments.map(baseEnv => { - return { - id: baseEnv._id, - icon: 'code', - name: baseEnv.workspaceName || baseEnv.name, - textValue: baseEnv.workspaceName || baseEnv.name, - }; - }), { id: '', icon: 'cancel', name: 'No Global Environment', textValue: 'No Global Environment' }]} - > -
- - -
- - - className="select-none text-sm min-w-max p-2 flex flex-col overflow-y-auto focus:outline-none" - > - {item => ( - - - {item.name} - - )} - - -
+ + setActiveGlobalEnvironmentFetcher.submit( + { + environmentId, + }, + { + method: 'POST', + action: `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/environment/set-active-global`, + } + ); + + globalEnvironmentListBox.current?.focus(); + }} + defaultInputValue={selectedGlobalBaseEnvironment?.workspaceName || selectedGlobalBaseEnvironment?.name || ''} + selectedKey={selectedGlobalBaseEnvironmentId} + defaultItems={[...globalBaseEnvironments.map(baseEnv => { + return { + id: baseEnv._id, + icon: 'code', + name: baseEnv.workspaceName || baseEnv.name, + textValue: baseEnv.workspaceName || baseEnv.name, + }; + }), { id: '', icon: 'cancel', name: 'No Global Environment', textValue: 'No Global Environment' }]} + > +
+ + +
+ + + className="select-none text-sm min-w-max p-2 flex flex-col overflow-y-auto focus:outline-none" + > + {item => ( + + + {item.name} + + )} + + + +