Skip to content
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
5 changes: 5 additions & 0 deletions src/packages/table/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Demo10 from './demos/taro/demo10'
import Demo11 from './demos/taro/demo11'
import Demo12 from './demos/taro/demo12'
import Demo13 from './demos/taro/demo13'
import Demo14 from './demos/taro/demo14'

const TableDemo = () => {
const [translated] = useTranslate({
Expand All @@ -33,6 +34,7 @@ const TableDemo = () => {
stickyHeader: '固定表头',
stickyLeftColumn: '固定左列',
stickyRightColumn: '固定右列',
customRow: '自定义行',
},
'en-US': {
basic: 'Basic usage',
Expand All @@ -50,6 +52,7 @@ const TableDemo = () => {
stickyHeader: 'sticky header',
stickyLeftColumn: 'sticky left column',
stickyRightColumn: 'sticky right column',
customRow: 'Custom Row',
},
})

Expand Down Expand Up @@ -94,6 +97,8 @@ const TableDemo = () => {
<Demo12 />
<h2>{translated.stickyRightColumn}</h2>
<Demo13 />
<h2>{translated.customRow}</h2>
<Demo14 />
</div>
</>
)
Expand Down
5 changes: 5 additions & 0 deletions src/packages/table/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Demo10 from './demos/h5/demo10'
import Demo11 from './demos/h5/demo11'
import Demo12 from './demos/h5/demo12'
import Demo13 from './demos/h5/demo13'
import Demo14 from './demos/h5/demo14'

const TableDemo = () => {
const [translated] = useTranslate({
Expand All @@ -30,6 +31,7 @@ const TableDemo = () => {
stickyHeader: '固定表头',
stickyLeftColumn: '固定左列',
stickyRightColumn: '固定右列',
customRow: '自定义行',
},
'en-US': {
basic: 'Basic Usage',
Expand All @@ -46,6 +48,7 @@ const TableDemo = () => {
stickyHeader: 'Sticky Header',
stickyLeftColumn: 'Sticky Left Column',
stickyRightColumn: 'Sticky Rright Column',
customRow: 'Custom Row',
},
})

Expand Down Expand Up @@ -77,6 +80,8 @@ const TableDemo = () => {
<Demo12 />
<h2>{translated.stickyRightColumn}</h2>
<Demo13 />
<h2>{translated.customRow}</h2>
<Demo14 />
</div>
)
}
Expand Down
69 changes: 69 additions & 0 deletions src/packages/table/demos/h5/demo14.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { useState } from 'react'
import { Table, TableColumnProps } from '@nutui/nutui-react'

const Demo14 = () => {
const [columns] = useState<Array<TableColumnProps>>([
{
title: '姓名',
key: 'name',
align: 'center',
},
{
title: '性别',
key: 'gender',
},
{
title: '学历',
key: 'record',
},
])

const [data] = useState([
{
name: 'Tom',
gender: '男',
record: '小学',
},
{
height: '50px',
text: '这里是自定义行',
Component: (props: any) => {
return (
<div style={{ height: props.height }}>
<div
style={{
position: 'absolute',
height: props.height,
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderBottom:
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
}}
>
{props.text}
</div>
</div>
)
},
rowRender: (item: any) => {
const { Component, ...rest } = item
return <Component {...rest} />
},
},
{
name: 'Lucy',
gender: '女',
record: '本科',
},
{
name: 'Jack',
gender: '男',
record: '高中',
},
])

return <Table columns={columns} data={data} />
}
export default Demo14
69 changes: 69 additions & 0 deletions src/packages/table/demos/taro/demo14.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { useState } from 'react'
import { Table, TableColumnProps } from '@nutui/nutui-react-taro'

const Demo14 = () => {
const [columns] = useState<Array<TableColumnProps>>([
{
title: '姓名',
key: 'name',
align: 'center',
},
{
title: '性别',
key: 'gender',
},
{
title: '学历',
key: 'record',
},
])
Comment on lines +5 to +19
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

优化列定义

columns 数组是常量,不需要使用 useState 来定义。可以直接定义为常量数组以减少不必要的状态管理复杂性。

-  const [columns] = useState<Array<TableColumnProps>>([
+  const columns: Array<TableColumnProps> = [
...
-  ])
+  ]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [columns] = useState<Array<TableColumnProps>>([
{
title: '姓名',
key: 'name',
align: 'center',
},
{
title: '性别',
key: 'gender',
},
{
title: '学历',
key: 'record',
},
])
const columns: Array<TableColumnProps> = [
{
title: '姓名',
key: 'name',
align: 'center',
},
{
title: '性别',
key: 'gender',
},
{
title: '学历',
key: 'record',
},
]


const [data] = useState([
{
name: 'Tom',
gender: '男',
record: '小学',
},
{
height: '50px',
text: '这里是自定义行',
Component: (props: any) => {
return (
<div style={{ height: props.height }}>
<div
style={{
position: 'absolute',
height: props.height,
width: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
borderBottom:
'1px solid var(--nutui-table-border-color, var(--nutui-black-3, rgba(0, 0, 0, 0.06)))',
}}
>
{props.text}
</div>
</div>
)
},
rowRender: (item: any) => {
const { Component, ...rest } = item
return <Component {...rest} />
},
},
{
name: 'Lucy',
gender: '女',
record: '本科',
},
{
name: 'Jack',
gender: '男',
record: '高中',
},
])

return <Table columns={columns} data={data} />
}
export default Demo14
1 change: 1 addition & 0 deletions src/packages/table/index.taro.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Table } from './table.taro'

export type { TableProps } from './table.taro'
export type { TableColumnProps } from './types'
export default Table
1 change: 1 addition & 0 deletions src/packages/table/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Table } from './table'

export type { TableProps } from './table'
export type { TableColumnProps } from './types'
export default Table
4 changes: 4 additions & 0 deletions src/packages/table/table.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export const Table: FunctionComponent<
}

