@inquirer/select
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -25,2 +25,3 @@ "use strict"; | ||
const [status, setStatus] = (0, core_1.useState)('pending'); | ||
const searchTimeoutRef = (0, core_1.useRef)(undefined); | ||
const bounds = (0, core_1.useMemo)(() => { | ||
@@ -42,3 +43,4 @@ const first = items.findIndex(isSelectable); | ||
const selectedChoice = items[active]; | ||
(0, core_1.useKeypress)((key) => { | ||
(0, core_1.useKeypress)((key, rl) => { | ||
clearTimeout(searchTimeoutRef.current); | ||
if ((0, core_1.isEnterKey)(key)) { | ||
@@ -49,2 +51,3 @@ setStatus('done'); | ||
else if ((0, core_1.isUpKey)(key) || (0, core_1.isDownKey)(key)) { | ||
rl.clearLine(0); | ||
if (loop || | ||
@@ -62,2 +65,3 @@ ((0, core_1.isUpKey)(key) && active !== bounds.first) || | ||
else if ((0, core_1.isNumberKey)(key)) { | ||
rl.clearLine(0); | ||
const position = Number(key.name) - 1; | ||
@@ -69,2 +73,22 @@ const item = items[position]; | ||
} | ||
else if ((0, core_1.isBackspaceKey)(key)) { | ||
rl.clearLine(0); | ||
} | ||
else { | ||
// Default to search | ||
const searchTerm = rl.line.toLowerCase(); | ||
const matchIndex = items.findIndex((item) => { | ||
if (core_1.Separator.isSeparator(item) || !isSelectable(item)) | ||
return false; | ||
return String(item.name || item.value) | ||
.toLowerCase() | ||
.startsWith(searchTerm); | ||
}); | ||
if (matchIndex >= 0) { | ||
setActive(matchIndex); | ||
} | ||
searchTimeoutRef.current = setTimeout(() => { | ||
rl.clearLine(0); | ||
}, 700); | ||
} | ||
}); | ||
@@ -71,0 +95,0 @@ const message = theme.style.message(config.message); |
@@ -25,2 +25,3 @@ "use strict"; | ||
const [status, setStatus] = (0, core_1.useState)('pending'); | ||
const searchTimeoutRef = (0, core_1.useRef)(undefined); | ||
const bounds = (0, core_1.useMemo)(() => { | ||
@@ -42,3 +43,4 @@ const first = items.findIndex(isSelectable); | ||
const selectedChoice = items[active]; | ||
(0, core_1.useKeypress)((key) => { | ||
(0, core_1.useKeypress)((key, rl) => { | ||
clearTimeout(searchTimeoutRef.current); | ||
if ((0, core_1.isEnterKey)(key)) { | ||
@@ -49,2 +51,3 @@ setStatus('done'); | ||
else if ((0, core_1.isUpKey)(key) || (0, core_1.isDownKey)(key)) { | ||
rl.clearLine(0); | ||
if (loop || | ||
@@ -62,2 +65,3 @@ ((0, core_1.isUpKey)(key) && active !== bounds.first) || | ||
else if ((0, core_1.isNumberKey)(key)) { | ||
rl.clearLine(0); | ||
const position = Number(key.name) - 1; | ||
@@ -69,2 +73,22 @@ const item = items[position]; | ||
} | ||
else if ((0, core_1.isBackspaceKey)(key)) { | ||
rl.clearLine(0); | ||
} | ||
else { | ||
// Default to search | ||
const searchTerm = rl.line.toLowerCase(); | ||
const matchIndex = items.findIndex((item) => { | ||
if (core_1.Separator.isSeparator(item) || !isSelectable(item)) | ||
return false; | ||
return String(item.name || item.value) | ||
.toLowerCase() | ||
.startsWith(searchTerm); | ||
}); | ||
if (matchIndex >= 0) { | ||
setActive(matchIndex); | ||
} | ||
searchTimeoutRef.current = setTimeout(() => { | ||
rl.clearLine(0); | ||
}, 700); | ||
} | ||
}); | ||
@@ -71,0 +95,0 @@ const message = theme.style.message(config.message); |
{ | ||
"name": "@inquirer/select", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Inquirer select/list prompt", | ||
@@ -57,3 +57,3 @@ "main": "./dist/cjs/index.js", | ||
"dependencies": { | ||
"@inquirer/core": "^7.0.0", | ||
"@inquirer/core": "^7.0.1", | ||
"@inquirer/type": "^1.2.0", | ||
@@ -65,3 +65,3 @@ "ansi-escapes": "^4.3.2", | ||
"devDependencies": { | ||
"@inquirer/testing": "^2.1.11" | ||
"@inquirer/testing": "^2.1.12" | ||
}, | ||
@@ -91,3 +91,3 @@ "scripts": { | ||
}, | ||
"gitHead": "44016a40bc9e93455dfdb9fa6c25c27c1c109bd3" | ||
"gitHead": "c91196e66689cfc05e9237763e6f95f3eb5342a1" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26449
409
Updated@inquirer/core@^7.0.1