🌐 AI搜索 & 代理 主页
Skip to content

Commit fdb8bb6

Browse files
authored
fix(tables): ensure row variant active (class table-active) takes precedence over other row variants (addresses #3008) (#4127)
1 parent f079fcf commit fdb8bb6

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/components/table/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,10 +1532,12 @@ example).
15321532

15331533
The `selected-variant` can be any of the
15341534
[standard (or custom) bootstrap base color variants](/docs/reference/color-variants), or the special
1535-
[table `active` variant](/docs/reference/color-variants#table-variants).
1535+
[table `active` variant](/docs/reference/color-variants#table-variants) which takes precedence over
1536+
any specific row or cell variants.
15361537

1537-
For accessibility reasons (specifically for color blind users), it is highly recommended to always
1538-
provide some other visual means of conveying that a row is selected, as shown in the example below.
1538+
For accessibility reasons (specifically for color blind users, or users with color contrast issues),
1539+
it is highly recommended to always provide some other visual means of conveying that a row is
1540+
selected, such as shown in the example below.
15391541

15401542
```html
15411543
<template>

src/components/table/_table.scss

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,53 @@
3535
}
3636
}
3737

38+
// Re-declare `table-active` class here so that it can take
39+
// precedence over row variants when used on selectable rows
40+
// Class can only be applied to rows and not individual cells
41+
> tbody > .table-active {
42+
&,
43+
> th,
44+
> td {
45+
background-color: $table-active-bg;
46+
}
47+
}
48+
49+
// Add special hover styling for `table-active` row variant
50+
&.table-hover > tbody > tr.table-active:hover {
51+
td,
52+
th {
53+
color: $table-hover-color;
54+
// `$table-hover-bg` default is a very transparent black
55+
// We overlay it over the background color to achieve the
56+
// same color effect while keeping the background solid
57+
background-image: linear-gradient($table-hover-bg, $table-hover-bg);
58+
background-repeat: no-repeat;
59+
}
60+
}
61+
3862
// Add in missing `bg-active` class for table tbody rows
3963
// Bootstrap v4.3 is missing this for dark tables
4064
// `bg-active` class cannot be applied to individual cells
4165
> tbody > .bg-active {
4266
&,
4367
> th,
4468
> td {
45-
background-color: $table-dark-active-bg;
69+
// Important is needed to override the standard `bg-variants`
70+
// as the also use `!important`
71+
background-color: $table-dark-active-bg !important;
72+
}
73+
}
74+
75+
// Add special hover styling for `bg-active` row variant (dark tables)
76+
&.table-hover.table-dark > tbody > tr.bg-active:hover {
77+
td,
78+
th {
79+
color: $table-dark-hover-color;
80+
// `$table-dark-hover-bg` default is a very transparent white
81+
// We overlay it over the background color to achieve the
82+
// same color effect while keeping the background solid
83+
background-image: linear-gradient($table-dark-hover-bg, $table-dark-hover-bg);
84+
background-repeat: no-repeat;
4685
}
4786
}
4887
}

0 commit comments

Comments
 (0)