const renderBodyTds = (item: any, rowIndex: number) => {
const { rowRender } = item
if (rowRender && typeof rowRender === 'function') {
return rowRender(item, rowIndex)
}
return sortDataItem().map(([value, render]) => {
return (
<div
Expand Down
4 changes: 4 additions & 0 deletions src/packages/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export const Table: FunctionComponent<
}

const renderBodyTds = (item: any, rowIndex: number) => {
const { rowRender } = item
if (rowRender && typeof rowRender === 'function') {
return rowRender(item, rowIndex)
}
Comment on lines +125 to +128
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

需要增加键盘访问性支持。

在文件 src/packages/table/table.tsx 中,发现存在 onClick 事件,但缺少相应的键盘事件处理程序(如 onKeyUponKeyDownonKeyPress)。为了确保组件的可访问性,请添加这些键盘事件处理程序。

  • onClick 事件位置:
    • onClick={() => handleSorterClick(item)}
Analysis chain

自定义行渲染逻辑正确。

但需要增加键盘访问性支持。

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the onClick event in the table has corresponding keyboard event handlers.

# Test: Search for onClick events in the file. Expect: Corresponding onKeyUp, onKeyDown, or onKeyPress events.
rg --type typescript $'onClick' src/packages/table/table.tsx

Length of output: 94



Script:

#!/bin/bash
# Description: Verify the onClick event in the table has corresponding keyboard event handlers.

# Test: Search for onClick events in the file. Expect: Corresponding onKeyUp, onKeyDown, or onKeyPress events.
rg 'onClick' src/packages/table/table.tsx

Length of output: 91



Script:

#!/bin/bash
# Description: Verify the presence of keyboard event handlers corresponding to the onClick event in the table component.

# Test: Search for onKeyUp, onKeyDown, or onKeyPress events in the file.
rg 'on(KeyUp|KeyDown|KeyPress)' src/packages/table/table.tsx

Length of output: 62

return sortDataItem().map(([value, render]) => {
return (
<div
Expand Down