Skip to content

Commit c5da68d

Browse files
committed
fix: Fixed header ref for calculating the header height
1 parent 00a866a commit c5da68d

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/Form.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Box, useFocusManager, useInput } from 'ink';
2-
import { useEffect, useMemo, useState } from 'react';
1+
import { Box, measureElement, useFocusManager, useInput } from 'ink';
2+
import { useEffect, useMemo, useRef, useState } from 'react';
33
import * as React from 'react';
44
import { FormProps } from './types.js';
55
import { FormHeader } from './FormHeader.js';
@@ -21,6 +21,8 @@ export const Form: React.FC<FormProps> = props => {
2121
const canSubmitForm = useMemo(() => canSubmit(props.form, value), [value, props.form]);
2222
const focusManager = useFocusManager();
2323
const [focusedElement, setFocusedElement] = useState(0);
24+
const headerRef = useRef();
25+
const headerHeight = headerRef.current ? measureElement(headerRef.current).height : 5
2426

2527
useEffect(() => {
2628
focusManager.enableFocus();
@@ -118,8 +120,8 @@ export const Form: React.FC<FormProps> = props => {
118120
return (
119121
<FullScreen>
120122
<Box width="100%" height="90%" flexDirection="column" overflowY="hidden">
121-
<FormHeader {...props} form={{ ...props.form, sections }} currentTab={currentTab} onChangeTab={onChangeTab} editingField={editingField} />
122-
<ScrollArea height={size.rows - 6} key={currentTab} isStart={focusedElement === 0}>
123+
<FormHeader {...props} headerRef={headerRef} form={{ ...props.form, sections }} currentTab={currentTab} onChangeTab={onChangeTab} editingField={editingField} />
124+
<ScrollArea height={size.rows - headerHeight} key={currentTab} isStart={focusedElement === 0}>
123125
{!editingField && sections[currentTab].description && (
124126
<Box marginX={4}>
125127
<DescriptionRenderer description={props.form.sections[currentTab]?.description} />

src/FormHeader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FormProps } from './types.js';
55
export const HELP_SECTION_ID = 'Help';
66

77
export const FormHeader: React.FC<
8-
FormProps & { currentTab: number; onChangeTab: (tab: number) => void; editingField?: string }
8+
FormProps & { currentTab: number; onChangeTab: (tab: number) => void; editingField?: string, headerRef?: React.Ref<any> }
99
> = props => {
1010
const sections = props.form.sections;
1111

@@ -29,7 +29,7 @@ export const FormHeader: React.FC<
2929
);
3030

3131
return (
32-
<Box borderStyle="double" width="100%" flexDirection="column">
32+
<Box borderStyle="double" width="100%" flexDirection="column" ref={props.headerRef}>
3333
<Box width="100%">
3434
<Box flexGrow={1}>
3535
<Text bold={true}>{props.form.title}</Text>

0 commit comments

Comments
 (0)