diff --git a/examples/sites/demos/apis/anchor.js b/examples/sites/demos/apis/anchor.js index 3cb61c7ff5..c0910c03ea 100644 --- a/examples/sites/demos/apis/anchor.js +++ b/examples/sites/demos/apis/anchor.js @@ -56,6 +56,21 @@ export default { pcDemo: 'set-container', mfDemo: 'set-container' }, + // 添加offset-top属性文档 + { + name: 'offset-top', + type: 'number', + defaultValue: '0', + desc: { + 'zh-CN': '锚点距离顶部的偏移量,用于调整滚动定位的位置', + 'en-US': 'Offset from the top of the anchor, used to adjust the scroll position' + }, + meta: { + stable: '3.19.0' + }, + mode: ['pc'], + pcDemo: 'offset-top' + }, { name: 'type', type: "'line' | 'dot'", diff --git a/examples/sites/demos/pc/app/anchor/basic-usage-composition-api.vue b/examples/sites/demos/pc/app/anchor/basic-usage-composition-api.vue index 7497660642..99528e62c4 100644 --- a/examples/sites/demos/pc/app/anchor/basic-usage-composition-api.vue +++ b/examples/sites/demos/pc/app/anchor/basic-usage-composition-api.vue @@ -12,36 +12,29 @@ import { TinyAnchor, TinySwitch } from '@opentiny/vue' const links = ref([ { - key: 'demonstrate', - link: '#demonstrate', - title: '演示', - children: [ - { - key: 'basic-usage', - link: '#basic-usage', - title: '基本用法' - }, - { - key: 'is-affix', - link: '#is-affix', - title: '固定模式' - }, - { - key: 'set-container', - link: '#set-container', - title: '滚动容器' - }, - { - key: 'on-change', - link: '#change', - title: 'change 事件' - } - ] + key: 'basic-usage', + link: '#basic-usage', + title: '基本用法' }, { - key: 'api', - link: '#API', - title: 'API' + key: 'is-affix', + link: '#is-affix', + title: '固定模式' + }, + { + key: 'set-container', + link: '#set-container', + title: '滚动容器' + }, + { + key: 'offset-top', + link: '#offset-top', + title: '顶部偏移量' + }, + { + key: 'on-change', + link: '#change', + title: 'change 事件' } ]) diff --git a/examples/sites/demos/pc/app/anchor/basic-usage.spec.ts b/examples/sites/demos/pc/app/anchor/basic-usage.spec.ts index fe710f739a..2691fe215a 100644 --- a/examples/sites/demos/pc/app/anchor/basic-usage.spec.ts +++ b/examples/sites/demos/pc/app/anchor/basic-usage.spec.ts @@ -5,15 +5,15 @@ test('基本用法', async ({ page }) => { await page.goto('anchor#basic-usage') const anchor = page.locator('.tiny-anchor') - const link1 = anchor.getByRole('link', { name: '演示' }) + const link1 = anchor.getByRole('link', { name: '基本用法' }) const link2 = anchor.getByRole('link', { name: 'change 事件' }) const hash1 = await page.evaluate(() => window.location.hash) await link1.click() const hash2 = await page.evaluate(() => window.location.hash) - await expect(hash2).not.toEqual(hash1) - await expect(hash2).toContain('#demonstrate') + await expect(hash2).toEqual(hash1) + await expect(hash2).toContain('#basic-usage') await link2.click() const hash3 = await page.evaluate(() => window.location.hash) diff --git a/examples/sites/demos/pc/app/anchor/basic-usage.vue b/examples/sites/demos/pc/app/anchor/basic-usage.vue index e3762642e2..d86f44bd37 100644 --- a/examples/sites/demos/pc/app/anchor/basic-usage.vue +++ b/examples/sites/demos/pc/app/anchor/basic-usage.vue @@ -20,36 +20,29 @@ export default { return { links: [ { - key: 'demonstrate', - link: '#demonstrate', - title: '演示', - children: [ - { - key: 'basic-usage', - link: '#basic-usage', - title: '基本用法' - }, - { - key: 'is-affix', - link: '#is-affix', - title: '固定模式' - }, - { - key: 'set-container', - link: '#set-container', - title: '滚动容器' - }, - { - key: 'on-change', - link: '#change', - title: 'change 事件' - } - ] + key: 'basic-usage', + link: '#basic-usage', + title: '基本用法' }, { - key: 'api', - link: '#API', - title: 'API' + key: 'is-affix', + link: '#is-affix', + title: '固定模式' + }, + { + key: 'set-container', + link: '#set-container', + title: '滚动容器' + }, + { + key: 'offset-top', + link: '#offset-top', + title: '顶部偏移量' + }, + { + key: 'on-change', + link: '#change', + title: 'change 事件' } ], type: 'dot' diff --git a/examples/sites/demos/pc/app/anchor/change-composition-api.vue b/examples/sites/demos/pc/app/anchor/change-composition-api.vue index ab905f2589..97b027fd18 100644 --- a/examples/sites/demos/pc/app/anchor/change-composition-api.vue +++ b/examples/sites/demos/pc/app/anchor/change-composition-api.vue @@ -8,36 +8,29 @@ import { TinyAnchor } from '@opentiny/vue' const links = ref([ { - key: 'demonstrate', - link: '#demonstrate', - title: '演示', - children: [ - { - key: 'basic-usage', - link: '#basic-usage', - title: '基本用法' - }, - { - key: 'is-affix', - link: '#is-affix', - title: '固定模式' - }, - { - key: 'set-container', - link: '#set-container', - title: '滚动容器' - }, - { - key: 'on-change', - link: '#change', - title: 'change 事件' - } - ] + key: 'basic-usage', + link: '#basic-usage', + title: '基本用法' }, { - key: 'api', - link: '#API', - title: 'API' + key: 'is-affix', + link: '#is-affix', + title: '固定模式' + }, + { + key: 'set-container', + link: '#set-container', + title: '滚动容器' + }, + { + key: 'offset-top', + link: '#offset-top', + title: '顶部偏移量' + }, + { + key: 'on-change', + link: '#change', + title: 'change 事件' } ]) diff --git a/examples/sites/demos/pc/app/anchor/change.vue b/examples/sites/demos/pc/app/anchor/change.vue index 3cb45ede45..958e6276c8 100644 --- a/examples/sites/demos/pc/app/anchor/change.vue +++ b/examples/sites/demos/pc/app/anchor/change.vue @@ -13,36 +13,29 @@ export default { return { links: [ { - key: 'demonstrate', - link: '#demonstrate', - title: '演示', - children: [ - { - key: 'basic-usage', - link: '#basic-usage', - title: '基本用法' - }, - { - key: 'is-affix', - link: '#is-affix', - title: '固定模式' - }, - { - key: 'set-container', - link: '#set-container', - title: '滚动容器' - }, - { - key: 'on-change', - link: '#change', - title: 'change 事件' - } - ] + key: 'basic-usage', + link: '#basic-usage', + title: '基本用法' }, { - key: 'api', - link: '#API', - title: 'API' + key: 'is-affix', + link: '#is-affix', + title: '固定模式' + }, + { + key: 'set-container', + link: '#set-container', + title: '滚动容器' + }, + { + key: 'offset-top', + link: '#offset-top', + title: '顶部偏移量' + }, + { + key: 'on-change', + link: '#change', + title: 'change 事件' } ] } diff --git a/examples/sites/demos/pc/app/anchor/is-affix-composition-api.vue b/examples/sites/demos/pc/app/anchor/is-affix-composition-api.vue index 70ab2d49b5..10b40b12a5 100644 --- a/examples/sites/demos/pc/app/anchor/is-affix-composition-api.vue +++ b/examples/sites/demos/pc/app/anchor/is-affix-composition-api.vue @@ -15,36 +15,29 @@ import { TinyAnchor, TinySwitch } from '@opentiny/vue' const isAffix = ref(false) const links = ref([ { - key: 'demonstrate', - link: '#demonstrate', - title: '演示', - children: [ - { - key: 'basic-usage', - link: '#basic-usage', - title: '基本用法' - }, - { - key: 'is-affix', - link: '#is-affix', - title: '固定模式' - }, - { - key: 'set-container', - link: '#set-container', - title: '滚动容器' - }, - { - key: 'on-change', - link: '#change', - title: 'change 事件' - } - ] + key: 'basic-usage', + link: '#basic-usage', + title: '基本用法' }, { - key: 'api', - link: '#API', - title: 'API' + key: 'is-affix', + link: '#is-affix', + title: '固定模式' + }, + { + key: 'set-container', + link: '#set-container', + title: '滚动容器' + }, + { + key: 'offset-top', + link: '#offset-top', + title: '顶部偏移量' + }, + { + key: 'on-change', + link: '#change', + title: 'change 事件' } ]) diff --git a/examples/sites/demos/pc/app/anchor/is-affix.vue b/examples/sites/demos/pc/app/anchor/is-affix.vue index c3d748379d..cad6d1a942 100644 --- a/examples/sites/demos/pc/app/anchor/is-affix.vue +++ b/examples/sites/demos/pc/app/anchor/is-affix.vue @@ -21,36 +21,29 @@ export default { isAffix: false, links: [ { - key: 'demonstrate', - link: '#demonstrate', - title: '演示', - children: [ - { - key: 'basic-usage', - link: '#basic-usage', - title: '基本用法' - }, - { - key: 'is-affix', - link: '#is-affix', - title: '固定模式' - }, - { - key: 'set-container', - link: '#set-container', - title: '滚动容器' - }, - { - key: 'on-change', - link: '#change', - title: 'change 事件' - } - ] + key: 'basic-usage', + link: '#basic-usage', + title: '基本用法' }, { - key: 'api', - link: '#API', - title: 'API' + key: 'is-affix', + link: '#is-affix', + title: '固定模式' + }, + { + key: 'set-container', + link: '#set-container', + title: '滚动容器' + }, + { + key: 'offset-top', + link: '#offset-top', + title: '顶部偏移量' + }, + { + key: 'on-change', + link: '#change', + title: 'change 事件' } ] } diff --git a/examples/sites/demos/pc/app/anchor/offset-top-composition-api.vue b/examples/sites/demos/pc/app/anchor/offset-top-composition-api.vue new file mode 100644 index 0000000000..d57bc808a5 --- /dev/null +++ b/examples/sites/demos/pc/app/anchor/offset-top-composition-api.vue @@ -0,0 +1,36 @@ + + + diff --git a/examples/sites/demos/pc/app/anchor/offset-top.spec.ts b/examples/sites/demos/pc/app/anchor/offset-top.spec.ts new file mode 100644 index 0000000000..967b418a4c --- /dev/null +++ b/examples/sites/demos/pc/app/anchor/offset-top.spec.ts @@ -0,0 +1,19 @@ +import { test, expect } from '@playwright/test' + +test('顶部偏移量', async ({ page }) => { + page.on('pageerror', (exception) => expect(exception).toBeNull()) + await page.goto('anchor#offset-top') + + const anchor = page.locator('.tiny-anchor') + const link1 = anchor.getByRole('link', { name: '基本用法' }).nth(0) + const link2 = anchor.getByRole('link', { name: '顶部偏移量' }).nth(0) + await link1.click() + const hash1 = await page.evaluate(() => window.location.hash) + + await link2.click() + const hash2 = await page.evaluate(() => window.location.hash) + + // 验证hash变化 + await expect(hash2).not.toEqual(hash1) + await expect(hash2).toContain('#offset-top') +}) diff --git a/examples/sites/demos/pc/app/anchor/offset-top.vue b/examples/sites/demos/pc/app/anchor/offset-top.vue new file mode 100644 index 0000000000..fd8f707bfb --- /dev/null +++ b/examples/sites/demos/pc/app/anchor/offset-top.vue @@ -0,0 +1,44 @@ + + + diff --git a/examples/sites/demos/pc/app/anchor/webdoc/anchor.js b/examples/sites/demos/pc/app/anchor/webdoc/anchor.js index de6c9196af..4491b8e993 100644 --- a/examples/sites/demos/pc/app/anchor/webdoc/anchor.js +++ b/examples/sites/demos/pc/app/anchor/webdoc/anchor.js @@ -42,6 +42,18 @@ export default { }, codeFiles: ['set-container.vue'] }, + { + demoId: 'offset-top', + name: { + 'zh-CN': '顶部偏移量', + 'en-US': 'Offset Top' + }, + desc: { + 'zh-CN': '通过 offset-top 设置锚点距离顶部的偏移量。', + 'en-US': 'Set the offset from the top of the anchor through offset-top.' + }, + codeFiles: ['offset-top.vue'] + }, { demoId: 'change', name: { @@ -133,6 +145,20 @@ export default { }, apis: ['link-click', 'change'], demos: ['set-container', 'change'] + }, + // 在features数组中添加新的特性说明 + { + id: 'offset-top', + name: '顶部偏移量', + support: { + value: true + }, + description: '通过 offset-top 属性设置锚点距离顶部的偏移量。', + cloud: { + value: true + }, + apis: ['offset-top'], + demos: ['offset-top'] } ] }