Skip to content

Commit c33ab76

Browse files
authored
bugfix/MIG-6690 Fix border (#34)
1 parent 0de89d8 commit c33ab76

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/components/field/field.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ const FieldBorderAnimated = styled.div<{ height: string; left: string; width: st
4141
position: absolute;
4242
width: ${props => props.width};
4343
height: ${props => props.height};
44-
left: ${props => props.left};
45-
top: ${FIELD_BORDER_ANIMATED_PADDING / 2}px;
44+
left: calc(${props => props.left} - ${FIELD_BORDER_ANIMATED_PADDING}px);
45+
top: ${FIELD_BORDER_ANIMATED_PADDING / 2 - FIELD_BORDER_ANIMATED_PADDING}px;
4646
${animatedBlueBorder};
47-
padding: ${FIELD_BORDER_ANIMATED_PADDING}px;
48-
margin: -${FIELD_BORDER_ANIMATED_PADDING}px;
4947
}
5048
`;
5149

@@ -159,6 +157,28 @@ export const Field = ({
159157
</>
160158
);
161159

160+
/**
161+
* Set the height based on the number of fields in preview multiplied by the default field height.
162+
* Add some padding.
163+
*/
164+
const previewBorderHeight = `${previewGroupLength * DEFAULT_FIELD_HEIGHT + FIELD_BORDER_ANIMATED_PADDING}px`;
165+
166+
/**
167+
* Set the width to 100%.
168+
* Increase the width to cover any glyphs.
169+
* Decrease the width if the field is nested.
170+
* Add some padding.
171+
*/
172+
const previewBorderWidth = `calc(100% + ${
173+
glyphs.length * FIELD_GLYPH_SPACING - depth * FIELD_BORDER_ANIMATED_PADDING * 2 + FIELD_BORDER_ANIMATED_PADDING * 2
174+
}px)`;
175+
176+
/**
177+
* Inset the border to the right if the field is nested.
178+
* Inset the border to the left if the field has glyphs.
179+
*/
180+
const previewBorderLeft = `${depth * DEFAULT_DEPTH_SPACING - glyphs.length * FIELD_GLYPH_SPACING}px`;
181+
162182
return (
163183
<FieldWrapper color={getTextColor()}>
164184
<InnerFieldWrapper width={spacing}>
@@ -168,9 +188,10 @@ export const Field = ({
168188
</InnerFieldWrapper>
169189
{previewGroupLength ? (
170190
<FieldBorder
171-
height={`${previewGroupLength * DEFAULT_FIELD_HEIGHT - FIELD_BORDER_ANIMATED_PADDING / 2}px`}
172-
left={`${depth * DEFAULT_DEPTH_SPACING - glyphs.length * FIELD_GLYPH_SPACING}px`}
173-
width={`calc(100% + ${glyphs.length * FIELD_GLYPH_SPACING - depth * FIELD_BORDER_ANIMATED_PADDING * 2}px)`}
191+
data-testid={`preview-border-${name}`}
192+
height={previewBorderHeight}
193+
left={previewBorderLeft}
194+
width={previewBorderWidth}
174195
>
175196
{content}
176197
</FieldBorder>

0 commit comments

Comments
 (0)