Skip to content

Commit 237aecb

Browse files
srubinBrian Vaughn
authored andcommitted
Blur commit input on enter/return
1 parent 4a8cf42 commit 237aecb

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';
@@ -85,7 +85,20 @@ export default function SnapshotSelector(_: Props) {
8585
}
8686

8787
let label = null;
88-
const onCommitInputChange = useCallback(
88+
const commitInputRef = useRef(null);
89+
const handleCommitInputKeyDown = useCallback(event => {
90+
switch (event.key) {
91+
case 'Enter':
92+
event.stopPropagation();
93+
if (commitInputRef.current) {
94+
commitInputRef.current.blur();
95+
}
96+
break;
97+
default:
98+
break;
99+
}
100+
}, []);
101+
const handleCommitInputChange = useCallback(
89102
event => {
90103
const value = parseInt(event.target.value, 10);
91104
if (!isNaN(value)) {
@@ -104,13 +117,15 @@ export default function SnapshotSelector(_: Props) {
104117
1}`;
105118
const input = (
106119
<input
120+
ref={commitInputRef}
107121
className={styles.Input}
108122
type="text"
109123
inputMode="numeric"
110124
pattern="[0-9]*"
111125
value={selectedFilteredCommitIndexString}
112-
onChange={onCommitInputChange}
113126
size={numFilteredCommitsString.length}
127+
onChange={handleCommitInputChange}
128+
onKeyDown={handleCommitInputKeyDown}
114129
/>
115130
);
116131
label = (

0 commit comments

Comments
 (0)