Skip to content

Commit 7a74578

Browse files
committed
refactor: rework grid border implementation in base styles
1 parent ec62dfb commit 7a74578

File tree

2 files changed

+80
-51
lines changed

2 files changed

+80
-51
lines changed

dev/playground/grid.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<div class="control-group">
7575
<vaadin-checkbox-group label="Column Features">
7676
<vaadin-checkbox id="header" value="header" label="Header" checked></vaadin-checkbox>
77-
<vaadin-checkbox id="footer" value="footer" label="Footer"></vaadin-checkbox>
77+
<vaadin-checkbox id="footer" value="footer" label="Footer" checked></vaadin-checkbox>
7878
<vaadin-checkbox id="autoWidthCols" value="autoWidth" label="Auto Width"></vaadin-checkbox>
7979
<vaadin-checkbox id="resizable" value="resizable" label="Resizable"></vaadin-checkbox>
8080
<vaadin-checkbox id="frozen" value="frozen" label="Freeze First Group"></vaadin-checkbox>

packages/grid/src/styles/vaadin-grid-base-styles.js

Lines changed: 79 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const gridStyles = css`
2222
cursor: default;
2323
--_border-color: var(--vaadin-grid-border-color, var(--vaadin-border-color-secondary));
2424
--_border-width: 0;
25-
--_row-border-width: var(--vaadin-grid-row-border-width, 1px);
25+
--_row-border-width: var(--vaadin-grid-row-border-width, 5px);
2626
--_column-border-width: var(--vaadin-grid-column-border-width, 0px);
2727
border-radius: var(--_border-radius);
2828
--_border-radius: 0;
@@ -52,7 +52,7 @@ export const gridStyles = css`
5252
}
5353
5454
#scroller {
55-
contain: layout;
55+
/* contain: layout; */
5656
border-radius: calc(var(--_border-radius) - var(--_border-width));
5757
position: relative;
5858
display: flex;
@@ -97,13 +97,13 @@ export const gridStyles = css`
9797
width: 100%;
9898
}
9999
100-
:host([overflow~='top']) #header,
100+
/* :host([overflow~='top']) #header,
101101
:host([overflow~='bottom']) #footer,
102102
:host([navigating]) #header:has(tr:last-child:focus-within),
103103
:host([navigating]) #footer:has(tr:first-child:focus-within),
104104
[empty-state] #header {
105105
z-index: 2;
106-
}
106+
} */
107107
108108
:host([dir='rtl']) #items,
109109
:host([dir='rtl']) #header,
@@ -130,12 +130,65 @@ export const gridStyles = css`
130130
color: var(--vaadin-grid-header-text-color, var(--vaadin-text-color));
131131
}
132132
133+
#header,
134+
#footer {
135+
z-index: 2;
136+
}
137+
133138
[part~='row'] {
134-
display: flex;
135-
width: 100%;
139+
display: inline-flex;
140+
min-width: 100%;
136141
box-sizing: border-box;
137142
margin: 0;
138143
position: relative;
144+
background: var(--vaadin-grid-cell-background, var(--vaadin-background-color));
145+
border-block: var(--_row-border-width) solid var(--_border-color);
146+
}
147+
148+
#header [part~='row'] {
149+
border-block-start-style: none;
150+
151+
&:last-child {
152+
background: transparent;
153+
}
154+
}
155+
156+
#footer [part~='row'] {
157+
border-block-end-style: none;
158+
159+
&:first-child {
160+
border-block-start-style: none;
161+
162+
&::before {
163+
content: '';
164+
display: none;
165+
height: var(--_row-border-width);
166+
background: var(--_border-color);
167+
position: absolute;
168+
inset-inline: 0;
169+
inset-block-start: calc(-1 * var(--_row-border-width));
170+
}
171+
}
172+
}
173+
174+
#items [part~='row'] {
175+
border-block-start-style: none;
176+
}
177+
178+
:host([overflow~='top']) [part~='last-row'] {
179+
border-block-end-style: none;
180+
}
181+
182+
:host([overflow~='bottom']),
183+
:host([overflow~='top']) {
184+
#table:has(#footer > tr:not([hidden])) [part~='last-row'] {
185+
border-block-end-style: solid;
186+
border-block-end-color: transparent;
187+
}
188+
189+
#footer [part~='row']::before {
190+
display: block;
191+
}
139192
}
140193
141194
[part~='row'][loading] [part~='body-cell'] ::slotted(vaadin-grid-cell-content) {
@@ -151,31 +204,8 @@ export const gridStyles = css`
151204
}
152205
153206
[part~='cell'] {
154-
padding: 0;
155207
box-sizing: border-box;
156208
background: var(--vaadin-grid-cell-background, var(--vaadin-background-color));
157-
border-block: var(--_row-border-width) solid var(--_border-color);
158-
/* margin-top: calc(var(--_row-border-width) * -1); */
159-
160-
/*
161-
Box-shadows are used to create a "fake" border at the end of the cell/row, which is visible when a row/cell ends
162-
before the edge of the grid viewport, as well as frozen columns and rows (header and footer).
163-
If there are frozen columns, we'll make the "fake box-shadow border" on the header and footer opaque by rendering
164-
both the border color and cell background color, so that a semi-transparent border color doesn't "stack" when
165-
scrolling horizontally.
166-
*/
167-
--_fake-border:
168-
0 calc(var(--_top, 0) * var(--_row-border-width) * -1) 0 0 var(--_border-color),
169-
0 calc(var(--_top-opaque, 0) * var(--_row-border-width) * -1) 0 0
170-
var(--vaadin-grid-cell-background-color, var(--vaadin-background-color)),
171-
0 calc(var(--_bottom, 0) * var(--_row-border-width)) 0 0 var(--_border-color),
172-
0 calc(var(--_bottom-opaque, 0) * var(--_row-border-width)) 0 0
173-
var(--vaadin-grid-cell-background-color, var(--vaadin-background-color)),
174-
calc(var(--_start, 0) * var(--_column-border-width) * -1) 0 0 0 var(--_border-color),
175-
calc(var(--_end, 0) * var(--_column-border-width)) 0 0 0 var(--_border-color),
176-
calc(var(--_end-opaque, 0) * var(--_column-border-width)) 0 0 0
177-
var(--vaadin-grid-cell-background-color, var(--vaadin-background-color));
178-
box-shadow: var(--_fake-border);
179209
}
180210
181211
[part~='cell']:where(:not([part~='details-cell'])) {
@@ -193,18 +223,18 @@ export const gridStyles = css`
193223
border-inline-start: 0;
194224
}
195225
196-
[part~='first-header-row-cell'],
226+
/* [part~='first-header-row-cell'],
197227
[part~='first-footer-row-cell'],
198228
[part~='first-row-cell'] {
199229
margin-top: 0;
200230
border-top: 0;
201-
}
231+
} */
202232
203-
table:has(#header > tr:not([hidden])) [part~='first-row-cell'] {
233+
/* table:has(#header > tr:not([hidden])) [part~='first-row-cell'] {
204234
border-top: var(--_row-border-width) solid var(--_border-color);
205-
}
235+
} */
206236
207-
[part~='last-column-cell'] {
237+
/* [part~='last-column-cell'] {
208238
--_end: 1;
209239
}
210240
@@ -256,7 +286,7 @@ export const gridStyles = css`
256286
table:has(#footer > tr:not([hidden])) [part~='last-row-cell']:not([part~='details-opened-row-cell']) {
257287
border-bottom: var(--_row-border-width) solid var(--_border-color);
258288
--_bottom: 0;
259-
}
289+
} */
260290
261291
[part~='body-cell']:where(:not([part~='details-cell'])) {
262292
--_highlight-background-color: var(--vaadin-grid-row-highlight-background-color, transparent);
@@ -323,9 +353,9 @@ export const gridStyles = css`
323353
border-top: 0;
324354
}
325355
326-
[part~='last-row-cell'] + [part~='details-cell'] {
356+
/* [part~='last-row-cell'] + [part~='details-cell'] {
327357
border-bottom: 0;
328-
}
358+
} */
329359
330360
[part~='cell'] ::slotted(vaadin-grid-cell-content) {
331361
display: block;
@@ -504,42 +534,43 @@ export const gridStyles = css`
504534
/* Focus outline element, also used for d'n'd indication */
505535
:is([part~='row'], [part~='cell'])::after {
506536
position: absolute;
507-
inset: calc(var(--_row-border-width) * -1) calc(var(--_column-border-width) * -1);
537+
inset-block: calc(-1 * var(--_row-border-width));
538+
inset-inline: 0;
508539
z-index: 3;
509540
pointer-events: none;
510541
outline: var(--vaadin-focus-ring-width) solid var(--vaadin-focus-ring-color);
511542
outline-offset: calc(var(--vaadin-focus-ring-width) * -1);
512543
}
513544
514-
[part~='first-column-cell']::after {
545+
/* [part~='first-column-cell']::after {
515546
inset-inline-start: 0;
516547
}
517548
518549
[part~='last-column-cell']::after {
519550
inset-inline-end: 0;
520-
}
551+
} */
521552
522-
#header [part~='row']:first-child::after,
553+
/* #header [part~='row']:first-child::after,
523554
[part~='first-header-row-cell']::after,
524555
[part*='first-row']::after {
525556
top: 0;
526557
}
527558
528559
table:has(#header > tr:not([hidden])) [part~='first-row-cell']::after {
529560
top: calc(var(--_row-border-width) * -1);
530-
}
561+
} */
531562
532-
#footer [part~='row']:last-child::after,
563+
/* #footer [part~='row']:last-child::after,
533564
[part~='last-footer-row-cell']::after,
534565
[part~='last-row']::after,
535566
[part~='last-row-cell']::after {
536567
bottom: 0;
537-
}
568+
} */
538569
539-
#header [part~='row']:last-child::after,
570+
/* #header [part~='row']:last-child::after,
540571
table:has(#footer > tr:not([hidden])) [part*='last-row']::after {
541572
bottom: calc(var(--_row-border-width) * -1);
542-
}
573+
} */
543574
544575
:host([navigating]) [part~='row']:focus,
545576
:host([navigating]) [part~='cell']:focus {
@@ -548,8 +579,6 @@ export const gridStyles = css`
548579
549580
[part~='row']::after {
550581
transform: translateX(var(--_grid-horizontal-scroll-position));
551-
inset-inline: 0;
552-
bottom: 0;
553582
}
554583
555584
[part~='row']:focus-visible,
@@ -598,9 +627,8 @@ export const gridStyles = css`
598627
bottom: calc(var(--vaadin-focus-ring-width) / -2);
599628
}
600629
601-
[part~='row'][dragstart] [part~='cell'] {
630+
[part~='row'][dragstart] {
602631
border-block-color: transparent !important;
603-
box-shadow: none;
604632
}
605633
606634
[part~='row'][dragstart] [part~='cell'][last-column] {
@@ -635,6 +663,7 @@ export const gridStyles = css`
635663
#sizer {
636664
display: flex;
637665
visibility: hidden;
666+
border: none !important;
638667
}
639668
640669
#sizer [part~='details-cell'],

0 commit comments

Comments
 (0)