Skip to content

Commit

Permalink
fix(comp:table): can't reverse select, when multiple of selectable is…
Browse files Browse the repository at this point in the history
… false (#1383)
  • Loading branch information
liuzaijiang committed Jan 3, 2023
1 parent cb97fd0 commit 1300c13
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
Expand Up @@ -632,12 +632,12 @@ exports[`DatePanel > year type disabledDate work 1`] = `
</td>
</tr>
<tr role=\\"row\\" class=\\"ix-date-panel-row\\">
<td class=\\"ix-date-panel-cell ix-date-panel-cell-disabled ix-date-panel-cell-current\\" role=\\"gridcell\\">
<td class=\\"ix-date-panel-cell ix-date-panel-cell-disabled\\" role=\\"gridcell\\">
<div class=\\"ix-date-panel-cell-inner\\">
<div class=\\"ix-date-panel-cell-trigger\\">2022</div>
</div>
</td>
<td class=\\"ix-date-panel-cell\\" role=\\"gridcell\\">
<td class=\\"ix-date-panel-cell ix-date-panel-cell-current\\" role=\\"gridcell\\">
<div class=\\"ix-date-panel-cell-inner\\">
<div class=\\"ix-date-panel-cell-trigger\\">2023</div>
</div>
Expand Down
21 changes: 16 additions & 5 deletions packages/components/table/src/main/body/BodyCell.tsx
Expand Up @@ -214,19 +214,30 @@ function renderSelectableChildren(
mergedPagination: ComputedRef<TablePagination | null>,
) {
const { selected: checked, indeterminate, disabled, isHover, handleSelect: onChange } = props
const { showIndex, multiple, customCell } = selectable.value!
const { showIndex, multiple, customCell, trigger } = selectable.value!

if (!checked && !isHover && showIndex) {
return renderIndexableChildren(props, slots, config.columnIndexable as TableColumnIndexable, mergedPagination)
}

const customRender = isString(customCell) ? slots[customCell] : customCell
if (multiple) {
const checkboxProps = { checked, disabled, indeterminate, onChange, onClick }
return customRender ? customRender(checkboxProps) : <IxCheckbox {...checkboxProps}></IxCheckbox>
// 存在trigger时将事件代理到bodyCell进行处理
const exitTriggerCheckboxProps = { checked, disabled, indeterminate }
const checkboxProps = { ...exitTriggerCheckboxProps, onChange, onClick }
return customRender ? (
customRender(trigger ? exitTriggerCheckboxProps : checkboxProps)
) : (
<IxCheckbox {...(trigger ? exitTriggerCheckboxProps : checkboxProps)}></IxCheckbox>
)
} else {
const radioProps = { checked, disabled, onChange, onClick }
return customRender ? customRender(radioProps) : <IxRadio {...radioProps}></IxRadio>
const exitTriggerRadioProps = { checked, disabled }
const radioProps = { ...exitTriggerRadioProps, onChange, onClick }
return customRender ? (
customRender(radioProps)
) : (
<IxRadio {...(trigger ? exitTriggerRadioProps : radioProps)}></IxRadio>
)
}
}

Expand Down
20 changes: 10 additions & 10 deletions packages/pro/transfer/__tests__/proTransfer.spec.ts
Expand Up @@ -143,19 +143,19 @@ describe('ProTransfer', () => {
.findAll('tr:not(.ix-table-measure-row)')[0]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')
await sourceTable
.find('tbody')
.findAll('tr:not(.ix-table-measure-row)')[1]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')
await sourceTable
.find('tbody')
.findAll('tr:not(.ix-table-measure-row)')[2]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')

await appendTrigger.trigger('click')
expect(onChange).toBeCalledWith([0, 1, 2, 3, 4, 5, 7], [0, 1, 2, 3, 4])
Expand All @@ -165,19 +165,19 @@ describe('ProTransfer', () => {
.findAll('tr:not(.ix-table-measure-row)')[0]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')
await targetTable
.find('tbody')
.findAll('tr:not(.ix-table-measure-row)')[1]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')
await targetTable
.find('tbody')
.findAll('tr:not(.ix-table-measure-row)')[2]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')
await removeTrigger.trigger('click')
expect(onChange).toBeCalledWith([1, 3, 4], [0, 1, 2, 3, 4])
})
Expand Down Expand Up @@ -219,25 +219,25 @@ describe('ProTransfer', () => {
.findAll('tr:not(.ix-table-measure-row)')[0]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')
await sourceTable
.find('tbody')
.findAll('tr:not(.ix-table-measure-row)')[1]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')
await sourceTable
.find('tbody')
.findAll('tr:not(.ix-table-measure-row)')[2]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')
await sourceTable
.find('tbody')
.findAll('tr:not(.ix-table-measure-row)')[3]
.find('.ix-checkbox')
.find('input')
.setValue(true)
.trigger('click')

const [, targetTable] = wrapper.findAll('.ix-table')

Expand Down

0 comments on commit 1300c13

Please sign in to comment.