Skip to content

Commit

Permalink
implements focus behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitropoulos committed Jan 4, 2022
1 parent 7249c03 commit 4a4c018
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/insomnia-app/app/ui/components/panes/request-pane.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import classnames from 'classnames';
import { deconstructQueryStringToParams, extractQueryStringFromUrl } from 'insomnia-url';
import React, { FC, useCallback } from 'react';
import React, { FC, useCallback, useEffect, useRef } from 'react';
import { Tab, TabList, TabPanel, Tabs } from 'react-tabs';
import { useMount } from 'react-use';

import { getAuthTypeName, getContentTypeName } from '../../../common/constants';
import * as models from '../../../models';
Expand Down Expand Up @@ -136,6 +137,17 @@ export const RequestPane: FC<Props> = ({
}
}, [request, forceUpdateRequest]);

const requestUrlBarRef = useRef<RequestUrlBar | null>(null);
useMount(() => {
requestUrlBarRef.current?.focusInput();
});
useEffect(() => {
requestUrlBarRef.current?.focusInput();
}, [
request?._id, // happens when the user switches requests
settings.hasPromptedAnalytics, // happens when the user dismisses the analytics modal
]);

if (!request) {
return (
<PlaceholderRequestPane
Expand All @@ -161,6 +173,7 @@ export const RequestPane: FC<Props> = ({
<PaneHeader>
<ErrorBoundary errorClassName="font-error pad text-center">
<RequestUrlBar
ref={requestUrlBarRef}
uniquenessKey={uniqueKey}
onMethodChange={updateRequestMethod}
onUrlChange={updateRequestUrl}
Expand Down
6 changes: 6 additions & 0 deletions packages/insomnia-app/app/ui/components/request-url-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,19 @@ export class RequestUrlBar extends PureComponent<Props, State> {
return [cancelButton, sendButton];
}

// note: not an unused function, used by parent, RequestPane
focusInput() {
this._input?.focus(true);
}

render() {
const {
request,
handleAutocompleteUrls,
uniquenessKey,
} = this.props;
const { url, method } = request;

return (
<KeydownBinder onKeydown={this._handleKeyDown}>
<div className="urlbar">
Expand Down

0 comments on commit 4a4c018

Please sign in to comment.