Skip to content

Commit

Permalink
Blur commit input on enter/return
Browse files Browse the repository at this point in the history
  • Loading branch information
srubin committed Oct 5, 2020
1 parent 4d49ee8 commit 14fb778
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import * as React from 'react';
import {Fragment, useCallback, useContext, useMemo} from 'react';
import {Fragment, useCallback, useContext, useMemo, useRef} from 'react';
import Button from '../Button';
import ButtonIcon from '../ButtonIcon';
import {ProfilerContext} from './ProfilerContext';
Expand Down Expand Up @@ -81,7 +81,20 @@ export default function SnapshotSelector(_: Props) {
}

let label = null;
const onCommitInputChange = useCallback(
const commitInputRef = useRef(null);
const handleCommitInputKeyDown = useCallback(event => {
switch (event.key) {
case 'Enter':
event.stopPropagation();
if (commitInputRef.current) {
commitInputRef.current.blur();
}
break;
default:
break;
}
}, []);
const handleCommitInputChange = useCallback(
event => {
const value = parseInt(event.target.value, 10);
if (!isNaN(value)) {
Expand All @@ -100,13 +113,15 @@ export default function SnapshotSelector(_: Props) {
1}`;
const input = (
<input
ref={commitInputRef}
className={styles.Input}
type="text"
inputMode="numeric"
pattern="[0-9]*"
value={selectedFilteredCommitIndexString}
onChange={onCommitInputChange}
size={numFilteredCommitsString.length}
onChange={handleCommitInputChange}
onKeyDown={handleCommitInputKeyDown}
/>
);
label = (
Expand Down

0 comments on commit 14fb778

Please sign in to comment.