Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(comp:table): height of checkbox or radio in selectable column cell isn't right #1859

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/radio/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

display: inline-flex;
align-items: center;
vertical-align: middle;
line-height: unset;
cursor: pointer;

Expand Down

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions packages/components/table/demo/Selectable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
<IxSwitch v-model:checked="selectableColumn.showIndex" :labels="['Index', 'Index']"></IxSwitch>
</IxSpace>
<IxTable v-model:selectedRowKeys="selectedRowKeys" :columns="columns" :dataSource="data" :pagination="false">
<template #name="{ value }">
<IxButton mode="link">{{ value }}</IxButton>
</template>
</IxTable>
</IxSpace>
</template>
Expand Down Expand Up @@ -46,7 +43,6 @@ const columns: TableColumn<Data>[] = [
{
title: 'Name',
dataKey: 'name',
customCell: 'name',
},
{
title: 'Age',
Expand Down
5 changes: 3 additions & 2 deletions packages/components/table/src/main/body/BodyCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@
})

const classes = computed(() => {
const { fixed, align } = props.column as BodyColumn
const { fixed, align, type } = props.column as BodyColumn
const prefixCls = mergedPrefixCls.value
let classes = {
[`${prefixCls}-cell`]: true,
[`${prefixCls}-cell-sorted`]: !!activeSortOrderBy.value,
[`${prefixCls}-cell-align-${align.cell}`]: !!align && align.cell != 'start',
[`${prefixCls}-cell-ellipsis`]: !!mergedEllipsis.value,
[`${prefixCls}-cell-${type}`]: !!type,
}
if (fixed) {
classes = {
Expand Down Expand Up @@ -101,77 +102,77 @@
}
})

return () => {
const { column } = props
const prefixCls = mergedPrefixCls.value

const { type } = column as BodyColumn
let children: VNodeChild
let title: string | undefined

if (type === 'selectable') {
children = renderSelectableChildren(rowContext, slots, selectable, config, mergedPagination, prefixCls)
} else if (type === 'indexable') {
children = renderIndexableChildren(
rowContext,
slots,
column as TableColumnIndexable,
mergedPagination,
prefixCls,
)
} else {
const text = dataValue.value
children = renderChildren(rowContext, props, slots, text)
title = getColTitle(mergedEllipsis.value, children, text)

// emptyCell 仅支持普通列
if (!type && (isNil(children) || children === '')) {
const emptyCellRender = slots.emptyCell || mergedEmptyCell.value
children = isFunction(emptyCellRender)
? emptyCellRender({ column, record: rowProps.record, rowIndex: rowProps.rowIndex })
: emptyCellRender
}
}

// see: https://github.com/IDuxFE/idux/issues/1081
if (props.column.fixed && mergedEllipsis.value && (isFixStartLast.value || isFixEndFirst.value)) {
children = <span class={`${prefixCls}-cell-content`}>{children}</span>
}

const customAdditionalFn = tableProps.customAdditional?.bodyCell
const customAdditional = customAdditionalFn
? customAdditionalFn({ column, record: rowProps.record, rowIndex: rowProps.rowIndex })
: undefined
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const Tag = (tableProps.customTag?.bodyCell ?? 'td') as any

const contentNode =
type === 'expandable' ? (
<div class={`${prefixCls}-expandable-wrapper`}>
{renderExpandableChildren(rowContext, slots, expandable, isTreeData, prefixCls)}
{!isEmptyNode(children) && <span class={`${prefixCls}-expandable-trigger-gap`}></span>}
{children}
</div>
) : (
children
)

return (
<Tag
class={classes.value}
style={style.value}
title={title}
colSpan={props.colSpan}
rowSpan={props.rowSpan}
{...customAdditional}
>
{contentNode}
</Tag>
)
}
},
})

Check notice on line 175 in packages/components/table/src/main/body/BodyCell.tsx

View check run for this annotation

codefactor.io / CodeFactor

packages/components/table/src/main/body/BodyCell.tsx#L105-L175

Complex Method
function useDataValue(context: TableBodyRowContext, props: TableBodyCellProps) {
return computed(() => {
const {
Expand Down Expand Up @@ -348,6 +349,6 @@
return undefined
}

const classes = [`${prefixCls}-indexable`, selectDisabled.value && `${prefixCls}-indexable-disabled`]
const classes = [`${prefixCls}-indexable-label`, selectDisabled.value && `${prefixCls}-indexable-label-disabled`]
return <span class={classes}>{customRender({ record, rowIndex, pageIndex, pageSize })}</span>
}
2 changes: 1 addition & 1 deletion packages/components/table/style/indexable.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.@{table-prefix} {
&-indexable {
&-indexable-label {
color: var(--ix-color-text);
cursor: pointer;

Expand Down
7 changes: 7 additions & 0 deletions packages/components/table/style/selectable.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
background: var(--ix-table-body-row-bg-color-selected);
}
}

& td.@{table-prefix}-cell-selectable {
.@{checkbox-prefix},
.@{radio-prefix} {
line-height: 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -264,7 +264,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -319,7 +319,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -375,7 +375,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -430,7 +430,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -485,7 +485,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -540,7 +540,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -595,7 +595,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -650,7 +650,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -706,7 +706,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -761,7 +761,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -816,7 +816,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -871,7 +871,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -927,7 +927,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -982,7 +982,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -1037,7 +1037,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -1326,7 +1326,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -1371,7 +1371,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -1417,7 +1417,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down Expand Up @@ -1462,7 +1462,7 @@ exports[`ProTransfer > table transfer render work 1`] = `


<td
class="ix-table-cell"
class="ix-table-cell ix-table-cell-selectable"
>
<label
aria-checked="false"
Expand Down