Browse Source

style: Fixed the issue that when the Table component sets the header background color through style in onHeaderCell, the fixed header does not take effect (#2821)

YyumeiZhang 5 months ago
parent
commit
d117368c32

+ 34 - 33
packages/semi-foundation/table/table.scss

@@ -148,14 +148,14 @@ $module: #{$prefix}-table;
                         background-image: linear-gradient(0deg, $color-table_th-clickSort-bg-hover, $color-table_th-clickSort-bg-hover);
                         background-color: $color-table_cell-bg-hover;
                         
-                        &.#{$module}-cell-fixed {
-                            &-left,
-                            &-right {
-                                &::before {
-                                    background-color: transparent;
-                                }
-                            }
-                        }
+                        // &.#{$module}-cell-fixed {
+                        //     &-left,
+                        //     &-right {
+                        //         &::before {
+                        //             background-color: transparent;
+                        //         }
+                        //     }
+                        // }
                     }
                 }
 
@@ -164,19 +164,19 @@ $module: #{$prefix}-table;
                     &-right {
                         z-index: $z-table_fixed_column;
                         position: sticky;
-                        background-color: $color-table-bg-default;
-
-                        &::before {
-                            background-color: $color-table_th-bg-default;
-                            content: '';
-                            position: absolute;
-                            left: 0;
-                            top: 0;
-                            right: 0;
-                            bottom: 0;
-                            display: block;
-                            z-index: -1;
-                        }
+                        background-color: $color-table_th-bg-default;
+
+                        // &::before {
+                        //     background-color: $color-table_th-bg-default;
+                        //     content: '';
+                        //     position: absolute;
+                        //     left: 0;
+                        //     top: 0;
+                        //     right: 0;
+                        //     bottom: 0;
+                        //     display: block;
+                        //     z-index: -1;
+                        // }
                     }
 
                     &-left-last {
@@ -270,18 +270,19 @@ $module: #{$prefix}-table;
                         &-left,
                         &-right {
                             background-image: linear-gradient(0deg, $color-table_body-bg-default, $color-table_body-bg-default);
-
-                            &::before {
-                                background-color: $color-table_body-bg-hover;
-                                content: '';
-                                position: absolute;
-                                left: 0;
-                                top: 0;
-                                right: 0;
-                                bottom: 0;
-                                display: block;
-                                z-index: -1;
-                            }
+                            background-color: $color-table_body-bg-hover;
+
+                            // &::before {
+                            //     background-color: $color-table_body-bg-hover;
+                            //     content: '';
+                            //     position: absolute;
+                            //     left: 0;
+                            //     top: 0;
+                            //     right: 0;
+                            //     bottom: 0;
+                            //     display: block;
+                            //     z-index: -1;
+                            // }
                         }
                     }
                 }

+ 98 - 0
packages/semi-ui/table/_story/RowBg/index.jsx

@@ -0,0 +1,98 @@
+import React from 'react';
+import { Table } from '@douyinfe/semi-ui';
+
+
+class RowBg extends React.Component {
+    constructor(props = {}) {
+        super(props);
+  
+        this.columns = [
+            {
+                title: 'Name',
+                dataIndex: 'name',
+                width: 150,
+                fixed: 'left',
+                filterMultiple: false,
+                filters: [
+                    {
+                        text: 'Code 45',
+                        value: '45',
+                    },
+                    {
+                        text: 'King 4',
+                        value: 'King 4',
+                    },
+                ],
+                onFilter: (value, record) => record.name.includes(value),
+                filterDropdownProps: {
+                    showTick: true,
+                }
+            },
+            {
+                title: 'Age',
+                dataIndex: 'age',
+                width: 150,
+                sorter: (a, b) => (a.age - b.age > 0 ? 1 : -1),
+            },
+            {
+                title: 'Address',
+                width: 200,
+                dataIndex: 'address',
+            },
+            {
+                title: 'Description',
+                dataIndex: 'description',
+            },
+            {
+                fixed: 'right',
+                width: 250,
+                render: (text, record) => (
+                    <span color="green">Info</span>
+                ),
+            },
+        ];
+  
+  
+        const onHeaderCell = () => {
+            return {
+                style: { background: 'rgba(var(--semi-grey-1), 1)' },
+            };
+        };
+        this.columns.forEach((item) => (item.onHeaderCell = onHeaderCell));
+  
+        this.data = [];
+  
+        for (let i = 0; i < 46; i++) {
+            let age = 40 + (Math.random() > 0.5 ? 1 : -1) * Math.ceil(i / 3);
+            let name = `Edward King ${i}`;
+            this.data.push({
+                key: '' + i,
+                name,
+                age,
+                address: `London, Park Lane no. ${i}`,
+                description: `My name is ${name}, I am ${age} years old, living in New York No. ${i + 1} Lake Park.`,
+            });
+        }
+        this.handleRow = (record, index) => {
+            // 给偶数行设置斑马纹
+            if (index % 2 === 0) {
+                return {
+                    style: {
+                        background: 'var(--semi-color-fill-0)',
+                    },
+                };
+            } else {
+                return {};
+            }
+        };
+  
+        this.scroll = { y: 400, x: '150%' };
+    }
+  
+    render() {
+        return <Table columns={this.columns} dataSource={this.data} onRow={this.handleRow} scroll={this.scroll} />;
+    }
+}
+
+export default RowBg;
+  

+ 3 - 0
packages/semi-ui/table/_story/table.stories.jsx

@@ -49,6 +49,7 @@ import ExpandRowByClick from './ExpandRowByClick';
 import FixAllColumnsWithoutWidth from './FixAllColumnsWithoutWidth';
 import HugeData from "./HugeData"
 import RowSelectionRenderCell from './RowSelectionRenderCell';
+import RowBg from './RowBg';
 
 export default {
   title: 'Table'
@@ -653,3 +654,5 @@ export const _RowSelectionRenderCell = () => <RowSelectionRenderCell />;
 _RowSelectionRenderCell.story = {
   name: 'RowSelection RenderCell',
 };
+
+export const RowBgDemo = () => <RowBg />;