@@ -20,13 +20,14 @@ export const Form: React.FC<FormProps> = props => {
2020 const [ editingField , setEditingField ] = useState < string > ( ) ;
2121 const canSubmitForm = useMemo ( ( ) => canSubmit ( form , value ) , [ value , form ] ) ;
2222 const focusManager = useFocusManager ( ) ;
23- const [ focusedElement , setFocusedElement ] = useState ( - 1 ) ; // this is -1 because there is no initial focus. The first down click will focus on element 0
23+ const [ focusedElement , setFocusedElement ] = useState ( 0 ) ; // this is -1 because there is no initial focus. The first down click will focus on element 0
2424 const headerRef = useRef ( ) ;
2525 const headerHeight = headerRef . current ? measureElement ( headerRef . current ) . height : 5
2626 const [ , fullHeight ] = useStdoutDimensions ( )
2727
2828 useEffect ( ( ) => {
2929 focusManager . enableFocus ( ) ;
30+ setTimeout ( ( ) => focusManager . focusNext ( ) , 50 )
3031 } , [ ] ) ;
3132
3233 useEffect ( ( ) => {
@@ -54,7 +55,8 @@ export const Form: React.FC<FormProps> = props => {
5455
5556 const onChangeTab = ( tab : number ) => {
5657 setCurrentTab ( tab ) ;
57- setFocusedElement ( - 1 )
58+ setFocusedElement ( 0 )
59+ setTimeout ( ( ) => focusManager . focusNext ( ) , 50 )
5860 }
5961
6062 const setValueAndPropagate = ( index : number , newValue : Record < string , unknown > ) => {
@@ -84,7 +86,7 @@ export const Form: React.FC<FormProps> = props => {
8486 } else if ( key . downArrow ) {
8587 // This calculates the maximum amount of children there is. We don't want to scroll past the last item
8688 // Fields.length is number of json fields. 2 is the add and remove buttons. Submit button is sometimes focusable
87- const totalFocusableElements = sections [ currentTab ] . fields . length + 2 + ( canSubmitForm ? 1 : 0 ) + ( ( sections . length <= 1 ) ? - 1 : 0 )
89+ const totalFocusableElements = sections [ currentTab ] . fields . length + ( canSubmitForm ? 1 : 0 )
8890 if ( focusedElement + 1 >= totalFocusableElements ) {
8991 return ;
9092 }
@@ -126,6 +128,7 @@ export const Form: React.FC<FormProps> = props => {
126128
127129 setSections ( newTabs ) ;
128130 setValue ( [ ...value ] ) ;
131+ onChangeTab ( Math . min ( currentTab + 1 , newTabs . length - 1 ) ) ;
129132 }
130133
131134 const removeCurrentSection = ( ) => {
@@ -198,14 +201,13 @@ export const Form: React.FC<FormProps> = props => {
198201 { ! editingField && (
199202 < Box flexDirection = 'column' marginTop = { 1 } >
200203 < Box flexDirection = "row" >
201- < Button label = "[A]dd resource" id = { 'addButton' } onClicked = { ( ) => duplicateCurrentSection ( ) } />
202- < Button label = "[R]emove resource" id = { 'removeButton' } isEnabled = { sections . length > 1 } onClicked = { ( ) => removeCurrentSection ( ) } />
203204 < SubmitButton canSubmit = { canSubmitForm } onSubmit = { onSubmitForm } />
204205 </ Box >
205- < Text dimColor color = 'gray' > Provide all required information (< Text color = "red" > *</ Text > ) to submit.</ Text >
206- < Text dimColor color = 'gray' > Up/down: navigate options.</ Text >
207- < Text dimColor color = 'gray' > Left/right: navigate between resources.</ Text >
208- < Text dimColor color = 'gray' > Enter: select or edit.</ Text >
206+ < Text color = 'gray' > Up/down: navigate between parameters.</ Text >
207+ < Text color = 'gray' > Left/right: navigate between resources.</ Text >
208+ < Text color = 'gray' > Enter: select or edit.</ Text >
209+ < Text color = 'gray' > [A]: add an additional instance.</ Text >
210+ < Text color = 'gray' > [R]: remove import.</ Text >
209211 </ Box >
210212
211213 // </Box>
0 commit comments