Skip to content

Commit

Permalink
feat: adaptative max items
Browse files Browse the repository at this point in the history
  • Loading branch information
orochaa committed Oct 4, 2023
1 parent 90f8e3d commit 360afeb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-laws-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clack/prompts': patch
---

feat: adaptative max items
5 changes: 3 additions & 2 deletions packages/prompts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SelectKeyPrompt,
SelectPrompt,
State,
TextPrompt
TextPrompt,
} from '@clack/core';
import isUnicodeSupported from 'is-unicode-supported';
import color from 'picocolors';
Expand Down Expand Up @@ -69,7 +69,8 @@ const limitOptions = <TOption>(params: LimitOptionsParams<TOption>): string[] =>
const { cursor, options, style } = params;

// We clamp to minimum 5 because anything less doesn't make sense UX wise
const maxItems = params.maxItems === undefined ? Infinity : Math.max(params.maxItems, 5);
const maxItems =
params.maxItems === undefined ? process.stdout.rows - 4 : Math.max(params.maxItems, 5);
let slidingWindowLocation = 0;

if (cursor >= slidingWindowLocation + maxItems - 3) {
Expand Down

0 comments on commit 360afeb

Please sign in to comment.