UNPKG

698 BJavaScriptView Raw
1import isSelectable from './isSelectable';
2export default function defaultSelectHint(e, selectHint) {
3 var shouldSelectHint = false;
4
5 if (e.key === 'ArrowRight') {
6 // For selectable input types ("text", "search"), only select the hint if
7 // it's at the end of the input value. For non-selectable types ("email",
8 // "number"), always select the hint.
9 shouldSelectHint = isSelectable(e.currentTarget) ? e.currentTarget.selectionStart === e.currentTarget.value.length : true;
10 }
11
12 if (e.key === 'Tab') {
13 // Prevent input from blurring on TAB.
14 e.preventDefault();
15 shouldSelectHint = true;
16 }
17
18 return selectHint ? selectHint(shouldSelectHint, e) : shouldSelectHint;
19}
\No newline at end of file