Skip to content

Commit 14fb778

Browse files
committed
Blur commit input on enter/return
1 parent 4d49ee8 commit 14fb778

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

packages/react-devtools-shared/src/devtools/views/Profiler/SnapshotSelector.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import * as React from 'react';
11-
import {Fragment, useCallback, useContext, useMemo} from 'react';
11+
import {Fragment, useCallback, useContext, useMemo, useRef} from 'react';
1212
import Button from '../Button';
1313
import ButtonIcon from '../ButtonIcon';
1414
import {ProfilerContext} from './ProfilerContext';
@@ -81,7 +81,20 @@ export default function SnapshotSelector(_: Props) {
8181
}
8282

8383
let label = null;
84-
const onCommitInputChange = useCallback(
84+
const commitInputRef = useRef(null);
85+
const handleCommitInputKeyDown = useCallback(event => {
86+
switch (event.key) {
87+
case 'Enter':
88+
event.stopPropagation();
89+
if (commitInputRef.current) {
90+
commitInputRef.current.blur();
91+
}
92+
break;
93+
default:
94+
break;
95+
}
96+
}, []);
97+
const handleCommitInputChange = useCallback(
8598
event => {
8699
const value = parseInt(event.target.value, 10);
87100
if (!isNaN(value)) {
@@ -100,13 +113,15 @@ export default function SnapshotSelector(_: Props) {
100113
1}`;
101114
const input = (
102115
<input
116+
ref={commitInputRef}
103117
className={styles.Input}
104118
type="text"
105119
inputMode="numeric"
106120
pattern="[0-9]*"
107121
value={selectedFilteredCommitIndexString}
108-
onChange={onCommitInputChange}
109122
size={numFilteredCommitsString.length}
123+
onChange={handleCommitInputChange}
124+
onKeyDown={handleCommitInputKeyDown}
110125
/>
111126
);
112127
label = (

0 commit comments

Comments
 (0)