Skip to content

Commit

Permalink
fix(Table): can use Input as column.title normally, close #4370 (#4522)
Browse files Browse the repository at this point in the history
* fix(Table): Modify the props of the title element in the table header

* fix(Table): can use Input as column.title, close #4370

---------

Co-authored-by: chenkeyao.chenkeya <chenkeyao.chenkeya@alibaba-inc.com>
Co-authored-by: 珵之 <chengzhi.zpc@alibaba-inc.com>
  • Loading branch information
3 people committed Nov 15, 2023
1 parent d73a9f1 commit bde3b4e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/table/base/cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export default class Cell extends React.Component {
const cellProps = { value, index: rowIndex, record, context };
let content = cell;
if (React.isValidElement(content)) {
content = React.cloneElement(content, cellProps);
// header情况下, props.cell为 column.title,不需要传递这些props
content = React.cloneElement(content, type === 'header' ? undefined : cellProps);
} else if (typeof content === 'function') {
content = content(value, rowIndex, record, context);
}
Expand Down
21 changes: 21 additions & 0 deletions test/table/issue-spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import assert from 'power-assert';
import Promise from 'promise-polyfill';
import Table from '../../src/table/index';
import ConfigProvider from '../../src/config-provider';
import Input from '../../src/input';
import '../../src/table/style.js';

/* eslint-disable */
Expand Down Expand Up @@ -1143,4 +1145,23 @@ describe('Issue', () => {
}
);
});

it('should can use Input at column.title, close #4370', () => {
const container = document.createElement('div');
document.body.appendChild(container);

ReactDOM.render(
<Table>
<Table.Column title={<Input />} lock htmlTitle="Unique Id" dataIndex="id" />
<Table.Column title="Title" dataIndex="title.name" />
<Table.Column title="Time" dataIndex="time" />
</Table>,
container
);
const input = container.querySelector('input');
assert(input);
console.log('[ input ]', input);
ReactTestUtils.Simulate.change(input, { target: { value: 'aa' } });
assert(input.value === 'aa');
});
});

0 comments on commit bde3b4e

Please sign in to comment.