@inquirer/select
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -41,3 +41,8 @@ "use strict"; | ||
}, [items]); | ||
const [active, setActive] = (0, core_1.useState)(bounds.first); | ||
const defaultItemIndex = (0, core_1.useMemo)(() => { | ||
if (!('default' in config)) | ||
return -1; | ||
return items.findIndex((item) => isSelectable(item) && item.value === config.default); | ||
}, [config.default, items]); | ||
const [active, setActive] = (0, core_1.useState)(defaultItemIndex === -1 ? bounds.first : defaultItemIndex); | ||
// Safe to assume the cursor position always point to a Choice. | ||
@@ -51,12 +56,12 @@ const selectedChoice = items[active]; | ||
else if ((0, core_1.isUpKey)(key) || (0, core_1.isDownKey)(key)) { | ||
if (!loop && active === bounds.first && (0, core_1.isUpKey)(key)) | ||
return; | ||
if (!loop && active === bounds.last && (0, core_1.isDownKey)(key)) | ||
return; | ||
const offset = (0, core_1.isUpKey)(key) ? -1 : 1; | ||
let next = active; | ||
do { | ||
next = (next + offset + items.length) % items.length; | ||
} while (!isSelectable(items[next])); | ||
setActive(next); | ||
if (loop || | ||
((0, core_1.isUpKey)(key) && active !== bounds.first) || | ||
((0, core_1.isDownKey)(key) && active !== bounds.last)) { | ||
const offset = (0, core_1.isUpKey)(key) ? -1 : 1; | ||
let next = active; | ||
do { | ||
next = (next + offset + items.length) % items.length; | ||
} while (!isSelectable(items[next])); | ||
setActive(next); | ||
} | ||
} | ||
@@ -66,5 +71,5 @@ else if ((0, core_1.isNumberKey)(key)) { | ||
const item = items[position]; | ||
if (item == null || !isSelectable(item)) | ||
return; | ||
setActive(position); | ||
if (item != null && isSelectable(item)) { | ||
setActive(position); | ||
} | ||
} | ||
@@ -71,0 +76,0 @@ }); |
@@ -41,3 +41,8 @@ "use strict"; | ||
}, [items]); | ||
const [active, setActive] = (0, core_1.useState)(bounds.first); | ||
const defaultItemIndex = (0, core_1.useMemo)(() => { | ||
if (!('default' in config)) | ||
return -1; | ||
return items.findIndex((item) => isSelectable(item) && item.value === config.default); | ||
}, [config.default, items]); | ||
const [active, setActive] = (0, core_1.useState)(defaultItemIndex === -1 ? bounds.first : defaultItemIndex); | ||
// Safe to assume the cursor position always point to a Choice. | ||
@@ -51,12 +56,12 @@ const selectedChoice = items[active]; | ||
else if ((0, core_1.isUpKey)(key) || (0, core_1.isDownKey)(key)) { | ||
if (!loop && active === bounds.first && (0, core_1.isUpKey)(key)) | ||
return; | ||
if (!loop && active === bounds.last && (0, core_1.isDownKey)(key)) | ||
return; | ||
const offset = (0, core_1.isUpKey)(key) ? -1 : 1; | ||
let next = active; | ||
do { | ||
next = (next + offset + items.length) % items.length; | ||
} while (!isSelectable(items[next])); | ||
setActive(next); | ||
if (loop || | ||
((0, core_1.isUpKey)(key) && active !== bounds.first) || | ||
((0, core_1.isDownKey)(key) && active !== bounds.last)) { | ||
const offset = (0, core_1.isUpKey)(key) ? -1 : 1; | ||
let next = active; | ||
do { | ||
next = (next + offset + items.length) % items.length; | ||
} while (!isSelectable(items[next])); | ||
setActive(next); | ||
} | ||
} | ||
@@ -66,5 +71,5 @@ else if ((0, core_1.isNumberKey)(key)) { | ||
const item = items[position]; | ||
if (item == null || !isSelectable(item)) | ||
return; | ||
setActive(position); | ||
if (item != null && isSelectable(item)) { | ||
setActive(position); | ||
} | ||
} | ||
@@ -71,0 +76,0 @@ }); |
@@ -14,4 +14,5 @@ import { Separator } from '@inquirer/core'; | ||
loop?: boolean | undefined; | ||
default?: Value | undefined; | ||
}, context?: import("@inquirer/type").Context | undefined) => import("@inquirer/type").CancelablePromise<Value>; | ||
export default _default; | ||
export { Separator }; |
{ | ||
"name": "@inquirer/select", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Inquirer select/list prompt", | ||
@@ -57,3 +57,3 @@ "main": "./dist/cjs/index.js", | ||
"dependencies": { | ||
"@inquirer/core": "^5.1.0", | ||
"@inquirer/core": "^5.1.1", | ||
"@inquirer/type": "^1.1.5", | ||
@@ -65,3 +65,3 @@ "ansi-escapes": "^4.3.2", | ||
"devDependencies": { | ||
"@inquirer/testing": "^2.1.8" | ||
"@inquirer/testing": "^2.1.9" | ||
}, | ||
@@ -91,3 +91,3 @@ "scripts": { | ||
}, | ||
"gitHead": "c88aaca660e58aa0fb079fe656c1004855e029da" | ||
"gitHead": "a318aec57d33b53131c0b03cc8dd6ab4efae3e50" | ||
} |
@@ -54,3 +54,5 @@ # `@inquirer/select` | ||
| choices | `Array<{ value: string, name?: string, description?: string, disabled?: boolean \| string } \| Separator>` | yes | List of the available choices. The `value` will be returned as the answer, and used as display if no `name` is defined. Choices who're `disabled` will be displayed, but not selectable. The `description` will be displayed under the prompt when the cursor land over the choice. | | ||
| default | `string` | no | Defines in front of which item the cursor will initially appear. When omitted, the cursor will appear on the first selectable item. | | ||
| pageSize | `number` | no | By default, lists of choice longer than 7 will be paginated. Use this option to control how many choices will appear on the screen at once. | | ||
| loop | `boolean` | no | Defaults to `true`. When set to `false`, the cursor will be constrained to the top and bottom of the choice list without looping. | | ||
@@ -57,0 +59,0 @@ The `Separator` object can be used to render non-selectable lines in the choice list. By default it'll render a line, but you can provide the text as argument (`new Separator('-- Dependencies --')`). This option is often used to add labels to groups within long list of options. |
Sorry, the diff of this file is not supported yet
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
19998
290
64
Updated@inquirer/core@^5.1.1