Skip to content

Commit 58223c9

Browse files
authored
feat(select): set default cursorPosition to the first non-disabled item (#1170)
1 parent 3202395 commit 58223c9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/select/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ type SelectConfig = AsyncPromptConfig & {
2222

2323
export default createPrompt<string, SelectConfig>((config, done) => {
2424
const { choices } = config;
25+
const startIndex = Math.max(
26+
choices.findIndex(({ disabled }) => !disabled),
27+
0
28+
);
2529

2630
const paginator = useRef(new Paginator()).current;
2731
const firstRender = useRef(true);
2832

2933
const prefix = usePrefix();
3034
const [status, setStatus] = useState('pending');
31-
const [cursorPosition, setCursorPos] = useState(0);
35+
const [cursorPosition, setCursorPos] = useState(startIndex);
3236

3337
useKeypress((key) => {
3438
if (isEnterKey(key)) {

0 commit comments

Comments
 (0)