Skip to content

Commit

Permalink
fix(app): fix input field behavior on blur (#15035)
Browse files Browse the repository at this point in the history
* fix(app): fix input field behavior on blur
  • Loading branch information
koji authored May 3, 2024
1 parent 0526f55 commit d6472ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions app/src/atoms/InputField/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { css } from 'styled-components'
import styled, { css } from 'styled-components'

import {
ALIGN_CENTER,
Expand Down Expand Up @@ -276,7 +276,7 @@ function Input(props: InputFieldProps): JSX.Element {
}
}}
>
<input
<StyledInput
{...inputProps}
data-testid={props.id}
value={value}
Expand Down Expand Up @@ -314,3 +314,9 @@ function Input(props: InputFieldProps): JSX.Element {
</Flex>
)
}

const StyledInput = styled.input`
&::placeholder {
color: ${COLORS.grey40};
}
`
5 changes: 4 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 @@ -229,7 +230,7 @@ export function ChooseProtocolSlideoutComponent(
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(`protocol_details:value_out_of_range`, {
Expand Down Expand Up @@ -258,6 +259,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 d6472ae

Please sign in to comment.