Skip to content

Commit

Permalink
fix(table): table.columns.thClassName doesn't work (#3198) (#3238)
Browse files Browse the repository at this point in the history
* fix(table): table.columns.thClassName doesn't work (#3198)

fix #3198

* test(table): add missing test: thClassName
  • Loading branch information
theBestVayne authored and uyarn committed Aug 15, 2024
1 parent a1e7f7b commit 74c34f7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/table/__tests__/column.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,27 @@ TABLES.forEach((TTable) => {
expect(tdList.at(3).classes('tdesign-class')).toBeTruthy();
expect(tdList.at(3).classes('tdesign-class1')).toBeFalsy();
});

// 校验逻辑与上面columns.className一致
it('Props.columns.thClassName works fine', () => {
const columns = [
{ title: 'Index', colKey: 'index', thClassName: () => ['th-class'] },
{ title: 'Instance', colKey: 'instance', thClassName: 'th-class' },
{ title: 'description', colKey: 'description', thClassName: [{ 'th-class': true }] },
{ title: 'Owner', colKey: 'owner', thClassName: { 'th-class': true, 'th-class1': false } },
];
const wrapper = mount({
render() {
return <TTable rowKey="index" data={data} columns={columns}></TTable>;
},
});
const thWrapper = wrapper.find('thead > tr');
const thList = thWrapper.findAll('th');
expect(thList.at(0).classes('th-class')).toBeTruthy();
expect(thList.at(1).classes('th-class')).toBeTruthy();
expect(thList.at(2).classes('th-class')).toBeTruthy();
expect(thList.at(3).classes('th-class')).toBeTruthy();
expect(thList.at(3).classes('th-class1')).toBeFalsy();
});
});
});
2 changes: 2 additions & 0 deletions src/table/thead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ export default defineComponent({
rowIndex: -1,
};
const customClasses = formatClassNames(col.className, { ...colParams, type: 'th' });
const thCustomClasses = formatClassNames(col.thClassName, { ...colParams, type: 'th' });
const isLeftFixedActive = this.showColumnShadow.left && col.fixed === 'left';
const isRightFixedActive = this.showColumnShadow.right && col.fixed === 'right';
const canDragSort = this.thDraggable && !(isLeftFixedActive || isRightFixedActive);
const thClasses = [
thStyles.classes,
customClasses,
thCustomClasses,
{
// 受 rowspan 影响,部分 tr > th:first-child 需要补足左边框
[this.tableHeaderClasses.thBordered]: thBorderMap.get(col),
Expand Down

0 comments on commit 74c34f7

Please sign in to comment.