1
- import React from "react" ;
1
+ import React , { useRef } from "react" ;
2
2
import styled from "@emotion/styled" ;
3
3
import DatePicker from "react-datepicker" ;
4
4
import { colors } from "../constants" ;
@@ -107,6 +107,11 @@ const Prescreen1d = ({}) => {
107
107
birthDate,
108
108
} = useUserState ( ) ;
109
109
110
+ const estimateTypeRef = useRef < HTMLDivElement > ( null ) ;
111
+ const wageIncreaseRef = useRef < HTMLDivElement > ( null ) ;
112
+ const trendRef = useRef < HTMLDivElement > ( null ) ;
113
+ const futureEarningRef = useRef < HTMLDivElement > ( null ) ;
114
+
110
115
const handleSelection = ( e : React . ChangeEvent < HTMLInputElement > ) => {
111
116
const selectValueString = e . target . value ;
112
117
switch ( e . target . name ) {
@@ -127,6 +132,18 @@ const Prescreen1d = ({}) => {
127
132
setExpectedPercentageWageIncrease ( parseFloat ( selectValueString ) ) ;
128
133
}
129
134
} ;
135
+
136
+ const scrollToElement = ( ref : React . RefObject < HTMLDivElement > ) => {
137
+ const node = ref . current ;
138
+ if ( node ) {
139
+ setTimeout ( ( ) => {
140
+ node . scrollIntoView ( {
141
+ behavior : 'smooth' ,
142
+ block : 'start' } ) ;
143
+ } , 100 ) ;
144
+ }
145
+ }
146
+
130
147
return (
131
148
< React . Fragment >
132
149
< SEO title = "Prescreen 1D" keywords = { [ `gatsby` , `application` , `react` ] } />
@@ -152,7 +169,7 @@ const Prescreen1d = ({}) => {
152
169
/>
153
170
</ Card >
154
171
< Card >
155
- < QuestionText >
172
+ < QuestionText ref = { estimateTypeRef } >
156
173
How would you like to estimate your future earnings?
157
174
</ QuestionText >
158
175
< AnswerBox >
@@ -165,6 +182,7 @@ const Prescreen1d = ({}) => {
165
182
awiTrendOrManualPrediction ===
166
183
FutureAwiPredictionEnum . PERCENTAGE
167
184
}
185
+ onClick = { ( ) => scrollToElement ( wageIncreaseRef ) }
168
186
/>
169
187
< LabelText > Use Percentage Only</ LabelText >
170
188
</ AnswerBox >
@@ -177,6 +195,7 @@ const Prescreen1d = ({}) => {
177
195
checked = {
178
196
awiTrendOrManualPrediction === FutureAwiPredictionEnum . TREND
179
197
}
198
+ onClick = { ( ) => scrollToElement ( wageIncreaseRef ) }
180
199
/>
181
200
< LabelText >
182
201
Use Percentage plus
@@ -193,6 +212,7 @@ const Prescreen1d = ({}) => {
193
212
awiTrendOrManualPrediction ===
194
213
FutureAwiPredictionEnum . MANUAL
195
214
}
215
+ onClick = { ( ) => scrollToElement ( futureEarningRef ) }
196
216
/>
197
217
< LabelText > Predict it myself</ LabelText >
198
218
</ AnswerBox >
@@ -212,13 +232,14 @@ const Prescreen1d = ({}) => {
212
232
{ ( awiTrendOrManualPrediction === FutureAwiPredictionEnum . PERCENTAGE ||
213
233
awiTrendOrManualPrediction === FutureAwiPredictionEnum . TREND ) && (
214
234
< CardGlossaryContainer >
215
- < Card >
235
+ < Card ref = { wageIncreaseRef } >
216
236
< QuestionText > Percent wage increase</ QuestionText >
217
237
< AnswerInputDiscouragePlaceholder
218
238
name = "expectedPercentageWageIncrease"
219
239
defaultValue = { expectedPercentageWageIncrease ?? undefined }
220
240
placeholder = { "0.01" }
221
241
onChange = { handleSelection }
242
+ // TODO: onFinish, scroll
222
243
> </ AnswerInputDiscouragePlaceholder >
223
244
{ isNaN ( expectedPercentageWageIncrease ) && < WarningBox > Please enter a number.</ WarningBox > }
224
245
</ Card >
@@ -227,7 +248,7 @@ const Prescreen1d = ({}) => {
227
248
{ awiTrendOrManualPrediction &&
228
249
awiTrendOrManualPrediction === FutureAwiPredictionEnum . TREND && (
229
250
< CardGlossaryContainer >
230
- < Card >
251
+ < Card ref = { trendRef } >
231
252
< QuestionText >
232
253
Which trend would you like to use to predict your future
233
254
earnings?
@@ -303,7 +324,7 @@ const Prescreen1d = ({}) => {
303
324
}
304
325
{ awiTrendOrManualPrediction === FutureAwiPredictionEnum . MANUAL && (
305
326
< >
306
- < Card >
327
+ < Card ref = { futureEarningRef } >
307
328
< label >
308
329
< QuestionText > Future Earnings</ QuestionText >
309
330
</ label >
0 commit comments