Skip to content

Commit

Permalink
fix(app): fix input field behavior on blur
Browse files Browse the repository at this point in the history
fix input field behavior on blur

close RQA-2646 first one
  • Loading branch information
koji committed Apr 29, 2024
1 parent 35e4e10 commit 46b7d3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/src/organisms/ChooseProtocolSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function ChooseProtocolSlideoutComponent(
] = React.useState<RunTimeParameter[]>([])
const [currentPage, setCurrentPage] = React.useState<number>(1)
const [hasParamError, setHasParamError] = React.useState<boolean>(false)
const [isInputFocused, setIsInputFocused] = React.useState<boolean>(false)

React.useEffect(() => {
setRunTimeParametersOverrides(
Expand Down Expand Up @@ -228,8 +229,9 @@ export function ChooseProtocolSlideoutComponent(
} else if (runtimeParam.type === 'int' || runtimeParam.type === 'float') {
const value = runtimeParam.value as number
const id = `InputField_${runtimeParam.variableName}_${index.toString()}`
console.log()
const error =
Number.isNaN(value) ||
(Number.isNaN(value) && !isInputFocused) ||
value < runtimeParam.min ||
value > runtimeParam.max
? t(`protocol_details:value_out_of_range`, {
Expand Down Expand Up @@ -258,6 +260,8 @@ export function ChooseProtocolSlideoutComponent(
caption={`${runtimeParam.min}-${runtimeParam.max}`}
id={id}
error={error}
onBlur={() => setIsInputFocused(false)}
onFocus={() => setIsInputFocused(true)}
onChange={e => {
const clone = runTimeParametersOverrides.map((parameter, i) => {
if (i === index) {
Expand Down
5 changes: 4 additions & 1 deletion app/src/organisms/ChooseRobotSlideout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export function ChooseRobotSlideout(
const dispatch = useDispatch<Dispatch>()
const isScanning = useSelector((state: State) => getScanning(state))
const [targetProps, tooltipProps] = useHoverTooltip()
const [isInputFocused, setIsInputFocused] = React.useState<boolean>(false)

const unhealthyReachableRobots = useSelector((state: State) =>
getReachableRobots(state)
Expand Down Expand Up @@ -383,7 +384,7 @@ export function ChooseRobotSlideout(
const value = runtimeParam.value as number
const id = `InputField_${runtimeParam.variableName}_${index.toString()}`
const error =
Number.isNaN(value) ||
(Number.isNaN(value) && !isInputFocused) ||
value < runtimeParam.min ||
value > runtimeParam.max
? t(`value_out_of_range`, {
Expand Down Expand Up @@ -418,6 +419,8 @@ export function ChooseRobotSlideout(
}
id={id}
error={error}
onBlur={() => setIsInputFocused(false)}
onFocus={() => setIsInputFocused(true)}
onChange={e => {
const clone = runTimeParametersOverrides.map((parameter, i) => {
if (i === index) {
Expand Down

0 comments on commit 46b7d3d

Please sign in to comment.