-
Notifications
You must be signed in to change notification settings - Fork 311
feat(grid): add expand trigger slot #3518
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<template> | ||
<div> | ||
<tiny-grid ref="expandGridRef" :data="tableData" @toggle-expand-change="handleExpand"> | ||
<tiny-grid-column type="index" width="60"></tiny-grid-column> | ||
<tiny-grid-column type="expand" width="120"> | ||
<template #expand-trigger="{ row, $table }"> | ||
<tiny-button>{{ $table.hasRowExpand(row) ? '收起' : '展开' }}</tiny-button> | ||
</template> | ||
<template #default="data"> | ||
<ul> | ||
<li> | ||
<span>公司名称:</span> | ||
<span>{{ data.row.name }}</span> | ||
</li> | ||
<li> | ||
<span>区域:</span> | ||
<span>{{ data.row.area }}</span> | ||
</li> | ||
<li> | ||
<span>员工数:</span> | ||
<span>{{ data.row.employees }}</span> | ||
</li> | ||
<li> | ||
<span>公司简介:</span> | ||
<span>{{ data.row.introduction }}</span> | ||
</li> | ||
</ul> | ||
</template> | ||
</tiny-grid-column> | ||
<tiny-grid-column field="name" title="公司名称"></tiny-grid-column> | ||
<tiny-grid-column field="area" title="区域"></tiny-grid-column> | ||
<tiny-grid-column field="employees" title="员工数"></tiny-grid-column> | ||
</tiny-grid> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="jsx"> | ||
import { ref } from 'vue' | ||
import { TinyGrid, TinyGridColumn, TinyModal, TinyButton } from '@opentiny/vue' | ||
|
||
const tableData = ref([ | ||
{ | ||
id: '1', | ||
pid: '0', | ||
name: 'GFD 科技 YX 公司', | ||
area: '华东区', | ||
employees: '800', | ||
introduction: '公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||
}, | ||
{ | ||
id: '2', | ||
pid: '0', | ||
name: 'WWWW 科技 YX 公司', | ||
area: '华南区', | ||
employees: '500', | ||
introduction: '公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||
}, | ||
{ | ||
id: '4', | ||
pid: '0', | ||
name: 'TGBYX 公司', | ||
area: '华南区', | ||
employees: '360', | ||
introduction: '公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||
}, | ||
{ | ||
id: '7', | ||
pid: '0', | ||
name: '康康物业 YX 公司', | ||
area: '华南区', | ||
employees: '400', | ||
introduction: '公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||
} | ||
]) | ||
const expandGridRef = ref() | ||
|
||
function handleExpand({ row, rowIndex }) { | ||
if (expandGridRef.value.hasRowExpand(row)) { | ||
TinyModal.message({ | ||
message: `当前展开行:${JSON.stringify(rowIndex + 1)}`, | ||
status: 'info' | ||
}) | ||
} | ||
} | ||
</script> |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||||||||||||||||||||||||||||
import { test, expect } from '@playwright/test' | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
test('检查当前行是否展开', async ({ page }) => { | ||||||||||||||||||||||||||||||
page.on('pageerror', (exception) => expect(exception).toBeNull()) | ||||||||||||||||||||||||||||||
await page.goto('grid-expand#expand-trigger-slot') | ||||||||||||||||||||||||||||||
await page.locator('#expand-trigger-slot .tiny-grid-body__row').first().locator('.tiny-button').click() | ||||||||||||||||||||||||||||||
await expect(page.locator('div').filter({ hasText: '当前展开行:1' }).nth(1)).toBeVisible() | ||||||||||||||||||||||||||||||
await expect(page.locator('.tiny-grid-body__expanded-cell')).toHaveText( | ||||||||||||||||||||||||||||||
'公司名称:GFD 科技 YX 公司区域:华东区员工数:800公司简介:公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||
Comment on lines
+4
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion ❓ Verification inconclusiveMake the assertions less brittle
- await expect(page.locator('div').filter({ hasText: '当前展开行:1' }).nth(1)).toBeVisible()
- await expect(page.locator('.tiny-grid-body__expanded-cell')).toHaveText(
+ await expect(page.locator('div:has-text("当前展开行:1")').first()).toBeVisible()
+ await expect(
+ page.locator('.tiny-grid-body__expanded-cell')
+ ).toContainText('公司名称:GFD 科技 YX 公司') The revised selectors are unambiguous and the partial-text assertion guards against harmless formatting changes. Make the assertions less brittle
- await expect(page.locator('div').filter({ hasText: '当前展开行:1' }).nth(1)).toBeVisible()
- await expect(page.locator('.tiny-grid-body__expanded-cell')).toHaveText(
+ await expect(page.locator('div:has-text("当前展开行:1")').first()).toBeVisible()
+ await expect(
+ page.locator('.tiny-grid-body__expanded-cell')
+ ).toContainText('公司名称:GFD 科技 YX 公司') The revised selectors are unambiguous and the partial-text assertion guards against harmless formatting changes. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<template> | ||
<div> | ||
<tiny-grid ref="expandGrid" :data="tableData" @toggle-expand-change="handleExpand"> | ||
<tiny-grid-column type="index" width="60"></tiny-grid-column> | ||
<tiny-grid-column type="expand" width="120"> | ||
<template #expand-trigger="{ row, $table }"> | ||
<tiny-button>{{ $table.hasRowExpand(row) ? '收起' : '展开' }}</tiny-button> | ||
</template> | ||
<template #default="data"> | ||
<ul> | ||
<li> | ||
<span>公司名称:</span> | ||
<span>{{ data.row.name }}</span> | ||
</li> | ||
<li> | ||
<span>区域:</span> | ||
<span>{{ data.row.area }}</span> | ||
</li> | ||
<li> | ||
<span>员工数:</span> | ||
<span>{{ data.row.employees }}</span> | ||
</li> | ||
<li> | ||
<span>公司简介:</span> | ||
<span>{{ data.row.introduction }}</span> | ||
</li> | ||
</ul> | ||
</template> | ||
</tiny-grid-column> | ||
<tiny-grid-column field="name" title="公司名称"></tiny-grid-column> | ||
<tiny-grid-column field="area" title="区域"></tiny-grid-column> | ||
<tiny-grid-column field="employees" title="员工数"></tiny-grid-column> | ||
</tiny-grid> | ||
</div> | ||
</template> | ||
|
||
<script lang="jsx"> | ||
import { TinyGrid, TinyGridColumn, TinyModal, TinyButton } from '@opentiny/vue' | ||
|
||
export default { | ||
components: { | ||
TinyGrid, | ||
TinyGridColumn, | ||
TinyButton | ||
}, | ||
data() { | ||
return { | ||
tableData: [ | ||
{ | ||
id: '1', | ||
pid: '0', | ||
name: 'GFD 科技 YX 公司', | ||
area: '华东区', | ||
employees: '800', | ||
introduction: '公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||
}, | ||
{ | ||
id: '2', | ||
pid: '0', | ||
name: 'WWWW 科技 YX 公司', | ||
area: '华南区', | ||
employees: '500', | ||
introduction: '公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||
}, | ||
{ | ||
id: '4', | ||
pid: '0', | ||
name: 'TGBYX 公司', | ||
area: '华南区', | ||
employees: '360', | ||
introduction: '公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||
}, | ||
{ | ||
id: '7', | ||
pid: '0', | ||
name: '康康物业 YX 公司', | ||
area: '华南区', | ||
employees: '400', | ||
introduction: '公司技术和研发实力雄厚,是国家 863 项目的参与者,并被政府认定为“高新技术企业”。' | ||
} | ||
] | ||
} | ||
}, | ||
methods: { | ||
handleExpand({ row, rowIndex }) { | ||
if (this.$refs.expandGrid.hasRowExpand(row)) { | ||
TinyModal.message({ | ||
message: `当前展开行:${JSON.stringify(rowIndex + 1)}`, | ||
status: 'info' | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
IColumnConfig
makes formerly-optional props mandatory & drops'expand'
'expand'
, while the prop table above (2921-2924) still advertises it.id
,rules
,required
,width
,minWidth
,resizable
,fixed
are all non-optional – this is a breaking change for every existing consumer.Making them optional preserves backwards compatibility and syncs the type set with the public prop docs.
📝 Committable suggestion
🤖 Prompt for AI Agents