Skip to content

Commit

Permalink
fix(InputGroup): fixes problem with long labels (#3779)
Browse files Browse the repository at this point in the history
  • Loading branch information
DSil committed Mar 27, 2023
1 parent e2feb34 commit 2ef2dc1
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions packages/orbit-components/src/InputGroup/index.tsx
Expand Up @@ -38,17 +38,6 @@ const getToken = (name: string) => ({
return tokens[name][size];
};

const getFakeGroupMarginTop = ({
label,
theme,
}: {
label?: string;
theme: typeof defaultTheme;
}) => {
if (!label) return false;
return `calc(${theme.orbit.lineHeightTextNormal} + ${theme.orbit.spaceXXSmall})`;
};

const FakeGroup = styled.span<{
error?: Props["error"];
label?: Props["label"];
Expand All @@ -59,9 +48,6 @@ const FakeGroup = styled.span<{
${({ theme, error, disabled, active }) => css`
width: 100%;
display: block;
position: absolute;
top: 0px;
left: 0;
z-index: 1;
box-sizing: border-box;
height: ${getToken(TOKENS.height)};
Expand All @@ -74,7 +60,6 @@ const FakeGroup = styled.span<{
: theme.orbit.backgroundInput};
font-size: ${theme.orbit.fontSizeInputNormal};
transition: box-shadow ${theme.orbit.durationFast} ease-in-out;
margin-top: ${getFakeGroupMarginTop};
border-radius: 6px;
${mq.tablet(css`
Expand Down Expand Up @@ -307,28 +292,29 @@ const InputGroup = React.forwardRef<HTMLDivElement, Props>(
</FormLabel>
)}

<StyledChildren onBlur={handleBlurGroup}>
{React.Children.toArray(children).map((child, key) => {
const childFlex =
Array.isArray(flex) && flex.length !== 1 ? flex[key] || flex[0] : flex;
const item = child as React.ReactElement<Props>;
return (
<StyledChild flex={childFlex || "0 1 auto"} key={randomId(String(key))}>
{React.cloneElement(item, {
disabled: item.props.disabled || disabled,
size,
label: undefined,
onChange: handleChange(item.props.onChange),
onBlur: handleBlur(item.props.onBlur),
onFocus: handleFocus(item.props.onFocus),
// @ts-expect-error custom prop
insideInputGroup: true,
})}
</StyledChild>
);
})}
</StyledChildren>
<FakeGroup label={label} error={errorReal} active={active} size={size} />
<FakeGroup label={label} error={errorReal} active={active} size={size}>
<StyledChildren onBlur={handleBlurGroup}>
{React.Children.toArray(children).map((child, key) => {
const childFlex =
Array.isArray(flex) && flex.length !== 1 ? flex[key] || flex[0] : flex;
const item = child as React.ReactElement<Props>;
return (
<StyledChild flex={childFlex || "0 1 auto"} key={randomId(String(key))}>
{React.cloneElement(item, {
disabled: item.props.disabled || disabled,
size,
label: undefined,
onChange: handleChange(item.props.onChange),
onBlur: handleBlur(item.props.onBlur),
onFocus: handleFocus(item.props.onFocus),
// @ts-expect-error custom prop
insideInputGroup: true,
})}
</StyledChild>
);
})}
</StyledChildren>
</FakeGroup>
<ErrorFormTooltip
help={helpReal}
error={errorReal}
Expand Down

0 comments on commit 2ef2dc1

Please sign in to comment.