mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
Pass name prop down to the table selection input (#9054)
This commit is contained in:
parent
842c7f21d9
commit
5fd741bf21
@ -45,26 +45,24 @@ export default class SelectionBox extends React.Component<SelectionBoxProps, Sel
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { type, rowIndex, disabled, onChange } = this.props;
|
const { type, rowIndex, ...rest } = this.props;
|
||||||
const { checked } = this.state;
|
const { checked } = this.state;
|
||||||
|
|
||||||
if (type === 'radio') {
|
if (type === 'radio') {
|
||||||
return (
|
return (
|
||||||
<Radio
|
<Radio
|
||||||
disabled={disabled}
|
|
||||||
onChange={onChange}
|
|
||||||
value={rowIndex}
|
|
||||||
checked={checked}
|
checked={checked}
|
||||||
|
value={rowIndex}
|
||||||
|
{...rest}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<Checkbox
|
||||||
|
checked={checked}
|
||||||
|
{...rest}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
|
||||||
<Checkbox
|
|
||||||
checked={checked}
|
|
||||||
disabled={disabled}
|
|
||||||
onChange={onChange}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -597,9 +597,9 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
|||||||
type={type}
|
type={type}
|
||||||
store={this.store}
|
store={this.store}
|
||||||
rowIndex={rowIndex}
|
rowIndex={rowIndex}
|
||||||
disabled={props.disabled}
|
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
defaultSelection={this.getDefaultSelection()}
|
defaultSelection={this.getDefaultSelection()}
|
||||||
|
{...props}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
@ -3,16 +3,18 @@ import { mount } from 'enzyme';
|
|||||||
import createStore from '../createStore';
|
import createStore from '../createStore';
|
||||||
import SelectionBox from '../SelectionBox';
|
import SelectionBox from '../SelectionBox';
|
||||||
|
|
||||||
|
const getDefaultStore = (selectedRowKeys) => {
|
||||||
|
return createStore({
|
||||||
|
selectedRowKeys: selectedRowKeys || [],
|
||||||
|
selectionDirty: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
describe('SelectionBox', () => {
|
describe('SelectionBox', () => {
|
||||||
it('unchecked by selectedRowKeys ', () => {
|
it('unchecked by selectedRowKeys ', () => {
|
||||||
const store = createStore({
|
|
||||||
selectedRowKeys: [],
|
|
||||||
selectionDirty: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<SelectionBox
|
<SelectionBox
|
||||||
store={store}
|
store={getDefaultStore()}
|
||||||
rowIndex="1"
|
rowIndex="1"
|
||||||
disabled={false}
|
disabled={false}
|
||||||
onChange={() => {}}
|
onChange={() => {}}
|
||||||
@ -24,14 +26,9 @@ describe('SelectionBox', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checked by selectedRowKeys ', () => {
|
it('checked by selectedRowKeys ', () => {
|
||||||
const store = createStore({
|
|
||||||
selectedRowKeys: ['1'],
|
|
||||||
selectionDirty: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<SelectionBox
|
<SelectionBox
|
||||||
store={store}
|
store={getDefaultStore(['1'])}
|
||||||
rowIndex="1"
|
rowIndex="1"
|
||||||
disabled={false}
|
disabled={false}
|
||||||
onChange={() => {}}
|
onChange={() => {}}
|
||||||
@ -43,14 +40,9 @@ describe('SelectionBox', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checked by defaultSelection', () => {
|
it('checked by defaultSelection', () => {
|
||||||
const store = createStore({
|
|
||||||
selectedRowKeys: [],
|
|
||||||
selectionDirty: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<SelectionBox
|
<SelectionBox
|
||||||
store={store}
|
store={getDefaultStore()}
|
||||||
rowIndex="1"
|
rowIndex="1"
|
||||||
disabled={false}
|
disabled={false}
|
||||||
onChange={() => {}}
|
onChange={() => {}}
|
||||||
@ -62,11 +54,7 @@ describe('SelectionBox', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('checked when store change', () => {
|
it('checked when store change', () => {
|
||||||
const store = createStore({
|
const store = getDefaultStore();
|
||||||
selectedRowKeys: [],
|
|
||||||
selectionDirty: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<SelectionBox
|
<SelectionBox
|
||||||
store={store}
|
store={store}
|
||||||
@ -84,4 +72,49 @@ describe('SelectionBox', () => {
|
|||||||
|
|
||||||
expect(wrapper.state()).toEqual({ checked: true });
|
expect(wrapper.state()).toEqual({ checked: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('passes props to Checkbox', () => {
|
||||||
|
const checkboxProps = {
|
||||||
|
name: 'testName',
|
||||||
|
id: 'testId',
|
||||||
|
};
|
||||||
|
const wrapper = mount(
|
||||||
|
<SelectionBox
|
||||||
|
store={getDefaultStore()}
|
||||||
|
rowIndex="1"
|
||||||
|
disabled={false}
|
||||||
|
onChange={() => {
|
||||||
|
}}
|
||||||
|
defaultSelection={['1']}
|
||||||
|
{...checkboxProps}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
wrapper.find('Checkbox').forEach((box) => {
|
||||||
|
expect(box.props().name).toEqual(checkboxProps.name);
|
||||||
|
expect(box.props().id).toEqual(checkboxProps.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('passes props to Radios', () => {
|
||||||
|
const radioProps = {
|
||||||
|
name: 'testName',
|
||||||
|
id: 'testId',
|
||||||
|
};
|
||||||
|
const wrapper = mount(
|
||||||
|
<SelectionBox
|
||||||
|
store={getDefaultStore()}
|
||||||
|
rowIndex="1"
|
||||||
|
disabled={false}
|
||||||
|
onChange={() => {
|
||||||
|
}}
|
||||||
|
defaultSelection={['1']}
|
||||||
|
type="radio"
|
||||||
|
{...radioProps}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
wrapper.find('Radio').forEach((radio) => {
|
||||||
|
expect(radio.props().name).toEqual(radioProps.name);
|
||||||
|
expect(radio.props().id).toEqual(radioProps.id);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -77,6 +77,7 @@ describe('Table.rowSelection', () => {
|
|||||||
const rowSelection = {
|
const rowSelection = {
|
||||||
getCheckboxProps: record => ({
|
getCheckboxProps: record => ({
|
||||||
disabled: record.name === 'Lucy',
|
disabled: record.name === 'Lucy',
|
||||||
|
name: record.name,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -84,7 +85,9 @@ describe('Table.rowSelection', () => {
|
|||||||
const checkboxes = wrapper.find('input');
|
const checkboxes = wrapper.find('input');
|
||||||
|
|
||||||
expect(checkboxes.at(1).props().disabled).toBe(false);
|
expect(checkboxes.at(1).props().disabled).toBe(false);
|
||||||
|
expect(checkboxes.at(1).props().name).toEqual(data[0].name);
|
||||||
expect(checkboxes.at(2).props().disabled).toBe(true);
|
expect(checkboxes.at(2).props().disabled).toBe(true);
|
||||||
|
expect(checkboxes.at(2).props().name).toEqual(data[1].name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('works with pagination', () => {
|
it('works with pagination', () => {
|
||||||
|
@ -9302,6 +9302,7 @@ exports[`renders ./components/table/demo/row-selection.md correctly 1`] = `
|
|||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
class="ant-checkbox-input"
|
class="ant-checkbox-input"
|
||||||
|
name="John Brown"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
/>
|
/>
|
||||||
<span
|
<span
|
||||||
@ -9350,6 +9351,7 @@ exports[`renders ./components/table/demo/row-selection.md correctly 1`] = `
|
|||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
class="ant-checkbox-input"
|
class="ant-checkbox-input"
|
||||||
|
name="Jim Green"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
/>
|
/>
|
||||||
<span
|
<span
|
||||||
@ -9398,6 +9400,7 @@ exports[`renders ./components/table/demo/row-selection.md correctly 1`] = `
|
|||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
class="ant-checkbox-input"
|
class="ant-checkbox-input"
|
||||||
|
name="Joe Black"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
/>
|
/>
|
||||||
<span
|
<span
|
||||||
@ -9447,6 +9450,7 @@ exports[`renders ./components/table/demo/row-selection.md correctly 1`] = `
|
|||||||
<input
|
<input
|
||||||
class="ant-checkbox-input"
|
class="ant-checkbox-input"
|
||||||
disabled=""
|
disabled=""
|
||||||
|
name="Disabled User"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
/>
|
/>
|
||||||
<span
|
<span
|
||||||
|
@ -60,6 +60,7 @@ const rowSelection = {
|
|||||||
},
|
},
|
||||||
getCheckboxProps: record => ({
|
getCheckboxProps: record => ({
|
||||||
disabled: record.name === 'Disabled User', // Column configuration not to be checked
|
disabled: record.name === 'Disabled User', // Column configuration not to be checked
|
||||||
|
name: record.name,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ export interface SelectionBoxProps {
|
|||||||
type?: RowSelectionType;
|
type?: RowSelectionType;
|
||||||
defaultSelection: string[];
|
defaultSelection: string[];
|
||||||
rowIndex: string;
|
rowIndex: string;
|
||||||
|
name?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user