@@ -41,11 +41,9 @@ const FieldBorderAnimated = styled.div<{ height: string; left: string; width: st
41
41
position: absolute;
42
42
width: ${ props => props . width } ;
43
43
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;
46
46
${ animatedBlueBorder } ;
47
- padding: ${ FIELD_BORDER_ANIMATED_PADDING } px;
48
- margin: -${ FIELD_BORDER_ANIMATED_PADDING } px;
49
47
}
50
48
` ;
51
49
@@ -159,6 +157,28 @@ export const Field = ({
159
157
</ >
160
158
) ;
161
159
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
+
162
182
return (
163
183
< FieldWrapper color = { getTextColor ( ) } >
164
184
< InnerFieldWrapper width = { spacing } >
@@ -168,9 +188,10 @@ export const Field = ({
168
188
</ InnerFieldWrapper >
169
189
{ previewGroupLength ? (
170
190
< 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 }
174
195
>
175
196
{ content }
176
197
</ FieldBorder >
0 commit comments