Skip to content

Commit

Permalink
feat(comp:table): ellipsis supports hidden the title (#1044)
Browse files Browse the repository at this point in the history
fix #1035
  • Loading branch information
danranVm committed Jul 27, 2022
1 parent 29adb34 commit 70a6d4a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 13 deletions.
16 changes: 16 additions & 0 deletions packages/components/table/__tests__/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,22 @@ describe('Table', () => {
expect(wrapper.find('tbody').find('td').classes()).not.toContain('ix-table-ellipsis')
})

test('ellipsis with title work', async () => {
const wrapper = TableMount({ props: { ellipsis: { title: false } } })

expect(wrapper.find('thead').findAll('th')[2].classes()).toContain('ix-table-ellipsis')
expect(wrapper.find('tbody').findAll('td')[2].classes()).toContain('ix-table-ellipsis')
expect(wrapper.find('thead').findAll('th')[2].attributes('title')).toBe(undefined)
expect(wrapper.find('tbody').findAll('td')[2].attributes('title')).toBe(undefined)

await wrapper.setProps({ ellipsis: { title: true } })

expect(wrapper.find('thead').findAll('th')[2].classes()).toContain('ix-table-ellipsis')
expect(wrapper.find('tbody').findAll('td')[2].classes()).toContain('ix-table-ellipsis')
expect(wrapper.find('thead').findAll('th')[2].attributes('title')).not.toBe(undefined)
expect(wrapper.find('tbody').findAll('td')[2].attributes('title')).not.toBe(undefined)
})

test('ellipsis with columns work', async () => {
const wrapper = TableMount({
props: {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/docs/Index.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ order: 0
| `columns` | 表格列的配置描述 | `TableColumn[]` | - | - | 参见[TableColumn](#TableColumn) |
| `customAdditional` | 自定义表格行和单元格的额外属性 | `TableCustomAdditional` | - | - | 参见[TableCustomAdditional](#TableCustomAdditional) |
| `dataSource` | 表格数据数组 | `object[]` | - | - | - |
| `ellipsis` | 超过宽度将自动省略 | `boolean` | `false` | - | - |
| `ellipsis` | 超过宽度将自动省略 | `boolean \| { title: boolean }` | `false` | - | `title``false` 时, 不显示原生的 `title` |
| `empty` | 空数据时的内容 | `string \| EmptyProps \| #empty` | - | - | - |
| `getKey` | 获取数据的唯一标识 | `string \| (record: any) => VKey` | `key` || - |
| `headless` | 是否隐藏表头 | `boolean` | `false` | - |- |
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/src/composables/useColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function useColumns(
)
const fixedColumnKeys = useFixedColumnKeys(flattedColumnsWithScrollBar)
const hasEllipsis = computed(
() => props.ellipsis || flattedColumns.value.some(column => (column as TableColumnBase).ellipsis),
() => !!props.ellipsis || flattedColumns.value.some(column => (column as TableColumnBase).ellipsis),
)
const hasFixed = computed(() => flattedColumns.value.some(column => column.fixed))

Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/src/main/body/BodyCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default defineComponent({
let classes = {
[`${prefixCls}-sorted`]: !!activeSortOrderBy.value,
[`${prefixCls}-align-${align}`]: !!align,
[`${prefixCls}-ellipsis`]: ellipsis,
[`${prefixCls}-ellipsis`]: !!ellipsis,
}
if (fixed) {
const { lastStartKey, firstEndKey } = fixedColumnKeys.value
Expand Down
15 changes: 12 additions & 3 deletions packages/components/table/src/main/head/HeadCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

import { type ComputedRef, type Slots, type VNodeChild, computed, defineComponent, inject, normalizeClass } from 'vue'
import {
type CSSProperties,
type ComputedRef,
type Slots,
type VNodeChild,
computed,
defineComponent,
inject,
normalizeClass,
} from 'vue'

import { isFunction, isString } from 'lodash-es'

Expand Down Expand Up @@ -63,7 +72,7 @@ export default defineComponent({
[`${prefixCls}-cell-sortable`]: !!sortable,
[`${prefixCls}-align-${align}`]: !hasChildren && !!align,
[`${prefixCls}-align-center`]: hasChildren,
[`${prefixCls}-ellipsis`]: ellipsis,
[`${prefixCls}-ellipsis`]: !!ellipsis,
}
if (fixed) {
const { lastStartKey, firstEndKey } = fixedColumnKeys.value
Expand All @@ -79,7 +88,7 @@ export default defineComponent({
return normalizeClass(classes)
})

const style = computed(() => {
const style = computed<CSSProperties | undefined>(() => {
const { fixed, colStart, colEnd } = props.column as HeadColumn
if (!fixed) {
return
Expand Down
4 changes: 2 additions & 2 deletions packages/components/table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const tableProps = {
customAdditional: { type: Object as PropType<TableCustomAdditional<any, any>>, default: undefined },
customTag: { type: Object as PropType<TableCustomTag>, default: undefined },
dataSource: { type: Array as PropType<any[]>, default: () => [] },
ellipsis: { type: Boolean, default: false },
ellipsis: { type: [Boolean, Object] as PropType<boolean | { title?: boolean }>, default: false },
empty: { type: [String, Object] as PropType<string | EmptyProps>, default: undefined },
getKey: { type: [String, Function] as PropType<string | ((record: any) => any)>, default: undefined },
header: { type: [String, Object] as PropType<string | HeaderProps>, default: undefined },
Expand Down Expand Up @@ -107,7 +107,7 @@ export interface TableColumnCommon<T = any> {

export interface TableColumnBase<T = any, K = VKey> extends TableColumnCommon<T> {
dataKey?: VKey | VKey[]
ellipsis?: boolean
ellipsis?: boolean | { title?: boolean }
sortable?: TableColumnSortable<T>
filterable?: TableColumnFilterable<T>
title?: string
Expand Down
10 changes: 7 additions & 3 deletions packages/components/table/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

import { type VNode, type VNodeChild } from 'vue'

import { isString } from 'lodash-es'
import { isObject, isString } from 'lodash-es'

import { Logger, type VKey, convertArray, getFirstValidNode, uniqueId } from '@idux/cdk/utils'

import { type TableColumn } from '../types'

export function getColTitle(ellipsis: boolean, children: VNodeChild, title: string | undefined): string | undefined {
if (!ellipsis) {
export function getColTitle(
ellipsis: boolean | { title?: boolean },
children: VNodeChild,
title: string | undefined,
): string | undefined {
if (!ellipsis || (isObject(ellipsis) && !ellipsis.title)) {
return undefined
}

Expand Down
2 changes: 1 addition & 1 deletion packages/pro/table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const proTableProps = {
customTag: { type: Object as PropType<TableCustomTag>, default: undefined },
dataSource: { type: Array as PropType<any[]>, default: () => [] },
editable: { type: Boolean, default: false },
ellipsis: { type: Boolean, default: false },
ellipsis: { type: [Boolean, Object] as PropType<boolean | { title?: boolean }>, default: false },
empty: { type: [String, Object] as PropType<string | EmptyProps>, default: undefined },
getKey: { type: [String, Function] as PropType<string | ((record: any) => any)>, default: undefined },
header: { type: [String, Object] as PropType<string | HeaderProps>, default: undefined },
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default defineConfig({
setupFiles: [resolve(__dirname, './tests/setup.ts')],
coverage: {
enabled: true,
reporter: ['json', 'lcov', 'text', 'cobertura'],
reporter: ['json', 'lcov', 'cobertura'],
excludeNodeModules: true,
include: ['packages/**/src/*.{ts,tsx}'],
exclude: [],
Expand Down

0 comments on commit 70a6d4a

Please sign in to comment.