Skip to content

Commit aa7c463

Browse files
authored
Fix Input component icon positioning by only wrapping in relative container when needed (#777)
### Summary & Motivation Fix layout issues with the Input component when displaying icons. The component was wrapping all inputs in a div with conditional flex-1 class, which broke form layouts in certain scenarios like the questionnaire forms. - Modified the Input component to only wrap itself in a relative container when a startIcon is present. - Removed the conditional `isEmbedded ? "relative flex-1" : "relative"` wrapper that was applied to all inputs. - This preserves the original layout behavior for inputs without icons while maintaining proper icon positioning. ### Checklist - [x] I have added tests, or done manual regression tests - [x] I have updated the documentation, if necessary
2 parents 3f48954 + f3d0e1b commit aa7c463

File tree

1 file changed

+32
-26
lines changed
  • application/shared-webapp/ui/components

1 file changed

+32
-26
lines changed

application/shared-webapp/ui/components/Input.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,39 @@ export function Input({
4949
startIcon,
5050
...props
5151
}: Readonly<InputProps>) {
52-
return (
53-
<div className={isEmbedded ? "relative flex-1" : "relative"}>
54-
{startIcon && (
52+
const inputElement = (
53+
<AriaInput
54+
{...props}
55+
disabled={isDisabled}
56+
readOnly={isReadOnly}
57+
type={type}
58+
className={composeRenderProps(
59+
className,
60+
(className, { isFocusVisible, isDisabled, ...renderProps }) =>
61+
`${inputStyles({
62+
...renderProps,
63+
isFile: type === "file",
64+
isFocusVisible: isEmbedded ? false : isFocusVisible,
65+
isEmbedded,
66+
isDisabled,
67+
isReadOnly,
68+
hasStartIcon: !!startIcon,
69+
className
70+
})} ${isDisabled || isReadOnly ? "border-input" : ""}`
71+
)}
72+
/>
73+
);
74+
75+
if (startIcon) {
76+
return (
77+
<div className="relative">
5578
<div className="-translate-y-1/2 pointer-events-none absolute top-1/2 left-3 flex items-center">
5679
{startIcon}
5780
</div>
58-
)}
59-
<AriaInput
60-
{...props}
61-
disabled={isDisabled}
62-
readOnly={isReadOnly}
63-
type={type}
64-
className={composeRenderProps(
65-
className,
66-
(className, { isFocusVisible, isDisabled, ...renderProps }) =>
67-
`${inputStyles({
68-
...renderProps,
69-
isFile: type === "file",
70-
isFocusVisible: isEmbedded ? false : isFocusVisible,
71-
isEmbedded,
72-
isDisabled,
73-
isReadOnly,
74-
hasStartIcon: !!startIcon,
75-
className
76-
})} ${isDisabled || isReadOnly ? "border-input" : ""}`
77-
)}
78-
/>
79-
</div>
80-
);
81+
{inputElement}
82+
</div>
83+
);
84+
}
85+
86+
return inputElement;
8187
}

0 commit comments

Comments
 (0)