Skip to content

Commit

Permalink
fix(comp:table): selectable column showIndex doesn't work (#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Mar 5, 2024
1 parent 6a75ae2 commit 654ad1a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/components/checkbox/style/index.less
Expand Up @@ -7,6 +7,7 @@

display: inline-flex;
align-items: center;
vertical-align: middle;
line-height: unset;
cursor: pointer;
color: var(--ix-color-text);
Expand Down
36 changes: 26 additions & 10 deletions packages/components/table/src/main/body/BodyCell.tsx
Expand Up @@ -103,15 +103,22 @@ export default defineComponent({

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)
children = renderSelectableChildren(rowContext, slots, selectable, config, mergedPagination, prefixCls)
} else if (type === 'indexable') {
children = renderIndexableChildren(rowContext, slots, column as TableColumnIndexable, mergedPagination)
children = renderIndexableChildren(
rowContext,
slots,
column as TableColumnIndexable,
mergedPagination,
prefixCls,
)
} else {
const text = dataValue.value
children = renderChildren(rowContext, props, slots, text)
Expand All @@ -128,7 +135,7 @@ export default defineComponent({

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

const customAdditionalFn = tableProps.customAdditional?.bodyCell
Expand All @@ -140,9 +147,9 @@ export default defineComponent({

const contentNode =
type === 'expandable' ? (
<div class={`${mergedPrefixCls.value}-expandable-wrapper`}>
{renderExpandableChildren(rowContext, slots, expandable, isTreeData, mergedPrefixCls.value)}
{!isEmptyNode(children) && <span class={`${mergedPrefixCls.value}-expandable-trigger-gap`}></span>}
<div class={`${prefixCls}-expandable-wrapper`}>
{renderExpandableChildren(rowContext, slots, expandable, isTreeData, prefixCls)}
{!isEmptyNode(children) && <span class={`${prefixCls}-expandable-trigger-gap`}></span>}
{children}
</div>
) : (
Expand Down Expand Up @@ -272,6 +279,7 @@ function renderSelectableChildren(
selectable: ComputedRef<TableColumnMergedSelectable | undefined>,
config: TableConfig,
mergedPagination: ComputedRef<TablePagination | null>,
prefixCls: string,
) {
const {
props: { record, rowIndex },
Expand All @@ -291,8 +299,14 @@ function renderSelectableChildren(
}
}

if (!isSelected.value && !isHover && showIndex) {
return renderIndexableChildren(rowContext, slots, config.columnIndexable as TableColumnIndexable, mergedPagination)
if (!isSelected.value && !isHover.value && showIndex) {
return renderIndexableChildren(
rowContext,
slots,
config.columnIndexable as TableColumnIndexable,
mergedPagination,
prefixCls,
)
}

const customRender = isString(customCell) ? slots[customCell] : customCell
Expand Down Expand Up @@ -320,6 +334,7 @@ function renderIndexableChildren(
slots: Slots,
indexable: TableColumnIndexable,
mergedPagination: ComputedRef<TablePagination | null>,
prefixCls: string,
) {
const {
props: { record, rowIndex },
Expand All @@ -332,6 +347,7 @@ function renderIndexableChildren(
__DEV__ && Logger.warn('components/table', 'invalid customCell, please check the column is correct')
return undefined
}
const style = selectDisabled.value ? 'cursor: not-allowed' : 'cursor: pointer'
return <span style={style}>{customRender({ record, rowIndex, pageIndex, pageSize })}</span>

const classes = [`${prefixCls}-indexable`, selectDisabled.value && `${prefixCls}-indexable-disabled`]
return <span class={classes}>{customRender({ record, rowIndex, pageIndex, pageSize })}</span>
}
1 change: 1 addition & 0 deletions packages/components/table/style/index.less
Expand Up @@ -9,6 +9,7 @@
@import './size.less';
@import './expandable.less';
@import './selectable.less';
@import './indexable.less';
@import './triggers.less';
@import './shadow.less';

Expand Down
11 changes: 11 additions & 0 deletions packages/components/table/style/indexable.less
@@ -0,0 +1,11 @@
.@{table-prefix} {
&-indexable {
color: var(--ix-color-text);
cursor: pointer;

&&-disabled {
color: var(--ix-color-text-disabled);
cursor: not-allowed;
}
}
}

0 comments on commit 654ad1a

Please sign in to comment.